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

Revision 5134, 27.4 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoMail?.

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