source: branches/2.2/expressoMail1_2/js/filter.js @ 3833

Revision 3833, 25.1 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1636 - Corrigida mensagem de validação na criação de filtro.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1
2        function charCounter(form)
3        {
4                if (form.value.length >= 300)
5                {
6                        alert(get_lang("You have exceeded the number of allowed characters"));
7                        return false;
8                }
9        }
10
11        function cfilter(){
12
13                this.criticalError = false;
14                this.mode_in   = "";
15                this.rulest              = new Array;
16                this.rulesVoip   = new Array;
17                this.out_officeR = "";
18                this.out_officeF = false;
19                this.email_deny  = new Array;
20                this.ac_form     = "";
21                this.ind                 = "";
22                this.email_deny  = new Array;
23                this.email_ld    = "";
24                this.values = new Array("",
25                                        ",select_size=1",
26                                        ",select_rules=1",
27                                        ",select_size=1,select_rules=1",
28                                        ",checkBox2",
29                                        ",checkBox2,select_size=1",
30                                        ",ckeckBox1,checkBox2,select_size=1",
31                                        ",checkBox2,select_rules=1",
32                                        ",checkBox2,select_size=1,select_rules=1");
33               
34        }
35
36       
37        cfilter.prototype.load_rules = function(posHandler, param)
38        {
39                var _this = this;
40                var cont1 = parseInt(0);
41                var cont2 = parseInt(0);
42       
43                if( _this.rulest.length == 0 )
44                {
45                        var handler_sieve = function(data)
46                        {
47                                if (data.toString().indexOf('Error:') == 0)
48                                {
49                                        _this.criticalError = true;
50                                        alert(get_lang('The filters service is out of service, try again later...'));
51                                }
52                                else
53                                try{
54                                if(data.rule.length > 0){
55                                        for(var i=0 ; i < data.rule.length; i++)
56                                        {
57                                                var fields = data.rule[i].split("&&");
58                                                if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect )
59                                                        _this.rulesVoip[cont1++] = data.rule[i];
60                                                else
61                                                        _this.rulest[cont2++] = data.rule[i];
62                                        }
63                                }
64                                _this.out_officeR = data.vacation[0];
65                                _this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
66                                if(data.mode.length > 0){_this.mode_in = data.mode[0];}
67                                }
68                                catch(e){
69                                        _this.criticalError = true;
70                                        alert(get_lang('The filters service is out of service, try again later...'));
71                                }
72                                if (typeof(posHandler) == 'function') 
73                                        posHandler(param); 
74                        }
75                        if(Element('form_status') != null)
76                                Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
77                        cExecute("$this.ScriptS.init_a",handler_sieve);
78                        _this.get_email();
79            }
80        }
81       
82        cfilter.prototype.form_m = function(){
83                Element('form_body').innerHTML = "";
84                Element('form_buttons').style.display = '';
85                filters.mount_list();
86                this.ac_form = "";             
87        }
88       
89        cfilter.prototype.form_out = function(){
90                Element('form_body').innerHTML = "";
91                Element('form_body').innerHTML = this.forms_();
92                Element('div_vacation').style.display = "";
93                this.ac_form = "old_out";               
94                this.r_rules_out();             
95        }
96       
97        cfilter.prototype.form_r = function(pos,type)
98        {
99                Element('form_body').innerHTML = "";
100                Element('form_body').innerHTML = this.forms_();
101                this.ind = pos;         
102               
103                if( type === 'voip')
104                {
105                        this.ac_form = "old_voip";
106                        Element('div_voipFilter').style.display = "";
107                        this.r_rules_form(pos, type);   
108                }
109                else
110                {
111                        this.ac_form = "old_rule";
112                        Element('div_rule').style.display = "";
113                        this.r_rules_form(pos, type);
114                }
115        }
116       
117        cfilter.prototype.get_email = function()
118        {
119                var _this = this;
120                var handler_get_email = function(data)
121                {
122                        _this.email_ld = data ? data : "";
123                }
124                cExecute("$this.user.get_email",handler_get_email);
125        }
126       
127        cfilter.prototype.sel_boxes = function()
128        {
129                var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
130                if(document.getElementById("select_mailboxes") != null){
131                        var sel_nm = document.getElementById("select_mailboxes");
132                        if(sel_nm.length > 0 ){
133                                for(var i=0; i < sel_nm.options.length; i++){
134                                        sel_nm.options[i] = null;
135                                        i--;
136                                }
137                        }
138                        for(var i=0; i < nm_folders.length; i++){
139                                if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){
140                                        var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
141                                        sel_nm[sel_nm.length] = opt;
142                                }
143                        }
144                        sel_nm[0].selected = true;
145                }
146        }
147
148        cfilter.prototype.box_select = function(param){
149                var aux = this.BoxSelection[param].split(",");
150                var ele1 = document.getElementById(aux[0]);
151                var ele2 = document.getElementById(aux[1]);
152                var noption = "";
153                if(param == 0 || param == 1){
154                        if(ele1.selectedIndex != -1){
155                                noption = new Option(ele1.value,ele1.value,false,false);
156                                ele2.options[ele2.length] = noption;
157                                ele1.options[ele1.selectedIndex] = null;
158                                ele1.selectedIndex = 0;
159                        }
160                }
161        }
162
163        cfilter.prototype.r_rules_form = function(ind, type)
164        {
165                var fields = new Array;
166                var _this = this;
167               
168                // hide buttons
169                Element('form_buttons').style.display = 'none';
170               
171                if( type === 'voip')
172                {
173                        fields = _this.rulesVoip[ind].split("&&");
174                        document.getElementById("field9").value = fields[5];                   
175                }
176                else
177                {
178                        this.sel_boxes();
179                        if(this.rulest.length == 0){
180                                return false;
181                        }
182                        fields = _this.rulest[ind].split("&&");
183                        document.getElementById("field1").value = fields[3];
184                        document.getElementById("field2").value = fields[4];
185                        document.getElementById("field3").value = fields[5];
186                        document.getElementById("field4").value = fields[11];                           
187                       
188                        switch(fields[6]){
189                                case "folder":
190                                        document.getElementById("radio1").checked  = true;
191                                        var name_mb = fields[7];
192                                        var sel_mb = document.getElementById("select_mailboxes");
193                                        for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
194                                        break;
195                                case "address":
196                                        document.getElementById("radio2").checked   = true;
197                                        document.getElementById("field5").value         = fields[7];
198                                        break;
199                                case "reject":
200                                         document.getElementById("radio3").checked  = true;
201                                         var text0 = fields[7].split("\\n");                                   
202                                         for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
203                                         break;
204                                case "discard":
205                                        document.getElementById("radio4").checked       = true;
206                                        break;
207                                case "flagged":
208                                        document.getElementById("radio5").checked       = true;
209                                        break;
210                        }
211                        var mark_values = this.values[fields[8]].split(",");
212                        for(var i=0; i < mark_values.length; i++){
213                                if( mark_values[i] == "checkBox2"){
214                                        document.getElementById(mark_values[i]).checked = true;
215                                }
216                                if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
217                                        var mark_val = mark_values[i].split("=");
218                                        document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
219                                }
220                        }
221                }
222        }
223
224        cfilter.prototype.r_rules_out = function(){
225       
226                var _this = this;
227                if(_this.out_officeR.length == 0){
228                        return false;
229                }
230               
231                // hide buttons
232                Element('form_buttons').style.display = 'none';
233       
234                var aux = _this.out_officeR.split("&&");
235                var days   = aux[1];
236                var emails = aux[2];
237                var mens   = aux[3];           
238                var p_emails = new Array;
239                var d_emails = new Array;
240                               
241                var p_aux = emails.split(", ");
242                for(var i=0; i < p_aux.length; i++){
243                        p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
244                        p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
245                }
246                for(var i=0; i < _this.email_ld.length; i++){
247                        d_emails[i] = _this.email_ld[i];
248                }
249
250                diff = function(vet, comp){
251                        var sel1 = new Array;
252                        for(var i=0; i < vet.length; i++){
253                                for(var j=0; j < comp.length; j++){
254                                        if(vet[i] == comp[j]){
255                                                comp.splice(j,1);
256                                                j--;
257                                        }
258                                }
259                        }
260                };     
261                diff(p_emails,d_emails);
262                var text    = mens.split("\\n");
263                for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
264                for(var i=0; i < _this.email_ld.length; i++){
265                        d_emails[i] = _this.email_ld[i];
266                }
267
268        }
269
270        /*
271         * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição)
272         * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada
273         */
274        cfilter.prototype.disable_radio =  function()
275        {
276                radio4 = Element('radio4');
277                radio3 = Element('radio3');
278                cb2 = Element('checkBox2');
279                field6 = Element('field6');
280
281                if (cb2.checked)
282                {
283                        radio3.disabled = true;
284                        radio4.disabled = true;
285                        field6.disabled = true;
286
287                        if (radio3.checked)
288                        {
289                                radio3.checked = false;
290                        }
291                }
292                else
293                {
294                        radio3.disabled = false;
295                        radio4.disabled = true;
296                        field6.disabled = false;
297                }
298
299        }
300
301        cfilter.prototype.forms_ = function()
302        {
303                         var form = "";
304                                 form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
305                                         "<tr><td colspan='2'><b>"+get_lang("Criteria")+":</b></td></tr><tr>"+
306                                         "<td rowspan='4' width='20%'>"+get_lang('Find items')+":<br><select id='select_rules' name='select_rules'>"+
307                                         "<option value='1'>"+get_lang("If any criterion is met")+"</option><option value='0'>"+get_lang("If all criteria is met")+"</option>"+
308                                         "</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+
309                                                "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+
310                                                "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+
311                                                "</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
312                                                "<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+
313                                                "</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
314                                                "</tr><tr><td colspan='2'><hr size='1' width='100%'><b>"+get_lang("Action")+":</b></td></tr>"+
315                                                "</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
316                                                 "<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
317                                                 "<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
318                                                "<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
319                                                "</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
320                                                "<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
321                                                "</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
322                                                "<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
323                                                "</tr><tr id='tr_radio4'><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
324                                                "</tr><tr id='tr_radio5'><td colspan='2'><input type='radio' id='radio5' name='radio' value='important'>"+get_lang('Flag as important')+"</td>"+
325                                                "</tr></table></div><div id='div_vacation' style='display:none'>"+
326                                                "<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
327                                                "<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
328                                                //"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
329                                                "<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
330                                                "</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>" +
331                                                "<div id='div_voipFilter' style='display:none'>" +
332                                                "<br/><table id='table_voipFilter'>" +
333                                                "<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+
334                                                "</td></tr><tr><td><input type='text' id='field9' size='50' maxlength='200'>" +
335                                                "</td></tr><br/></table></div>" +
336                                                "<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
337                                                "<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";
338                return form;
339        }
340
341        cfilter.prototype.enabled_disabled = function(param){
342
343                // Rules
344                if(Element("rule_0") != null){
345                        for(var i=0; i < this.rulest.length; i++){
346                                if(Element("rule_"+i).checked){
347                                        var aux_rul = this.rulest[i].split("&&");
348                                        if(aux_rul[2] != param){
349                                                aux_rul[2] = param;                                     
350                                                var rl = "";
351                                                for(var j=0; j < aux_rul.length; j++){
352                                                        rl += aux_rul[j] + "&&";
353                                                }
354                                                rl = rl.substr(0,(rl.length - 2));
355                                                this.rulest[i] = rl;                                   
356                                        }
357                                }
358                        }
359                }
360                // Out Office
361                if(Element("out_0") != null){
362                        if(Element("out_0").checked){
363                                var aux_out = this.out_officeR.split("&&");
364                                if(param == "ENABLED")
365                                        aux_out[4] = "on ";
366                                else
367                                        aux_out[4] = "off";
368                                var out = "";
369                                for(var i=0; i < aux_out.length; i++){
370                                        out += aux_out[i] + "&&";
371                                }                               
372                                out = out.substr(0,(out.length - 2));
373                                this.out_officeR = out;
374                        }
375                }
376
377                // Voip
378                if(Element("voip_rule_0") != null){
379                        for(var i=0; i < this.rulesVoip.length; i++){
380                                if(Element("voip_rule_"+i).checked){
381                                        var aux_rul = this.rulesVoip[i].split("&&");
382                                        if(aux_rul[2] != param){
383                                                aux_rul[2] = param;                                     
384                                                var rl = "";
385                                                for(var j=0; j < aux_rul.length; j++){
386                                                        rl += aux_rul[j] + "&&";
387                                                }
388                                                rl = rl.substr(0,(rl.length - 2));
389                                                this.rulesVoip[i] = rl;                                 
390                                        }
391                                }
392                        }
393                }
394               
395                this.reload_rules();
396        }
397
398cfilter.prototype.new_rule = function(email){
399
400        var createFilter = function (param){
401                if (filter.criticalError){
402                        alert(get_lang('The filters service is out of service, try again later...'));
403                        return false;
404                }
405                if(filter.rulest.length > 0){
406                        var blockedReg = new RegExp('#rule&&[0-9]+&&ENABLED&&'+param+'&&&&&&discard&&&&0&&&&&&0');
407                        for(var i=0 ; i < filter.rulest.length; i++){
408                                if(blockedReg.test(filter.rulest[i])){
409                                        alert(get_lang("Sender blocked")+"!");
410                                        return false;
411                                }
412                        }
413                }                       
414                if(confirm(get_lang("Do you want to block this e-mail?"))){
415                        new_r = "&&ENABLED&&" + param + "&&&&&&discard&&&&0&&&&&&0";
416                        //setTimeout("filter.e_newrule('" + new_r + "')",2000);         
417                        if (filter.e_newrule(new_r)){
418                                filter.email_deny.push(new_r);
419                                write_msg(get_lang("The sender was blocked"));                                                   
420                        }else
421                                write_msg(get_lang("You have reached the maximum number of rules"));
422                }
423        };
424        if ( filter.rulest.length > 0 )
425                createFilter(email);
426        else
427                this.load_rules( createFilter, email );
428}
429
430        cfilter.prototype.e_newrule = function(nw_rule)
431        {
432
433                var new_rl = "";
434                if (this.rulest.length >= rules_limit)
435                        return false;
436                       
437                if(this.rulest.length == 0){
438                        new_rl = "#rule&&1" + nw_rule;
439                }else{
440                        var aux = this.rulest[this.rulest.length -1 ].split("&&");
441                        new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
442                }
443                this.rulest.push(new_rl);
444                this.saved_all();
445                return true;
446        }
447       
448        cfilter.prototype.delete_r = function(){
449       
450                // rule
451                var _this = this;
452                if(Element("rule_0") != null){
453                        for(var i=0; i < _this.rulest.length; i++){
454                                if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
455                        }
456                        for(var i=0; i < _this.rulest.length; i++){
457                                if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
458                        }
459                }
460       
461                if(_this.rulest.length > 0){
462                        var cont = parseInt(1);
463                        for(var i=0; i < _this.rulest.length ; i++){
464                                var n_rulest = _this.rulest[i].split("&&");
465                                n_rulest[1] = cont;
466                                cont = cont + parseInt(2);
467                                var aux = "";
468                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
469                                aux = aux.substr(0,(aux.length - 2));
470                                _this.rulest[i] = aux;
471                        }
472                }
473                // out office
474                if(Element("out_0") != null){
475                        if(Element("out_0").checked){
476                                _this.out_officeR ='';
477                                _this.out_officeF = false;
478                                //Save outoffice in prefs:
479                                connector.loadScript("preferences");
480                                prefe.save("outoffice", _this.out_officeF);
481                        }
482                }
483               
484                // Voip
485                if(Element("voip_rule_0") != null){
486                        for(var i=0; i < _this.rulesVoip.length; i++){
487                                if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
488                        }
489                        for(var i=0; i < _this.rulesVoip.length; i++){
490                                if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
491                        }
492                }
493       
494                if(_this.rulesVoip.length > 0){
495                        var cont = parseInt(1);
496                        for(var i=0; i < _this.rulesVoip.length ; i++){
497                                var n_rulest = _this.rulesVoip[i].split("&&");
498                                n_rulest[1] = cont;
499                                cont = cont + parseInt(2);
500                                var aux = "";
501                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
502                                aux = aux.substr(0,(aux.length - 2));
503                                _this.rulesVoip[i] = aux;
504                        }
505                }
506
507                _this.reload_rules();
508        }
509       
510        cfilter.prototype.reload_rules = function()
511        {
512                this.saved_all();
513                Element('form_body').innerHTML = "";
514                this.load_rules();
515
516                if(this.out_officeF)
517                {
518                        write_msg(get_lang("Attention, you are in out of office mode."), true);
519                }else{
520                        clean_msg();
521                        this.out_officeF = false;
522                }
523                filters.mount_list();
524        }
525
526        cfilter.prototype.forwardAddressValidation = function(addr) {
527            domains = sieve_forward_domains.replace(/\s/g, "").replace(/\./g, "\\.").replace(/,/g, "|");
528            domainRegexp = new RegExp("(" + domains +")$");
529            return domainRegexp.test(addr);
530        }
531
532        cfilter.prototype.saved_rules = function(){
533
534                var mount_rule = "";
535                var form = this.ac_form.split("_");
536                var n_rule = "";
537
538                if(form[1] == "rule")
539                {
540                        mount_rule = "#rule&&";
541                        if(form[0] == "new")
542                        {
543                                n_rule = "1&&";
544                                if(this.rulest.length > 0)
545                                {
546                                        aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
547                                        n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
548                                }
549                                mount_rule += n_rule + "ENABLED&&";
550                        }
551                        else
552                        {
553                                n_rule = this.rulest[this.ind].split("&&");
554                                mount_rule += n_rule[1] + "&&";
555                                mount_rule += n_rule[2] + "&&";
556                        }
557
558                        if (
559                                ( /[^\x00-\x80]/.test( Element("field1").value ) || /[^\x00-\x80]/.test( Element("field2").value ) || /[^\x00-\x80]/.test( Element("field3").value ) )
560                                && ( ! confirm( get_lang ( 'Your rule contains any accented character. The filter may not work. Do you wish to continue?' ) ) )
561                        ) return false;
562
563                        if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "")
564                        {
565                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
566                                return false;
567                        }
568
569                        if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){
570                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
571                                return false;
572                        }
573                       
574                        var isNumero = /^\d+$/.test(Element("field4").value);
575                        if(!isNumero){
576                                alert(get_lang("Enter a numerical value to the message size!"));
577                                return false;                           
578                        }
579                        for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";}
580                        var v_checked = false;
581                        if(Element("radio1").checked){
582                                mount_rule += "folder&&";
583                                var sel_nameBox = Element("select_mailboxes");
584                                for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
585                                v_checked = true;
586                        }
587                        if(Element("radio2").checked){
588                            if (this.forwardAddressValidation(Element("field5").value)){
589                                mount_rule += "address&&";
590                                if(Element("field5").value == ""){
591                                        alert(get_lang("Inform a forwarding e-mail!"));
592                                        return false;
593                                }else{
594                                    if(validateEmail(Element("field5").value)){
595                                                mount_rule += Element("field5").value + "&&";
596                                        }else{
597                                                alert(get_lang("Inform a valid e-mail!"));
598                                                return false;
599                                        }
600                                }
601                                v_checked = true;
602                            }
603                            else
604                                {
605                                    alert(get_lang("You can't forward e-mails to this domain: %1", Element("field5").value.split("@")[1]));
606                                    return false;
607                                }
608                        }
609                        if(Element("radio3").checked){
610                                mount_rule += "reject&&";
611                                if(Element("field6").value == ""){
612                                        alert(get_lang("Inform a text for rejection!"));
613                                        return false;
614                                }else{
615                                        mount_rule += Element("field6").value + "&&";
616                                }
617                                v_checked = true;
618                        }                               
619                        if(Element("radio4").checked){
620                                mount_rule += "discard&&&&";
621                                v_checked = true;
622                        }
623                        if(Element("radio5").checked){
624                                mount_rule += "flagged&&&&";
625                                v_checked = true;
626                        }
627                        if(!v_checked){
628                                alert(get_lang("No option marked!"));
629                                return false;
630                        }
631                        var opts = "";
632                        if(Element("checkBox2").checked == true){
633                            opts += ",checkBox2";
634                        }
635                        if(Element("select_size").options[1].selected == true){
636                            opts += ",select_size=1";
637                        }
638                        if(Element("select_rules").options[1].selected == true){
639                            opts += ",select_rules=1";
640                        }
641                        for(var i=0; i < this.values.length; i++){
642                            if(this.values[i] == opts){
643                                mount_rule += i + "&&";
644                            }
645                        }
646                        mount_rule += "&&&&";
647                        if(LTrim(Element("field4").value) != "" && LTrim(Element("field4").value) >= 0){
648                                mount_rule += LTrim(Element("field4").value);
649                        }
650                        if(form[0] == "new")
651                        {
652                                this.rulest[this.rulest.length] = mount_rule;
653                        }
654                        else
655                                this.rulest[this.ind] = mount_rule;
656                }
657                else if(form[1] == "out")
658                {
659                        mount_rule = "";
660                        var fld_emails = this.email_ld; // Get first email of list!
661                        var fld_men        = Element("field8");
662                        mount_rule = "#vacation&&";
663                        mount_rule += "1&&";
664                        mount_rule += "\"" + fld_emails + "\", ";                       
665                        mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
666                        mount_rule += "&&";
667                        mount_rule += fld_men.value + "&&on";
668                        if(LTrim(fld_men.value) == ""){
669                                alert(get_lang("Message required"));
670                                return false;
671                        }
672                        this.out_officeR = mount_rule;
673                }
674                else if(form[1] == "voip")
675                {
676                        if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
677                        {
678                                mount_rule = "#rule&&";
679                                if(form[0] == "new")
680                                {
681                                        n_rule = "1&&";
682                                        if( this.rulesVoip.length > 0 )
683                                        {
684                                                aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
685                                                n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
686                                        }
687                                        mount_rule += n_rule + "ENABLED&&";
688                                }
689                                else
690                                {
691                                        n_rule = this.rulesVoip[this.ind].split("&&");
692                                        mount_rule += n_rule[1] + "&&";
693                                        mount_rule += n_rule[2] + "&&";
694                                }
695
696                                if ( Element("field9").value.indexOf("#") >= 0 )
697                                {
698                                        alert(get_lang('Caracter "#" is not allowed!'));
699                                        return false;
700                                }
701                               
702                                mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
703
704                                if( form[0] == "new" )
705                                {
706                                        this.rulesVoip[this.rulesVoip.length] = mount_rule;
707                                }
708                                else
709                                {
710                                        this.rulesVoip[this.ind] = mount_rule;
711                                }
712                        }
713                        else
714                        {
715                                alert( 'CAMPOS EM BRANCO !!' );
716                                return false;
717                        }
718                }
719               
720                Element('form_buttons').style.display = '';
721                this.reload_rules();
722        }
723
724        cfilter.prototype.close_frm= function()
725        {
726                filters.filter_Sh['window_ffilter_ccform'].close();
727        }
728       
729        cfilter.prototype.saved_all = function()
730        {
731                var aux_rul = "";
732                var _this = this;
733                var cont = 0;
734               
735                // Regras Gerais
736                if(_this.rulest.length > 0)
737                {
738                        for(var i=0; i < _this.rulest.length; i++)
739                        {
740                                var fieldsNormal = _this.rulest[i].split("&&");                         
741                                aux_rul += "_begin_##";
742                                for(var j=0 ; j < fieldsNormal.length; j++)
743                                {
744                                        aux_rul += url_encode(fieldsNormal[j]) + "##";
745                                        cont = parseInt(fieldsNormal[1]);                                       
746                                }       
747                                aux_rul += "_end_\n";
748                        }
749                }
750       
751                // Voip
752                if(_this.rulesVoip.length > 0)
753                {
754                        for(var i=0; i < _this.rulesVoip.length; i++)
755                        {
756                                var fieldsVoip = _this.rulesVoip[i].split("&&");
757                                aux_rul += "_begin_##";
758                                for(var j=0 ; j < fieldsVoip.length; j++)
759                                {
760                                        if(j == 1)
761                                        {
762                                                if( cont == 0 )
763                                                        cont = parseInt(1);
764                                                else
765                                                        cont = parseInt(cont) + parseInt(2);
766                                                aux_rul += cont;
767                                                aux_rul += "##";
768                                        }
769                                        else
770                                                aux_rul += url_encode(fieldsVoip[j]) + "##";
771                                }
772                                aux_rul += "_end_\n";
773                        }
774                }
775               
776                // Fora do Escritório
777                if(_this.out_officeR.length > 0)
778                {
779                                var aux = _this.out_officeR.split("&&");                               
780                                aux_rul += "_begin_##";
781                                for(var j=0 ; j < aux.length; j++)
782                                {
783                                        aux_rul += url_encode(aux[j]) + "##";                                   
784                                }       
785                                aux_rul += "_end_\n";
786                                _this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
787                                //Save outoffice in prefs:
788                                connector.loadScript("preferences");
789                                if(typeof(prefe) == 'undefined')
790                                        setTimeout("filter.saved_all();",500);
791                                else
792                                        prefe.save("outoffice", _this.out_officeF);
793                }
794               
795                var h_filter = function(data)
796                {
797                        if(data != "Ok"){alert("Erro : \n" + get_lang(data));}
798                }
799                var args   = "$this.ScriptS.rec_rules";
800                var params = "arfilter="+aux_rul;
801                if(!_this.criticalError)
802                        cExecute(args,h_filter,params);
803        }
804
805// build object
806   var filter;
807   filter = new cfilter();
Note: See TracBrowser for help on using the repository browser.