source: branches/2.3/expressoMail1_2/js/filter.js @ 6657

Revision 6657, 27.2 KB checked in by brunocosta, 12 years ago (diff)

Ticket #2853 - Exibição de cotas de sub pastas IMAP. - ajuste.

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