source: branches/2.2/expressoMail1_2/js/filter.js @ 3438

Revision 3438, 24.0 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1289 - Criacao de regra para as mensagens c/mais de 0k nao é aceita

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