source: branches/2.2.0.1/expressoMail1_2/js/filter.js @ 4770

Revision 4770, 26.4 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #2084 - Filtros Encadeados .......................

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