source: trunk/expressoMail1_2/js/jscode/filter.js @ 2657

Revision 2657, 23.0 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1056 - Corrigido problema que remove todas as regras ao criar um nova.

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