source: sandbox/2.3-MailArchiver/expressoMail1_2/js/filter.js @ 6779

Revision 6779, 26.7 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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