source: trunk/expressoMail1_2/js/filter.js @ 5262

Revision 5262, 27.5 KB checked in by angelo, 12 years ago (diff)

Ticket #2389 - Botoes nao aparecem no gerenciamento de filtros

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