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

Revision 673, 22.7 KB checked in by niltonneto, 15 years ago (diff)

Revisão 670 revertida para versionar 1.233 em TAGS.

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