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

Revision 670, 22.7 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #413

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