source: trunk/expressoMail1_2/js/search.js @ 5452

Revision 5452, 49.8 KB checked in by gustavo, 12 years ago (diff)

Ticket #2468 - Resolvido problema da busca rapida de emails, tamanho da mensagem

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1/**************************************************************************\
2 Início
3\**************************************************************************/
4        function searchE()
5        {
6                this.totalPages = 1;
7                this.numPages = 5;
8                this.lastPage = 0;
9                this.searchW            = [];
10                this.condition          = "";
11                this.sort_type          = "";
12                //this.page                     = 0;
13                this.name_box_search = "";
14                this.all_boxes          = [];
15                this.type                       = "";
16                this.txtfields          = new Array("txt_ass","txt_de","txt_body","txt_para","txt_cc","txt_cco", "since_date", "before_date", "on_date");
17                this.selectFields       = new Array("flagged", "seen", "answered", "recent");
18        }
19
20        //Monta os forms dentro da janela;
21        searchE.prototype.showForms = function(value)
22        {
23                // Principal
24                if(!Element("window_search"))
25                {
26                        var form_search = document.createElement("DIV");
27                        form_search.style.visibility = 'hidden';
28                        form_search.style.top = '0px';
29                        form_search.style.left = '0px';
30                        form_search.style.cursor = 'default';
31                        form_search.id = "window_search";
32                        document.body.appendChild(form_search);
33                }
34                $("#window_search").css("pointer", "default");
35                // Pesquisa
36                if(!Element("div_form_search"))
37                {
38                        var div_form_search = document.createElement("DIV");
39                        div_form_search.id = "div_form_search";
40                        div_form_search.style.position = "absolute";
41                        div_form_search.style.left = "10px";
42                        div_form_search.style.top  = "10px";
43                        div_form_search.style.borderStyle = "outset";
44                        div_form_search.style.borderColor = "black";
45                        div_form_search.style.borderWidth = "1px";
46                        div_form_search.style.width = "784px";
47                        div_form_search.style.height = "418px";
48                        div_form_search.style.overflow = "hidden";
49                        div_form_search.innerHTML = "";
50                        var call_form_search = EsearchE.mount_form();
51                        div_form_search.appendChild(call_form_search);
52                        form_search.appendChild(div_form_search);
53                }
54
55                if(!Element("div_button_search")){
56                        var div_button_search    = document.createElement("DIV");
57                                div_button_search.id = "div_button_search";
58                                div_button_search.style.position = "absolute";
59                                div_button_search.style.marginLeft = "430px";
60                                div_button_search.style.top = "223px";
61                                div_button_search.style.width = "350px";
62                                div_button_search.style.height = "25px";
63                                div_button_search.innerHTML = "<table style='width: 100%;' border='0' cellpadding='0' cellspacing='0' align='center'>"+
64                                                                                          "<tr>"+
65                                                                                          "<td width='33%' align='center'><input type='button' value=" + get_lang('Search') + " onclick='EsearchE.func_search()'></td>"+
66                                                                                          "<td width='33%' align='center'><input type='button' value=" + get_lang('Clean') + " onclick='EsearchE.func_clean()'></td>"+
67                                                                                          "<td width='33%' align='center'><input type='button' value=" + get_lang('Close') + " onclick='EsearchE.func_close(\"hidden\")'></td>"+
68                                                                                          "</tr>"+
69                                                                                          "</table>";
70                                form_search.appendChild(div_button_search);
71                }
72
73                if(!Element("table_layer")){
74                        var table_layer    = "";
75                }
76
77                if(value == "")
78                        EsearchE.showWindow(Element("window_search"));
79
80                // Cria as caixas postais;
81                EsearchE.mount_folders();
82
83                if(value)
84                {
85                        Element("check_all_msg").checked = true;
86                        EsearchE.all_mailboxes();
87                        EsearchE.func_search(value, null, 'SORTDATE_REVERSE');
88                }
89                var dates = $("#since_date, #before_date").datepicker({
90                        onSelect: function( selectedDate ) {
91                                var option = this.id == "since_date" ? "minDate" : "maxDate",
92                                        instance = $( this ).data( "datepicker" ),
93                                        date = $.datepicker.parseDate(
94                                                instance.settings.dateFormat ||
95                                                $.datepicker._defaults.dateFormat,
96                                                selectedDate, instance.settings );
97                                dates.not( this ).datepicker( "option", option, date );
98                        }
99                });
100                $("#on_date").datepicker();
101        }
102       
103        //Form
104        searchE.prototype.mount_form = function(value)
105        {
106                var form_sch = document.createElement("FORM");
107                        form_sch.id  = "form_sch";
108
109            form_sch.innerHTML =  '<fieldset style="width:400px; text-align:right; padding: 5px; position:absolute;">'
110                                                + '     <legend>'+get_lang('Inform your search in the text fields')+'</legend>'
111                                                + '     <label>'+get_lang("From")+':</label>'
112                                                + '     <input style="margin-left: 6px;" type="text" id="txt_de" size="39">'
113                                                + '     <br style="margin-bottom:15px"/>'
114                                                + '     <label>'+get_lang('To')+':</label>'
115                                                + '     <input style="margin-left: 6px;" type="text" id="txt_para" size="39">'
116                                                + '     <br style="margin-bottom:15px"/>'
117                                                + '     <label>'+get_lang('Cc')+':</label>'
118                                                + '     <input style="margin-left: 6px;" type="text" id="txt_cc" size="39">'
119                                                + '     <br style="margin-bottom:15px"/>'
120                                                + '     <label>'+get_lang('Subject')+':</label>'
121                                                + '     <input style="margin-left: 6px;" type="text" id="txt_ass" size="39">'
122                                                + '     <br style="margin-bottom:15px"/>'
123                                                + '     <label>'+get_lang('Message body')+':</label>'
124                                                + '     <input style="margin-left: 6px;" type="text" id="txt_body" size="39">'
125
126                                                + '     <br style="margin-bottom:30px"/>'
127                        + '     <label>'+get_lang("Since Date")+':</label>'
128                        + '     <input style="margin-left: 6px;" type="text" id="since_date" size="8" maxlength="10" onkeypress="return dateMask(this, event);">'
129                        //+ '     <img id="since_date-trigger" src="../phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
130                        + '     <label style="margin-left: 20px;">'+get_lang('Before Date')+':</label>'
131                        + '     <input style="margin-left: 6px;" type="text" id="before_date" size="8" maxlength="10" onkeypress="return dateMask(this, event);">'
132                        //+ '     <img id="before_date-trigger" src="../phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
133                        + '     <br style="margin-bottom:15px"/>'
134
135                        + '     <label>'+get_lang('On Date')+':</label>'
136                        + '     <input style="margin-left: 6px;" type="text" id="on_date" size="8" maxlength="10" onkeypress="return dateMask(this, event);">'
137                        //+ '     <img style="margin-right: -8px" id="on_date-trigger" src="../phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/><span>&nbsp;&nbsp;</span>'
138                        + '     <br style="margin-bottom:30px"/>'
139
140                        + '     <label>'+get_lang('Flags')+':</label>'
141                        + '     <select style="width:15em; margin-left: 6px" name="flagged" id="flagged">'
142                        + '     <option value=""/>'
143                        + '     <option value="FLAGGED">'+ get_lang("Flagged") +'</option>'
144                        + '     <option value="UNFLAGGED">'+ get_lang("Unflagged") +'</option>'
145                        + '     </select>'
146                        + '     <br style="margin-bottom:15px"/>'
147                        + '     <select style="width:15em;" name="seen" id="seen">'
148                        + '     <option value=""/>'
149                        + '     <option value="SEEN">'+ get_lang("Seen") +'</option>'
150                        + '     <option value="UNSEEN">'+ get_lang("Unseen") +'</option>'
151                        + '     </select>'
152                        + '     <br style="margin-bottom:15px"/>'
153                        + '     <select style="width:15em;" name="answered" id="answered">'
154                        + '     <option value=""/>'
155                        + '     <option value="ANSWERED">'+ get_lang('Answered/Forwarded') +'</option>'
156                        + '     <option value="UNANSWERED">'+ get_lang('Unanswered/Unforwarded') +'</option>'
157                        + '     </select>'
158                        + '     <br style="margin-bottom:15px"/>'
159                        + '     <select style="width:15em;visibility:hidden;" name="recent" id="recent">'
160                        + '     <option value=""/>'
161                        + '     <option value="RECENT">'+ get_lang('Recent') +'</option>'
162                        + '     <option value="OLD">'+ get_lang('Old') +'</option>'
163                        + '     </select>'
164
165                        + '     <br style="margin-bottom:60px"/>'
166                                                + '</fieldset>'
167                                                + '<fieldset style="width:350px; padding: 5px; position:absolute; margin-left: 414px">'
168                                                + '     <legend>'+get_lang('Search the messages in these folders')+'</legend>'
169                                                + '     <div id="folders" style="width:160px; height:150px;float:left;margin-bottom:10px;"></div>'
170                                                + '     <div style="float:left;height:100px;padding-top:50px;margin: 0 3px;">'
171                                                + '             <input type="button" id="incluir" name="incluir" value=">>" onclick="EsearchE.add_mailboxes()">'
172                                                + '             <br style="margin-bottom:15px">'
173                                                + '             <input type="button" id="excluir" name="excluir" value="<<" onclick="EsearchE.del_mailboxes()">'
174                                                + '     </div>'
175                                                + ' <div style="float:left;">'
176                                                + '      <select multiple id="sel_search_nm_box1" name="sel_search_nm_box1" style="width:140px;height:150px;"></select>'
177                                                + ' </div>'
178                                                + '     <br clear="both">'
179                                                + '     <input type="checkBox" id="check_all_msg" name="check_all_msg" onclick="EsearchE.all_mailboxes()">'
180                                                + '     <b>'+get_lang('In all the folders')+'</b>'
181                                                + '</fieldset>';
182
183                return form_sch;
184        }
185
186        // Pastas;
187        searchE.prototype.mount_folders = function()
188        {
189                connector.loadScript("TreeS");
190
191                if( Element("div_folders_search") == null)
192                {
193                        var div_folders = document.createElement("DIV");
194                                div_folders.id = "div_folders_search";
195                                div_folders.style.width = "155px";
196                                div_folders.style.height = "152px";
197                                div_folders.style.borderStyle = "outset";
198                                div_folders.style.borderColor = "black";
199                                div_folders.style.borderWidth = "1px";
200                                div_folders.style.background  = "#F7F7F7";
201                                div_folders.style.overflow = "auto";
202                                div_folders.innerHTML = "";
203                                var dest_div = Element("folders");
204                                dest_div.appendChild(div_folders);
205                }
206                ttree.make_tree($("#div_folders_search")[0],"_folders_tree_search","","","","");
207        }
208       
209        function openpage(data)
210        {
211                var _data                       = [3];
212                var _gears                      = [];
213        var local_folders       = [];
214
215        // Gears - local
216                if ( preferences.use_local_messages == 1 )
217                {
218                        temp = expresso_local_messages.list_local_folders();
219                        for (var x in temp)
220                        {
221                                local_folders.push(temp[x][0]);
222                        }
223                }
224               
225                    if ( local_folders.length > 0 )
226                        _gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
227
228                _data['data']                   = data['data'];
229                _data['num_msgs']               = data['num_msgs'];
230                _data['gears_num_msgs'] = _gears.length;
231
232                delete_border( data['currentTab'], false);
233               
234                EsearchE.mount_result(_data);
235        }
236
237        searchE.prototype.show_paging = function(size)
238        {
239                var span_pg = Element("span_paging"+currentTab);
240               
241                if( span_pg == null )
242                {
243                        span_pg         = document.createElement('span');
244                        span_pg.id      = "span_paging"+currentTab;
245                }
246                else
247                        span_pg.innerHTML = "";
248 
249                if(size > parseInt(preferences.max_email_per_page)) {
250                        this.totalPages = Math.ceil(size/preferences.max_email_per_page);
251                        if((size/preferences.max_email_per_page) > this.totalPages)
252                        this.totalPages++;
253                }
254 
255                if(this.page != 0 && this.page != null) {
256                        _link = document.createElement("A");
257                if( this.value )
258                  _link.href  = 'javascript:EsearchE.quickSearchMail( false, '+0+', false, "'+currentTab+'" )';
259                else{
260            _link.href  = 'javascript:EsearchE.page=0;';
261            _link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page=0&current_tab='+currentTab+'");';
262        }
263        }
264        else {
265            _link = document.createElement("SPAN");
266                }
267                span_pg.appendChild(_link);
268 
269                _link.innerHTML = "&lt;&lt;";
270        _link.title = get_lang("First");
271        span_pg.innerHTML += "&nbsp;";
272 
273                if(this.page == this.lastPage + (this.numPages))
274                {
275                        this.lastPage = this.page - 1;
276                }
277                else if((this.lastPage != 0 && this.lastPage == this.page) || this.page == (this.totalPages-1))
278                {
279                        this.lastPage = this.page - (this.numPages - 1);
280                }
281                else if(this.page == 0)
282                {
283                        this.lastPage = 0;
284                }
285 
286                if(this.lastPage < 0)
287                        this.lastPage = 0;
288                else if(this.lastPage > 0 && (this.lastPage > (this.totalPages -(this.numPages - 1))))
289                        this.lastPage = this.totalPages -(this.numPages);
290 
291                var hasMarked = false;
292                if(this.page == null){
293                        this.page = 0;
294                }
295                for(i = this.lastPage; i <= this.totalPages; i++)
296                {
297                        if( ( i * preferences.max_email_per_page ) > size)
298                        {
299                                break;
300                        }
301                 
302                        if( this.page == i || (i == this.totalPages && !hasMarked) )
303                        {
304                                var _link = document.createElement('span');
305                                _link.setAttribute("style", "font-weight:bold; color:red")
306                                _link.innerHTML = ( this.page + 1 ) + "&nbsp;&nbsp;";
307                        }
308                        else
309                        {
310                                var _page = i;
311                                var _link = document.createElement('A');
312                                _link.innerHTML = ( _page + 1 ) + "&nbsp;&nbsp;";
313                                if( this.value )
314                                _link.href = 'javascript: EsearchE.quickSearchMail( false, '+i+', false, "'+currentTab+'" )';
315                                else{
316                                _link.href  = 'javascript:EsearchE.page='+i+';';
317                                _link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+_page+'&current_tab='+currentTab+'");';
318                                }
319                        }
320                        _link.innerHTML = "&nbsp;...&nbsp;";
321                        if(i == (this.lastPage + this.numPages))
322                        {
323                                span_pg.appendChild( _link );
324                                break;
325                        }
326                        else if(this.lastPage == 0 || i != this.lastPage)
327                        {
328                                _link.innerHTML = "&nbsp;"+( i + 1 )+"&nbsp;";
329                        }
330                                //span_pg.innerHTML += "&nbsp;";
331 
332                                span_pg.appendChild( _link );
333                }
334 
335                        if(this.page != (this.totalPages - 1)) {
336                                _link = document.createElement("A");
337                                if( this.value )
338                                _link.href = 'javascript: EsearchE.quickSearchMail( false, '+(this.totalPages-1)+', false, "'+currentTab+'" )';
339                                else{
340                                _link.href  = 'javascript:EsearchE.page='+(this.totalPages-1)+';';
341                                _link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+(this.totalPages-1)+'&current_tab='+currentTab+'");';
342                                }
343                        }
344                else {
345                _link = document.createElement("SPAN");
346                        }
347 
348                        span_pg.innerHTML += "&nbsp;";
349                        span_pg.appendChild(_link);
350                         
351                        _link.title = get_lang("Last");
352                        _link.innerHTML += "&gt;&gt;";
353 
354                        Element("div_menu_c3").appendChild(span_pg);
355        }
356
357        searchE.prototype.searchFor = function( borderID, sortType )
358        {
359                var border_id   = borderID;
360                var sort_type   = sortType;
361                var is_local = border_id.match('.*_local_.*');
362                if(!is_local)
363                        if( this.value )
364                                return this.quickSearchMail( document.getElementsByName(currentTab)[0].value, false, sortType, border_id );
365 
366                var args   = "$this.imap_functions.search_msg";
367                var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type="+sort_type;
368
369                var handler = function( data )
370                {
371                var allMsg                      = [3];
372                var gears                       = [];
373                var local_folders       = [];
374
375                if ( preferences.use_local_messages == 1 && is_local)
376                {
377                        temp = expresso_local_messages.list_local_folders();
378                       
379                        for (var x in temp)
380                        {
381                                local_folders.push( temp[x][0] );
382                        }
383
384               
385                        if ( local_folders.length > 0 ){
386                                                        var currentSearch = document.getElementsByName(currentTab);
387                            expresso_local_messages.setSortType(sortType);
388                            gears = expresso_local_messages.search( local_folders, "##ALL <=>"+currentSearch[0].value +"##" );
389                        }
390                }
391                if (!is_local)
392            {
393                                if( data['num_msgs'])
394                                {
395                                        allMsg['data']                          = data['data'];
396                                        allMsg['num_msgs']                      = data['num_msgs'];
397                                       
398                                }
399                        }
400
401            if (gears.length > 0)
402            {
403                allMsg['data_gears']                    = gears;
404            }
405               
406                        var currentSearch = document.getElementsByName(currentTab)[0].value;
407                       
408                delete_border( border_id, false );
409                       
410                        EsearchE.mount_result( allMsg , sort_type, null, null, null, currentSearch );
411                };
412
413                if (is_local)
414                {
415                    eval("handler('none')");
416                }
417                else
418                {
419                    cExecute(args,handler,params);
420                }
421        }
422       
423        searchE.prototype.viewLocalMessage = function()
424        {
425                var data                        = [2];
426                var gears                       = [];
427                var local_folders       = [];
428               
429        // Gears - local
430                if ( preferences.use_local_messages == 1 )
431                {
432                        temp = expresso_local_messages.list_local_folders();
433                       
434                        for (var x in temp)
435                        {
436                                local_folders.push( temp[x][0] );
437                        }
438
439                        if ( local_folders.length > 0 ){
440                                var currentSearch = document.getElementsByName(currentTab);
441                                if(currentSearch[0].value != ''){
442                                        gears = expresso_local_messages.search( local_folders, "##ALL <=>"+currentSearch[0].value +"##");
443                                }else{
444                                        if(openTab.condition[currentTab]){
445                                                var condit = openTab.condition[currentTab][0].split(',');
446                                                var filter = condit[0].split('##');
447                                                gears = expresso_local_messages.search( local_folders, '##'+filter[1]+'##');
448                                               
449                                        }
450                               
451                                }
452                        }
453
454                        data['data_gears']      = gears;
455                        data['num_msgs']        = gears.length;
456       
457                        if(data['num_msgs'] != undefined)
458                                write_msg( data['num_msgs'] + " " + get_lang("results found") );
459                                               
460                        EsearchE.mount_result( data, 'SORTDATE' );
461                }
462        }
463       
464        searchE.prototype.make_tr_message = function(aux,border_id,i) {
465                var tr = document.createElement("TR");
466                if(typeof(preferences.line_height) != 'undefined')
467                        tr.style.height = preferences.line_height;
468
469                var mailbox = aux.boxname;
470                var uid_msg = aux.uid;
471                var subject = aux.subject;
472
473                tr.id = uid_msg+"_s"+numBox;
474
475                // Keep the two lines together please
476                tr.setAttribute('name',mailbox);
477                tr.name = mailbox;
478
479                if ( aux.flag.match("U") )
480                        add_className(tr,'tr_msg_unread');
481
482                add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
483
484                var _onclick = function()
485                {
486                        proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);
487                };
488
489                for(var j=0 ; j <= 10 ; j++)
490                {
491                        var td = document.createElement("TD");
492                        add_className(td, 'td_msg');
493                        if (j == 0)
494                        {
495                                td.setAttribute("width", colSizes[1][0]);
496                                var chk_onclick;
497                                if (is_ie)
498                                        chk_onclick = "changeBgColor(window.event,"+uid_msg+");";
499                                else
500                                        chk_onclick = "changeBgColor(event,"+uid_msg+");";                              //'search_' + numBox
501                                var td1 = '<input type="checkbox" onclick="' + chk_onclick + '" id="' + border_id + '_check_box_message_'+uid_msg+'"></input>';
502
503                        }
504                        if (j == 1)
505                        {
506                                td.setAttribute("width", colSizes[1][1]);
507                                if (aux.flag.match('T'))
508                                {
509                                        attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
510                                        td1 = "<img src='templates/"+template+"/images/clip.gif'>";
511                                }
512                                else
513                                        td1 = '';
514                        }
515                        if (j == 2)
516                        {
517                                td.setAttribute("width", colSizes[1][2]);
518                                td.id = "td_message_answered_"+uid_msg;
519                                if (aux.flag.match('X'))
520                                        td1 = '<img src=templates/'+template+'/images/forwarded.gif title="'+get_lang('Forwarded')+'">';
521                                else
522                                        if (aux.flag.match('A'))
523                                                td1 = '<img src=templates/'+template+'/images/answered.gif title="'+get_lang('Answered')+'">';
524                                        else
525                                                td1 = '';
526                        }
527                        if (j == 3)
528                        {
529                                td.setAttribute("width", colSizes[1][3]);
530                                td.id = "td_message_important_"+uid_msg;
531                                if (aux.flag.match("F"))
532                                {
533                                        add_className(tr, 'flagged_msg');
534                                        td1 = "<img src='templates/"+template+"/images/important.gif' title='"+get_lang('Flagged')+"'>";
535                                }
536                                else
537                                        td1 = '';
538                        }
539                        if (j == 4)
540                        {
541                                td.setAttribute("width", colSizes[1][4]);
542                                td.id = "td_message_sent_"+uid_msg;
543                                td1 = '';
544                        }
545
546                        if ( j == 5 )
547                        {
548                                td.setAttribute("width", colSizes[1][5]);
549                                td.className = "td_resizable";
550                                td.onclick = _onclick;
551                                var nm_box = aux.boxname.split(cyrus_delimiter);
552                                var td1 = nm_box.pop();
553                                td.setAttribute("NoWrap","true");
554                                td.style.overflow = "hidden";
555                                td.style.color = "#42795b";
556                                td.style.fontWeight = "bold";
557
558                                var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
559
560                                                                        td1 = translateFolder(td1);
561
562
563                                if( proxy_mensagens.is_local_folder(td1))
564                                {
565                                        var td1 = this.aux_local_folder_display(td1);
566                                }
567                        }
568
569                        if( j == 6 )
570                        {
571                                var name;
572                                if( aux.from.name != undefined){
573                                        name = aux.from.name;
574                                }else{
575                                        name = aux.from;
576                                }
577                                if ( name !== null && name.length > 29)
578                                        name = name.substr(0,29) + "...";
579
580                                td.setAttribute("width", colSizes[1][6]);
581                                td.className = "td_resizable";
582                                td.onclick = _onclick;
583                                td.setAttribute("NoWrap","true");
584                                                                        td.style.overflow = "hidden";
585                                                                       
586                                var td1  =  '<div style="width:100%;overflow:hidden">'+name+"</div>";
587                        }
588
589                        if( j == 7 )
590                        {
591                                var subject_encode = url_encode(subject);
592
593                                if (! subject_encode)
594                                        aux.subject = get_lang("no subject") + "...";
595                                if (aux.subject.length > 70)
596                                        aux.subject = aux.subject.substr(0,70) + "...";
597
598                                td.setAttribute("width", colSizes[1][7]);
599                                td.className = "td_resizable";
600                                td.onclick = _onclick;
601                                td.setAttribute("NoWrap","true");
602                                td.style.overflow = "hidden";
603
604                                var td1  = aux.subject;
605                        }
606
607                        if( j == 8 )
608                        {
609                                td.setAttribute("width", colSizes[1][8]);
610                                td.className = "td_resizable";
611                                td.align                = "center";
612                                td.onclick              = _onclick;
613
614                                if( validate_date( aux.udate ) )
615                                {
616                                        var td1 = aux.udate;
617                                }
618                                else
619                                {
620                                        var dt  = new Date( aux.udate * 1000 );
621                                        var td1  = dt.getDate() + "/";
622
623                                        if( !( dt.getMonth() + 1 ).toString().match(/\d{2}/) )
624                                                td1 += "0"+( dt.getMonth() + 1 ) + "/";
625                                        else
626                                                td1 += ( dt.getMonth() + 1 ) + "/";
627
628                                        td1 += dt.getFullYear();
629                                }
630                        }
631
632                        if( j == 9 )
633                        {
634                                td.setAttribute("width", "9.4%");//alinhamento dos campos data e tamanho
635                                td.className = "td_resizable";
636                                td.align = "center";
637                                td.onclick = _onclick;
638                                if(aux.Size != undefined){
639                                        var td1  = borkb(aux.Size);
640                                }
641                                else{
642                                        var td1  = borkb(aux.size);
643                                }
644                        }
645
646                        if( j == 10 )
647                        {
648                                if (aux.flag.match("U"))
649                                        add_className(tr, 'tr_msg_unread');
650                                if (aux.flag.match("F"))
651                                        add_className(tr, 'flagged_msg');
652                                var td1 = '';
653                        }
654                        if (j<10) {
655                                td.innerHTML = td1;
656                                tr.appendChild(td);
657                        }
658                }
659
660                _dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
661
662                return tr;
663        }
664
665        // Form resultado
666        searchE.prototype.mount_result = function( Data, sort_type, keep_border, keep_filled, division, actualSearch )
667        {
668                var data = ( Data['data'] ) ? Data['data'] : Data['data_gears'];
669               
670                if ( data == undefined )
671                        return;
672               
673                var cont = parseInt(0);
674
675                if ( typeof(sort_type) != 'undefined')
676                        this.sort_type = sort_type;
677                else
678                        sort_type = this.sort_type;
679
680                if ( keep_border ) {
681                        var border_id = currentTab;
682                }
683                else {
684                        if(isNaN(numBox)){
685                                var aux = numBox.split("_");
686                                numBox = parseInt(aux[0]) + 1;
687                        }else{
688                                inc_abas_search++;
689                                numBox = inc_abas_search;
690                        }
691                        if( Data['data'] )
692                                if(!actualSearch)
693                                        var border_id = create_border(get_lang("Server Results"), "search_" + numBox);
694                                else
695                                        var border_id = create_border(get_lang("Server Results"), "search_" + numBox, actualSearch);
696                        if( Data['data_gears'])
697                                if(!actualSearch)
698                                        var border_id = create_border(get_lang("Local Results"), "search_local_msg" + numBox);
699                                else
700                                        var border_id = create_border(get_lang("Local Results"), "search_local_msg" + numBox, actualSearch);
701                }
702
703                if (!border_id)
704            return;
705
706        currentTab = border_id;
707        openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
708        openTab.type[currentTab] = 1;
709                openTab.condition[currentTab] = this.condition;
710
711                if ( keep_border ) {
712                        var content_search =  Element('content_id_' + border_id);
713                        var div_scroll_result = Element("divScrollMain_"+numBox);
714
715                        content_search.removeChild(div_scroll_result);
716
717                        if( !keep_filled )
718                            div_scroll_result = false;
719                }
720
721                var table = document.createElement("TABLE");
722                        table.id    = "table_resultsearch_" + numBox;
723                        table.frame = "void";
724                        table.rules = "rows";
725                        table.cellPadding       = "0";
726                        table.cellSpacing       = "0";
727                        table.className         = "table_box";
728
729                var tbody               = document.createElement("TBODY");
730                        tbody.id        = "tbody_box_" + numBox;
731
732                for( var i=0; i < data.length; i++)
733                {
734                        if(data[i] !== null){
735                        var tr = EsearchE.make_tr_message(data[i],border_id,i);
736            tbody.appendChild(tr);
737                }
738                }
739               
740                //global_search++; //Tabs from search must not have the same id on its tr's // use numBox instead of this!
741               
742                table.appendChild(tbody);
743
744                var colgr_element = buildColGroup(1);
745                colgr_element.setAttribute("id","colgroup_main_"+numBox);
746                table.appendChild(colgr_element);
747
748                var content_search =  Element('content_id_' + border_id);
749               
750                if( !div_scroll_result )
751                {
752                var div_scroll_result = document.createElement("DIV");
753                    div_scroll_result.id = "divScrollMain_"+numBox;
754                div_scroll_result.style.overflowY = "scroll";
755                div_scroll_result.style.overflowX = "hidden";
756                div_scroll_result.style.width   ="100%";
757       
758                if (is_mozilla){
759                        div_scroll_result.style.overflow = "-moz-scrollbars-vertical";
760                        div_scroll_result.style.width   ="100%";
761                }
762                }
763                if( division )
764                {
765                    var _div = document.createElement("div");
766                    _div.className = 'local-messages-search-warning';
767                    _div.innerHTML = division;
768                    div_scroll_result.appendChild(_div);
769                }
770
771                if(is_ie)
772                        Element("border_table").width = "99.5%";
773
774                // Put header
775                var table_element = document.createElement("TABLE");
776                var tbody_element = document.createElement("TBODY");
777                if (is_ie)
778                {
779                        table_element.attachEvent("onmousemove",changeCursorState);
780                        table_element.attachEvent("onmousedown",startColResize);
781                }
782                else {
783                        table_element.addEventListener("mousemove",changeCursorState,false);
784                        table_element.addEventListener("mousedown",startColResize,false);
785                }
786                table_element.setAttribute("id", "table_message_header_box_"+numBox);
787                table_element.className = "table_message_header_box";
788                if (!is_ie)
789                        table_element.style.width = "98.8%";
790                table_element.emptyBody = false;
791
792                tr_element = document.createElement("TR");
793                tr_element.className = "message_header";
794                td_element0 = createTDElement(1,0);
795                chk_box_element = document.createElement("INPUT");
796                if(border_id.indexOf('local') > 0)
797                        chk_box_element.id  = "chk_box_select_all_messages_search_local";
798                else
799                        chk_box_element.id  = "chk_box_select_all_messages_search";
800                chk_box_element.setAttribute("type", "checkbox");
801                chk_box_element.className = "checkbox";
802                chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
803                chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
804                chk_box_element.onkeydown = function (e)
805                {
806                        if (is_ie)
807                        {
808                                if ((window.event.keyCode) == 46)
809                                        delete_msgs(current_folder,'selected','null');
810                        }
811                        else
812                        {
813                                if ((e.keyCode) == 46)
814                                        delete_msgs(current_folder,'selected','null');
815                        }
816                };
817
818                td_element0.appendChild(chk_box_element);
819                td_element01 = createTDElement(1,1);
820                td_element02 = createTDElement(1,2);
821                td_element03 = createTDElement(1,3);
822                td_element04 = createTDElement(1,4);
823                td_element1 = createTDElement(1,5,"th_resizable","left");
824               
825                var arrow_ascendant = function(Text)
826                {
827                        return "<b>" + Text + "</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
828                }
829               
830                // Ordernar Pasta
831                if ( sort_type == 'SORTBOX' /*|| sort_type == 'SORTBOX_REVERSE'*/ )
832                {
833                        if( Data['data'] )
834                        {
835                                td_element1.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTBOX_REVERSE'); };
836                                td_element1.innerHTML   = "<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
837                        }
838                        else
839                        {
840                                td_element1.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTBOX_REVERSE'); };
841                                td_element1.innerHTML   = "<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
842                        }
843                }
844                else
845                {
846                        if( Data['data'] )
847                        {
848                                td_element1.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTBOX'); };
849                        }
850                        else
851                        {
852                                td_element1.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTBOX'); };
853                        }
854                        td_element1.innerHTML   = ( sort_type == 'SORTBOX_REVERSE' ) ? arrow_ascendant(get_lang("Folder")) : get_lang("Folder");
855                }
856               
857                // Ordernar Quem
858                td_element2 = createTDElement(1,6,"th_resizable","left");
859
860                if (sort_type == 'SORTFROM' || sort_type == 'SORTWHO' /*|| sort_type == 'SORTWHO_REVERSE' || sort_type == 'SORTFROM_REVERSE'*/ )
861                {
862                        if(Data['data'])
863                        {
864                                td_element2.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTFROM_REVERSE'); };
865                                td_element2.innerHTML   = "<b>"+get_lang("From")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
866                        }
867                        else
868                        {
869                                td_element2.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTWHO_REVERSE'); };
870                                td_element2.innerHTML   = "<b>"+get_lang("From")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
871                        }
872                }
873                else
874                {
875                        if( Data['data'] )
876                        {
877                                td_element2.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTWHO'); };
878                        }
879                        else
880                        {
881                                td_element2.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTWHO'); };
882                        }
883                        td_element2.innerHTML   = ( sort_type == 'SORTWHO_REVERSE' ) ? arrow_ascendant(get_lang("From")) : get_lang("From");
884                }
885               
886                // Ordernar Subject
887                td_element3 = createTDElement(1,7,"th_resizable","left");
888               
889                if (sort_type == 'SORTSUBJECT' /*|| sort_type == 'SORTSUBJECT_REVERSE'*/)
890                {
891                        if( Data['data'])
892                        {
893                                td_element3.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT_REVERSE'); };
894                                td_element3.innerHTML   = "<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";                               
895                        }
896                        else
897                        {
898                                td_element3.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT_REVERSE'); };
899                                td_element3.innerHTML   = "<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
900                        }
901                }
902                else
903                {
904                        if( Data['data'] )
905                        {
906                                td_element3.onclick             = function(){ EsearchE.searchFor( border_id, 'SORTSUBJECT'); };
907                        }
908                        else
909                        {
910                                td_element3.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT'); };
911                        }
912                        td_element3.innerHTML   = ( sort_type == 'SORTSUBJECT_REVERSE' ) ? arrow_ascendant(get_lang("subject")) : get_lang("subject");
913                }
914               
915                // Ordernar Data
916                td_element4 = createTDElement(1,8,"th_resizable","center");
917               
918                if ( sort_type == 'SORTDATE' /*|| sort_type == 'SORTDATE_REVERSE'*/ )
919                {
920                        if( Data['data'] )
921                        {
922                                td_element4.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTDATE_REVERSE'); };
923                                td_element4.innerHTML   = "<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
924                        }
925                        else
926                        {
927                                td_element4.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTDATE_REVERSE'); };
928                                td_element4.innerHTML   = "<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
929                        }
930                }
931                else
932                {
933                        if( Data['data'] )
934                        {
935                                td_element4.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTDATE'); };
936                        }
937                        else
938                        {
939                                td_element4.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTDATE'); };
940                        }
941                        td_element4.innerHTML   = ( sort_type == 'SORTDATE_REVERSE' ) ? arrow_ascendant(get_lang("Date")) : get_lang("Date");
942                }                       
943
944                // Ordernar Tamanho
945                td_element5 = createTDElement(1,9,"th_resizable","center");
946               
947                if ( sort_type == 'SORTSIZE' /*|| sort_type == 'SORTSIZE_REVERSE'*/ )
948                {
949                        if( Data['data'] )
950                        {
951                                td_element5.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSIZE_REVERSE'); };
952                                td_element5.innerHTML   = "<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";                         
953                        }
954                        else
955                        {
956                                td_element5.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSIZE_REVERSE'); };
957                                td_element5.innerHTML   = "<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
958                        }
959                }
960                else
961                {
962                        if( Data['data'] )
963                        {       
964                                td_element5.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSIZE'); };
965                        }
966                        else
967                        {
968                                td_element5.onclick             = function(){ EsearchE.searchFor(border_id, 'SORTSIZE'); };
969                        }
970                        td_element5.innerHTML   = ( sort_type == 'SORTSIZE_REVERSE' ) ? arrow_ascendant(get_lang("size")) : get_lang("size");
971                }
972               
973                tr_element.appendChild(td_element0);
974                tr_element.appendChild(td_element01);
975                tr_element.appendChild(td_element02);
976                tr_element.appendChild(td_element03);
977                tr_element.appendChild(td_element04);
978                tr_element.appendChild(td_element1);
979                tr_element.appendChild(td_element2);
980                tr_element.appendChild(td_element3);
981                tr_element.appendChild(td_element4);
982                tr_element.appendChild(td_element5);
983                tbody_element.appendChild(tr_element);
984                table_element.appendChild(tbody_element);
985
986                var colgr_element = buildColGroup(1);
987                colgr_element.setAttribute("id","colgroup_head_"+numBox);
988                table_element.appendChild(colgr_element);
989
990                if( parseInt( Data['gears_num_msgs'] ) > 0 && !keep_filled)
991                {
992                        var messagesWarning = document.getElementById("local-messages-search-warning_"+border_id);
993                                if(!messagesWarning){
994                                        var _div_gears = document.createElement("div");
995                                        _div_gears.id = "local-messages-search-warning_"+border_id;
996                                        _div_gears.onclick = function(){ EsearchE.viewLocalMessage(); };
997                                        _div_gears.className = 'local-messages-search-warning';
998                                        _div_gears.innerHTML = get_lang("The search has% 1 messages stored locally. Want to see them ? Click here.", Data['gears_num_msgs']);
999                                        content_search.appendChild(_div_gears);         
1000                                }
1001                }               
1002
1003                var _divScroll = document.getElementById("divScrollHead_"+numBox);
1004               
1005                if( _divScroll ){
1006                        content_search.removeChild(_divScroll);
1007                        _divScroll = false;
1008                }
1009
1010                        _divScroll = document.createElement("DIV");
1011                _divScroll.id = "divScrollHead_"+numBox;
1012                        _divScroll.style.overflowY = "hidden";
1013                        _divScroll.style.overflowX = "hidden";
1014                        _divScroll.style.width  ="100%";
1015
1016                        if (is_mozilla){
1017                                _divScroll.style.width  ="99.3%";
1018                        }
1019                        _divScroll.appendChild(table_element);
1020                        content_search.appendChild(_divScroll);
1021
1022                /*end of "put header"*/
1023                if ( !expresso_offline )
1024                {
1025                        div_scroll_result.appendChild(table);
1026                        content_search.appendChild(div_scroll_result);
1027                }
1028                else
1029                {
1030                        div_scroll_result.appendChild(table);
1031                        content_search.appendChild(div_scroll_result);
1032                }
1033               
1034                resizeWindow();
1035                if(typeof(Data.data_gears)=="undefined")
1036                    EsearchE.show_paging( Data['num_msgs'] );
1037        }
1038
1039        searchE.prototype.open_msg = function(mailbox, uid_msg, subject)
1040        {
1041                var handler_get_msg = function(data)
1042                {
1043                        if( Element("border_id_" + uid_msg + "_r") )
1044                                alert(get_lang("This message is already opened!"));
1045                        else
1046                                draw_message( data, create_border(url_decode(subject), uid_msg + "_r") );
1047                }
1048               
1049                proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
1050        }
1051
1052        // Adiciona caixas postais na busca;
1053        searchE.prototype.add_mailboxes = function()
1054        {
1055                var sel = Element("sel_search_nm_box1");
1056                if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
1057                        var name_box     = this.name_box_search.split(cyrus_delimiter);
1058                        if(this.name_box_search == "")
1059                                return false;
1060                        var name_box_def = "";
1061                        if(name_box.length != 1){
1062                                name_box_def = name_box[(name_box.length-1)];
1063                        }else{
1064                                name_box_def = get_lang("Inbox");
1065                        }
1066                }
1067                else {
1068                        if(this.name_box_search=='local_root')
1069                                return;
1070                        if(this.name_box_search=='local_Inbox')
1071                                name_box_def = get_lang("Inbox");
1072                        else if(this.name_box_search.indexOf("/")!="-1") {
1073                                final_pos = this.name_box_search.lastIndexOf("/");
1074                                name_box_def = this.name_box_search.substr(final_pos+1);
1075                        }
1076                        else
1077                                name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
1078                }
1079                if( sel.length > 0){
1080                        for(var i=0; i < sel.options.length; i++){
1081                                if(sel.options[i].value == this.name_box_search){
1082                                        alert(get_lang('This message is already selected!'));
1083                                        return false;
1084                                }
1085                        }
1086                }
1087                name_box_def = translateFolder(name_box_def);
1088                var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
1089                sel[sel.length] = opt;
1090        }
1091
1092        //      Remove as caixas postais na busca;
1093        searchE.prototype.del_mailboxes = function()
1094        {
1095                var sel = Element("sel_search_nm_box1");
1096                if(sel.length > 0)
1097                {
1098                        for(var i=0; i < sel.options.length; i++)
1099                        {
1100                                if(sel.options[i].selected == true)
1101                                {
1102                                        sel.options[i] = null;
1103                                        i--;
1104                                }
1105                        }
1106                }
1107
1108        }
1109
1110        // todas as caixas
1111        searchE.prototype.all_mailboxes = function()
1112        {
1113                var value = Element("check_all_msg").checked;
1114                var cont = parseInt(0);
1115                if(value)
1116                {
1117                        if(EsearchE.all_boxes.length > 0)
1118                        {
1119                                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
1120                        }
1121                        for(var i=0; i < folders.length; i++)
1122                        {
1123                                EsearchE.all_boxes[cont++] = folders[i].folder_id;
1124                        }
1125                }
1126                else
1127                {
1128                        EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
1129                }
1130        }
1131
1132        // Search;
1133        searchE.prototype.func_search_complex = function()
1134        {
1135                var fields = "##";
1136                        // Verifica se os campos estão preenchidos;
1137                        if(trim(Element("txt_ass").value) != ""){
1138                                fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
1139                        }
1140                        if(trim(Element("txt_body").value) != ""){
1141                                fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
1142                        }
1143                        if(trim(Element("txt_de").value) != ""){
1144                                fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
1145                        }
1146                        if(trim(Element("txt_para").value) != ""){
1147                                fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
1148                        }
1149                        if(trim(Element("txt_cc").value) != ""){
1150                                fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
1151                        }
1152            if (trim(Element("since_date").value) != "")
1153            {
1154                if (validate_date(Element("since_date").value))
1155                {
1156                    fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##";
1157                }
1158                else
1159                {
1160                        alert(get_lang('Invalid date on field %1', get_lang('Since Date')));
1161                        return false;
1162                }
1163            }
1164
1165            if (trim(Element("before_date").value) != "")
1166            {
1167                if (validate_date(Element("before_date").value))
1168                {
1169                    fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##";
1170                }
1171                else
1172                    {
1173                        alert(get_lang('Invalid date on field %1', get_lang('Before Date')));
1174                        return false;
1175                    }
1176            }
1177                        if ((trim(Element("since_date").value) != "") && (trim(Element("before_date").value) != "")){
1178                                if(!(validate_date_order(trim(Element("since_date").value), trim(Element("before_date").value)))){
1179                                        alert(get_lang('Invalid date on field %1', get_lang('Before Date')));
1180                    return false;
1181                                }
1182                        }
1183            if(trim(Element("on_date").value) != "")
1184            {
1185                if (validate_date(Element("on_date").value))
1186                {
1187                    fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##";
1188                }
1189                else
1190                {
1191                        alert(get_lang('Invalid date on field %1', get_lang('On Date')));
1192                    return false;
1193                }
1194
1195            }
1196
1197            if(trim(Element("flagged").options[Element("flagged").selectedIndex].value) != "")
1198            {
1199                if (Element("flagged").options[Element("flagged").selectedIndex].value == "FLAGGED")
1200                {
1201                    fields += "FLAGGED##";
1202                }
1203                else
1204                {
1205                    fields += "UNFLAGGED##";
1206                }
1207            }
1208
1209            if(trim(Element("seen").options[Element("seen").selectedIndex].value) != "")
1210            {
1211                if (Element("seen").options[Element("seen").selectedIndex].value == "SEEN")
1212                {
1213                    fields += "SEEN##";
1214                }
1215                else
1216                {
1217                    fields += "UNSEEN##";
1218                }
1219            }
1220           
1221            if(trim(Element("answered").options[Element("answered").selectedIndex].value) != "")
1222            {
1223                if (Element("answered").options[Element("answered").selectedIndex].value == "ANSWERED"){
1224                    fields += "ANSWERED##";
1225                }
1226                else {
1227                    fields += "UNANSWERED##";
1228                }
1229            }
1230           
1231            if(trim(Element("recent").options[Element("recent").selectedIndex].value) != "")
1232            {
1233                if (Element("answered").options[Element("answered").selectedIndex].value == "RECENT")
1234                {
1235                    fields += "RECENT##";
1236                }
1237                else
1238                {
1239                    fields += "OLD##";
1240                }
1241            }
1242
1243                if(fields == "##")
1244                {
1245                        alert(get_lang("Define some search parameters!"));
1246                        return false;
1247                }
1248               
1249                var local_folders = new Array();
1250                var temp;
1251
1252                if( Element("check_all_msg").checked )
1253                {
1254                        this.all_mailboxes();
1255                        var nm_box = new Array;
1256                        for(var i=0; i < EsearchE.all_boxes.length; i++)
1257                        {
1258                                nm_box[i] = EsearchE.all_boxes[i] + fields;
1259                        }
1260                        if (preferences.use_local_messages == 1)
1261                        {
1262                                temp = expresso_local_messages.list_local_folders();
1263                                for (var x in temp)
1264                                {
1265                                        local_folders.push(temp[x][0]);
1266                                }
1267                        }
1268                }
1269                else
1270                {
1271                        var nm_box = new Array;
1272                        var sel_combo = Element("sel_search_nm_box1");
1273                       
1274                        if( sel_combo.options.length <= 0)
1275                        {
1276                                alert(get_lang("Define the boxes to search!"));
1277                                return false;
1278                        }
1279
1280                        for(var i=0; i < sel_combo.options.length; i++)
1281                        {
1282                                sel_combo.options[i].selected = true;
1283                        }
1284                       
1285                        for(var i=0; i < sel_combo.options.length; i++)
1286                        {
1287                                if( sel_combo.options[i].selected == true )
1288                                {
1289                                        if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
1290                                                nm_box[nm_box.length] = sel_combo.options[i].value + fields;
1291                                        else
1292                                                local_folders.push(sel_combo.options[i].value.substr(6));
1293                                }
1294                        }
1295                }
1296               
1297            var handler = function( data )
1298            {
1299                var allMsg      = [3];
1300                                var count       = ( data['num_msgs'] ) ?  data['num_msgs'] : "0";
1301                                var tmp         = [];
1302
1303                                // Gears - local
1304                                if ( local_folders.length > 0 ){
1305                                        expresso_local_messages.setSortType('SORTDATE');
1306                                        tmp = expresso_local_messages.search( local_folders, fields );
1307                                }
1308
1309                                if( data['num_msgs'] )
1310                                {
1311                                        allMsg['data']          = data['data'];
1312                                        allMsg['num_msgs']      = data['num_msgs'];
1313                                }
1314
1315                                if( tmp.length > 0 )
1316                                {
1317                                        allMsg['gears_num_msgs'] = tmp.length ;
1318                                }
1319
1320                                if( ( data['num_msgs'] ) == 0 )
1321                                {
1322                                        alert( get_lang("None result was found.") );
1323                                }
1324                                else
1325                                {
1326                                        if( (tmp.length > 0) && (!data['num_msgs']) )
1327                                        {
1328                                                EsearchE.viewLocalMessage();
1329                                        }
1330                                        else
1331                                        {
1332                                                if(count > 0)
1333                                                        EsearchE.func_clean();
1334                                                write_msg( count + " " + get_lang("results found") );
1335                                                EsearchE.mount_result( allMsg, 'SORTDATE' );
1336                                        }
1337                                }
1338            }
1339
1340            this.condition      = nm_box;
1341            this.page           = 0;
1342            var args            = "$this.imap_functions.search_msg";
1343            var params          = "condition=" + nm_box+ "&page=0"+ "&sort_type=SORTDATE";
1344
1345            if( expresso_offline )
1346                    handler('none');
1347            else
1348                    cExecute( args, handler, params);
1349        }
1350       
1351        searchE.prototype.func_search = function(value, page, sort, border_id)
1352        {
1353          if( !value )
1354              this.func_search_complex();
1355          else
1356            this.quickSearchMail( value, page, sort, border_id );
1357        }
1358       
1359        searchE.prototype.quickSearchMail = function(value, page, sort, border_id)
1360        {
1361                var local_folders = new Array();
1362                var temp;
1363                var not_found_corrent_folder = true;
1364
1365//              if( Element("check_all_msg").checked )
1366//              {
1367                        this.all_mailboxes();
1368                        var nm_box = new Array;
1369                        for(var i=0; i < EsearchE.all_boxes.length; i++)
1370                        {
1371                                nm_box[i] = EsearchE.all_boxes[i]/* + fields*/;
1372                        }
1373                        if (preferences.use_local_messages == 1)
1374                        {
1375                                temp = expresso_local_messages.list_local_folders();
1376                                for (var x in temp)
1377                                {
1378                                        local_folders.push(temp[x][0]);
1379                                }
1380                        }
1381                this.sort               = sort || this.sort || "SORTDATE";
1382                this.page               = isNaN(page) ? ( value ? 0 : this.page ) : page;
1383                this.value              = value || this.value || false;
1384                               
1385                if( !this.value )
1386                    return alert( "Busca sem caracteres." );
1387
1388                var args                = "$this.imap_functions.quickSearchMail";
1389                var params              = { page: this.page, sort: this.sort, search: this.value };
1390
1391                var selection1 = [], selection2 = [];
1392
1393                for( var i = 0; i < nm_box.length; i++ )
1394                    if( nm_box[i] === current_folder )
1395                        continue;
1396                    else if( /^user/.test(nm_box[i]) )
1397                        selection2[selection2.length] = nm_box[i];
1398                    else
1399                        selection1[selection1.length] = nm_box[i];
1400
1401                 if( expresso_offline )
1402                            handler('none');
1403                 else
1404                 {
1405                            var url = [], labels = [];
1406
1407                            params['folder'] = current_folder;
1408                            url[0] = args + "&" +  $.param( params );
1409                            labels[0] = "mensagem na sua pasta atual";
1410
1411                            if(selection1.length)
1412                            {
1413                                        params['folder'] = selection1;
1414                                        url[1] = args + "&" +  $.param( params );
1415                                        labels[1] = "mensagens nas suas outras pastas";
1416                                }
1417                                if(selection2.length)
1418                            {
1419                                        params['folder'] = selection2;
1420                                        url[2] = args + "&" +  $.param( params );
1421                                        labels[2] = "mensagens nas suas pastas compartilhadas";
1422                                }
1423                            var link = ' <a href="#" onclick="connector.cancelRequest(); clean_msg(); return false;">cancelar<a/>';
1424
1425                            write_msg( "pesquisando " + labels[0] + link, true );
1426                           
1427                            var keepFilled = false;
1428
1429                            var handler = function( data )
1430                            {
1431                                        data = $.parseJSON( Base64.decode(data) );
1432           
1433                                        var allMsg      = {
1434                                                num_msgs: ( data['num_msgs'] || 0 ),
1435                                                data: ( data['data'] || data['msgs'] || data )
1436                                        };
1437
1438                                        // Gears - local
1439                                        if ( local_folders.length > 0 ){
1440                                                expresso_local_messages.setSortType('SORTDATE');
1441                                                var tmp = expresso_local_messages.search( local_folders, "##ALL <=>" + url_encode(value) + "##" );
1442
1443                                                if( tmp.length > 0 )
1444                                                        if( !allMsg['num_msgs'] ){
1445                                                                clean_msg();
1446                                                            not_found_corrent_folder = false;
1447                                                                if(tmp.length)
1448                                                                        allMsg['gears_num_msgs'] = tmp.length;
1449                                                        }else
1450                                                                allMsg['gears_num_msgs'] = tmp.length;
1451        }
1452
1453                                        if( !allMsg['num_msgs'] && !url.length && not_found_corrent_folder){
1454                                                clean_msg();
1455                                                //alert( get_lang("None result was found.") );
1456                                                return EsearchE.viewLocalMessage();
1457                                        }
1458
1459                                        if( allMsg['num_msgs'] )
1460                                                EsearchE.total = allMsg['num_msgs'] = Math.max( (EsearchE.total || 0), allMsg['num_msgs'] );   
1461
1462                                        EsearchE.mount_result( allMsg, EsearchE.sort, ( keepFilled || border_id === currentTab ), keepFilled, "Foram encontradas " + data['msgs'].length + " "+labels.shift()+"." );
1463                                       
1464                                        keepFilled = true;
1465                                       
1466                                        write_msg( "pesquisando " + labels[0] + link, true );
1467
1468                                        if( url.length )
1469                                                cExecute( url.shift(), handler );
1470                                        else
1471                                                clean_msg();
1472                            }
1473
1474                            cExecute( url.shift(), handler );
1475                    }
1476        }
1477       
1478// clean;
1479        searchE.prototype.func_clean = function()
1480        {
1481                // Limpa os campos;
1482                for( var i=0; i < this.txtfields.length; i++ )
1483                {
1484                        if( Element(this.txtfields[i]) != null )
1485                                Element(this.txtfields[i]).value = "";
1486                }
1487
1488        for(i = 0; i < this.selectFields.length; i++)
1489        {
1490            if (Element(this.selectFields[i]))
1491                Element(this.selectFields[i]).selectedIndex = 0;
1492        }
1493       
1494            if( Element("check_all_msg") != null )
1495                Element("check_all_msg").checked = false;
1496
1497            EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
1498                EsearchE.del_mailboxes();
1499                $("#since_date, #before_date").datepicker("option", "minDate", "");
1500                $("#since_date, #before_date").datepicker("option", "maxDate", "");
1501        }
1502
1503        // close
1504        searchE.prototype.func_close = function(type)
1505        {
1506                var _this = this;
1507                _this.name_box_search = "";
1508                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
1509                _this.type = type;
1510                _this.searchW['window_search'].close();
1511                $("#since_date, #before_date, #on_date").datepicker( "destroy" );
1512        }
1513        // Monta a janela em tela;
1514        searchE.prototype.showWindow = function(div)
1515        {
1516                if(!this.searchW[div.id])
1517                {
1518                        div.style.width = "804px";
1519                        div.style.height = "440px";
1520                        div.style.visibility = "hidden";
1521                        div.style.position = "absolute";
1522                        div.style.zIndex = "10";
1523                        var title = ":: "+ get_lang("Search")+" ::";
1524                        var wHeight = div.offsetHeight + "px";
1525                        var wWidth =  div.offsetWidth   + "px";
1526
1527                        win = new dJSWin({
1528                                id: 'ccList'+div.id,
1529                                content_id: div.id,
1530                                width: wWidth,
1531                                height: wHeight,
1532                                title_color: '#3978d6',
1533                                bg_color: '#eee',
1534                                title: title,
1535                                title_text_color: 'white',
1536                                button_y_img: '../phpgwapi/images/win_min.gif',
1537                                button_x_img: '../phpgwapi/images/winclose.gif',
1538                                border: true});
1539                        this.searchW[div.id] = win;
1540                        win.draw();
1541                }
1542                else
1543                {
1544                        var _this = this;
1545                        win = this.searchW[div.id];
1546                        if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
1547                        win.draw();
1548                }
1549                win.open();     
1550        }
1551
1552        searchE.prototype.aux_local_folder_display = function(folder)
1553        {
1554                if(!expresso_offline)
1555                        return "(Local) " + lang_folder(folder.substr(6));
1556                else
1557                        return lang_folder(folder.substr(6));
1558        }
1559
1560        searchE.prototype.refresh = function(alert_new_msg){
1561                var handler_refresh = function(data){
1562                        var allMsg      = [3];
1563                        var count       = ( data['num_msgs'] ) ?  data['num_msgs'] : "0";
1564
1565                        if( data['num_msgs'] )
1566                        {
1567                                allMsg['data']          = data['data'];
1568                                allMsg['num_msgs']      = data['num_msgs'];
1569                        }
1570
1571                        if( ( data['num_msgs'] ) == 0 )
1572                        {
1573                                alert( get_lang("None result was found.") );
1574                        }
1575                        else
1576                        {
1577                                if( data['num_msgs'] )
1578                                {
1579                                        write_msg( count + " " + get_lang("results found") );
1580                                        EsearchE.mount_result( allMsg, 'SORTDATE', true );
1581                                }
1582                        }
1583                }
1584
1585                this.condition  = openTab.condition[currentTab];
1586
1587                var sort_type = (this.sort_type ? this.sort_type : 'SORTDATE');
1588
1589                if( expresso_offline )
1590                        handler('none');
1591                else
1592                        cExecute( "$this.imap_functions.search_msg", handler_refresh, "condition="+openTab.condition[currentTab]+"&page="+EsearchE.page+"&sort_type="+sort_type);
1593        }
1594
1595
1596// Cria o objeto
1597        var EsearchE;
1598        EsearchE = new searchE();
Note: See TracBrowser for help on using the repository browser.