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

Revision 2663, 23.2 KB checked in by amuller, 14 years ago (diff)

Ticket #1056 - Problemas de sincronismo na hora de aplicar no trunk

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