/**************************************************************************\ Início \**************************************************************************/ function searchE() { this.searchW = new Array; this.name_box_search = ""; this.all_boxes = new Array; this.type = ""; this.txtfields = new Array("txt_ass","txt_de","txt_body","txt_para","txt_cc","txt_cco", "since_date", "before_date", "on_date"); this.selectFields = new Array("flagged", "seen", "answered", "recent"); } //Monta os forms dentro da janela; searchE.prototype.showForms = function(value){ // Principal if(!Element("window_search")) { var form_search = document.createElement("DIV"); form_search.style.visibility = 'hidden'; form_search.style.top = '0px'; form_search.style.left = '0px'; form_search.id = "window_search"; document.body.appendChild(form_search); } // Pesquisa if(!Element("div_form_search")){ var div_form_search = document.createElement("DIV"); div_form_search.id = "div_form_search"; div_form_search.style.position = "absolute"; div_form_search.style.left = "10px"; div_form_search.style.top = "10px"; div_form_search.style.width = "784px"; div_form_search.style.height = "418px"; div_form_search.style.overflow = "hidden"; div_form_search.innerHTML = ""; var call_form_search = EsearchE.mount_form(); div_form_search.appendChild(call_form_search); form_search.appendChild(div_form_search); try{ Calendar._TT['WEEKEND'] = '0,6'; // hack Calendar._TT['DAY_FIRST'] = 'Mostrar %s primeiro'; Calendar.setup({ inputField : 'since_date', button : 'since_date-trigger', ifFormat : '%d/%m/%Y', daFormat : '%d/%m/%Y' }); Calendar.setup({ inputField : 'before_date', button : 'before_date-trigger', ifFormat : '%d/%m/%Y', daFormat : '%d/%m/%Y' }); Calendar.setup({ inputField : 'on_date', button : 'on_date-trigger', ifFormat : '%d/%m/%Y', daFormat : '%d/%m/%Y' }); }catch(e){ expresso.connector.loadScript('../../calendar/js/calendar-setup'); } } if(!Element("div_button_search")){ var div_button_search = document.createElement("DIV"); div_button_search.id = "div_button_search"; div_button_search.style.position = "absolute"; div_button_search.style.marginLeft = "430px"; div_button_search.style.top = "223px"; div_button_search.style.width = "350px"; div_button_search.style.height = "25px"; div_button_search.innerHTML = ""+ ""+ ""+ ""+ ""+ ""+ "
"; form_search.appendChild(div_button_search); } if(!Element("table_layer")){ var table_layer = ""; } if(value == "") EsearchE.showWindow(Element("window_search")); // Cria as caixas postais; EsearchE.mount_folders(); if(value){ Element("check_all_msg").checked = true; EsearchE.all_mailboxes(); EsearchE.func_search(value); } } //Form searchE.prototype.mount_form = function(value){ var form_sch = document.createElement("FORM"); form_sch.id = "form_sch"; form_sch.innerHTML = '
' + ' '+get_lang('Inform your search in the text fields')+'' + ' ' + ' ' + '
' + ' ' + ' ' + '
' + ' ' + ' ' + '
' + ' ' + ' ' + '
' + ' ' + ' ' + '
' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
' + ' ' + ' ' + '   ' + '
' + ' ' + ' ' + '
' + ' ' + '
' + ' ' + '
' + ' ' + '
' + '
' + '
' + ' '+get_lang('Search the messages in these folders')+'' + '
' + '
' + ' ' + '
' + ' ' + '
' + '
' + ' ' + '
' + '
' + ' ' + ' '+get_lang('In all the folders')+'' + '
'; return form_sch; } // Pastas; searchE.prototype.mount_folders = function(){ expresso.connector.loadScript("jscode/TreeS"); if( Element("div_folders_search") == null){ var div_folders = document.createElement("DIV"); div_folders.id = "div_folders_search"; div_folders.style.width = "155px"; div_folders.style.height = "152px"; div_folders.style.borderStyle = "outset"; div_folders.style.borderColor = "black"; div_folders.style.borderWidth = "1px"; div_folders.style.background = "#F7F7F7"; div_folders.style.overflow = "auto"; div_folders.innerHTML = ""; var dest_div = Element("folders"); dest_div.appendChild(div_folders); } ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","",""); } // Form resultado searchE.prototype.mount_result = function(data,sort_type){ if (data == undefined) return; var cont = parseInt(0); //This func returns the comparison between criterias var date_comp = function(a,b){ return a.udate > b.udate;}; var date_comp_reverse = function(a,b){ return date_comp(b,a);}; var box_comp = function(a,b){ return a.boxname > b.boxname; } var box_comp_reverse = function(a,b){ return box_comp(b,a); } var who_comp = function(a,b){ return a.from > b.from; } var who_comp_reverse = function(a,b){ return who_comp(b,a); } var subject_comp = function(a,b){ return a.subject > b.subject; } var subject_comp_reverse = function(a,b){ return subject_comp(b,a); } var size_comp = function(a,b){ return a.size > b.size; } var size_comp_reverse = function(a,b){ return size_comp(b,a); } switch (sort_type) { case 'SORTDATE': data.sort(date_comp); break; case 'SORTDATE_REVERSE': data.sort(date_comp_reverse); break; case 'SORTBOX': data.sort(box_comp); break; case 'SORTBOX_REVERSE': data.sort(box_comp_reverse); break; case 'SORTSUBJECT': data.sort(subject_comp); break; case 'SORTSUBJECT_REVERSE': data.sort(subject_comp_reverse); break; case 'SORTWHO': data.sort(who_comp); break; case 'SORTWHO_REVERSE': data.sort(who_comp_reverse); break; case 'SORTSIZE': data.sort(size_comp); break; case 'SORTSIZE_REVERSE': data.sort(size_comp_reverse); break; default: var showMsg = 1; } if( (preferences.search_result_number != '65536') && (data.length > 0) && (data.length >= preferences.search_result_number) ){ data.length = preferences.search_result_number; write_msg(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number)); } else { write_msg(data.length + " "+ get_lang('results found')); } numBox++; var border_id = create_border(get_lang("Search Results"), "search_" + numBox); if (!border_id) { return; } currentTab = border_id; openTab.content_id[currentTab] = Element('content_id_search_' + numBox); openTab.type[currentTab] = 1; var table = document.createElement("TABLE"); table.id = "table_resultsearch_" + numBox; table.frame = "void"; table.rules = "rows"; table.cellPadding = "0"; table.cellSpacing = "0"; table.className = "table_box"; var tbody = document.createElement("TBODY"); tbody.id = "tbody_box_" + numBox; for( var i=0; i < data.length; i++){ var tr = document.createElement("TR"); tr.style.height = preferences.line_height; var aux = data[i]; var mailbox = aux.boxname; var uid_msg = aux.uid; var subject = aux.subject; tr.id = uid_msg+"_s"+global_search; // Keep the two lines together please tr.setAttribute('name',mailbox); tr.name = mailbox; if (aux.flag.match("U")) add_className(tr,'tr_msg_unread'); add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read'); var _onclick = function () { proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);}; for(var j=0 ; j < 10 ; j++) { var td = document.createElement("TD"); if (j == 0) { td.style.width = "1%"; var td1 = ''; } if (j == 1) { td.style.width = "2%"; if (aux.flag.match('T')) { attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1)); td1 = ""; } else td1 = ''; } if (j == 2) { td.style.width = "1%"; td.id = "td_message_answered_"+uid_msg; if (aux.flag.match('X')) td1 = ''; else if (aux.flag.match('A')) td1 = ''; else td1 = ''; } if (j == 3) { td.style.width = "1%"; td.id = "td_message_important_"+uid_msg; if (aux.flag.match("F")) { add_className(tr, 'flagged_msg'); td.style.background = "url(templates/"+template+"/images/important.gif) no-repeat center"; } else td1 = ''; } if (j == 4) { td.style.width = "1%"; td.id = "td_message_sent_"+uid_msg; td1 = ''; } if (j == 5) { td.style.width = "14%"; td.onclick = _onclick; var nm_box = aux.boxname.split(cyrus_delimiter); var td1 = nm_box.pop(); td.setAttribute("NoWrap","true"); td.style.overflow = "hidden"; td.style.color = "#42795b"; td.style.fontWeight = "bold"; var td1 = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1); if ((tmp = translatedFolders.get(td1))) { td1 = tmp; } if(proxy_mensagens.is_local_folder(td1)) { var td1 = this.aux_local_folder_display(td1); } } if( j == 6) { if (aux.from.length > 29) aux.from = aux.from.substr(0,29) + "..."; td.style.width = "20%"; td.onclick = _onclick; td.setAttribute("NoWrap","true"); td.style.overflow = "hidden"; var td1 = '
'+aux.from+"
"; } if( j == 7) { var subject_encode = url_encode(subject); if (! subject_encode) aux.subject = get_lang("no subject") + "..."; if (aux.subject.length > 70) aux.subject = aux.subject.substr(0,70) + "..."; td.style.width = "35%"; td.onclick = _onclick; td.setAttribute("NoWrap","true"); td.style.overflow = "hidden"; var td1 = aux.subject; } if( j == 8) { td.style.width = "15%"; td.align = "center"; td.onclick = _onclick; var _dat = new Date(aux.udate*1000); var td1 = _dat.getDate()+"/"+_dat.getMonth()+"/"+_dat.getFullYear(); } if( j == 9) { td.style.width = "10%"; td.align = "center"; td.onclick = _onclick; var td1 = borkb(aux.size); } if (j == 10) { if (aux.flag.match("U")) add_className(tr, 'tr_msg_unread'); if (aux.flag.match("F")) add_className(tr, 'flagged_msg'); var td1 = ''; } td.innerHTML = td1; tr.appendChild(td); } aux.splice(0,(aux.length)); _dragArea.makeDragged(tr, uid_msg, subject, true, mailbox); tbody.appendChild(tr); } global_search++; //Tabs from search must not have the same id on its tr's table.appendChild(tbody); var content_search = Element('content_id_search_' + numBox); var div_scroll_result = document.createElement("DIV"); div_scroll_result.id = "divScrollMain_"+numBox; div_scroll_result.style.overflow = "auto"; if(is_ie) Element("border_table").width = "99.5%"; // Put header var table_element = document.createElement("TABLE"); var tbody_element = document.createElement("TBODY"); table_element.setAttribute("id", "table_message_header_box"); table_element.className = "table_message_header_box"; tr_element = document.createElement("TR"); tr_element.className = "message_header"; td_element0 = document.createElement("TD"); td_element0.setAttribute("width", "1%"); chk_box_element = document.createElement("INPUT"); chk_box_element.id = "chkbox_sel_allmsg"; chk_box_element.setAttribute("type", "checkbox"); chk_box_element.className = "checkbox"; chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);}; chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')}; chk_box_element.onkeydown = function (e){ if (is_ie) { if ((window.event.keyCode) == 46) delete_msgs(current_folder,'selected','null'); } else { if ((e.keyCode) == 46) delete_msgs(current_folder,'selected','null'); } }; td_element0.appendChild(chk_box_element); td_element1 = document.createElement("TD"); td_element1.setAttribute("width", "20%"); td_element1.align = "left"; if (sort_type == 'SORTBOX') { td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);}; td_element1.innerHTML =""+get_lang("Folder")+""; } else { td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);}; if (sort_type == 'SORTBOX_REVERSE') td_element1.innerHTML =""+get_lang("Folder")+""; else td_element1.innerHTML = get_lang("Folder"); } td_element2 = document.createElement("TD"); td_element2.setAttribute("width", "20%"); td_element2.align = "left"; if (sort_type == 'SORTWHO') { td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);}; td_element2.innerHTML =""+get_lang("who")+""; } else { td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);}; if (sort_type == 'SORTWHO_REVERSE') td_element2.innerHTML =""+get_lang("who")+""; else td_element2.innerHTML = get_lang("who"); } td_element3 = document.createElement("TD"); td_element3.setAttribute("width", "35%"); td_element3.align = "left"; if (sort_type == 'SORTSUBJECT') { td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);}; td_element3.innerHTML =""+get_lang("subject")+""; } else { td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);}; if (sort_type == 'SORTSUBJECT_REVERSE') td_element3.innerHTML =""+get_lang("subject")+""; else td_element3.innerHTML = get_lang("subject"); } td_element4 = document.createElement("TD"); td_element4.setAttribute("width", "15%"); td_element4.align = "center"; if (sort_type == 'SORTDATE') { td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);}; td_element4.innerHTML =""+get_lang("Date")+""; } else { td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);}; if (sort_type == 'SORTDATE_REVERSE') td_element4.innerHTML =""+get_lang("Date")+""; else td_element4.innerHTML = get_lang("Date"); } td_element5 = document.createElement("TD"); td_element5.setAttribute("width", "10%"); td_element5.align = "center"; if (sort_type == 'SORTSIZE') { td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);}; td_element5.innerHTML =""+get_lang("size")+""; } else { td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);}; if (sort_type == 'SORTSIZE_REVERSE') td_element5.innerHTML =""+get_lang("size")+""; else td_element5.innerHTML = get_lang("Size"); } tr_element.appendChild(td_element0); tr_element.appendChild(td_element1); tr_element.appendChild(td_element2); tr_element.appendChild(td_element3); tr_element.appendChild(td_element4); tr_element.appendChild(td_element5); tbody_element.appendChild(tr_element); table_element.appendChild(tbody_element); content_search.appendChild(table_element); /*end of "put header"*/ if (!expresso_offline) { /* var span_options = document.createElement("SPAN"); if (span_options) span_options.innerHTML = '' + get_lang("Delete") + ' | ' + '' + get_lang("Move") + '';*/ div_scroll_result.appendChild(table); content_search.appendChild(div_scroll_result); /*if (span_options) content_search.appendChild(span_options);*/ } else { div_scroll_result.appendChild(table); content_search.appendChild(div_scroll_result); } resizeWindow(); } searchE.prototype.open_msg = function(mailbox, uid_msg, subject){ var handler_get_msg = function(data){ if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));} else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));} //set_msg_as_read(msgs_to_set[i], false); } proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg); /*var args = "expressoMail1_2.imap_functions.get_info_msg"; var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox; cExecute(args,handler_get_msg,params);*/ } // Adiciona caixas postais na busca; searchE.prototype.add_mailboxes = function(){ var sel = Element("sel_search_nm_box1"); if (!proxy_mensagens.is_local_folder(this.name_box_search)) { var name_box = this.name_box_search.split(cyrus_delimiter); if(this.name_box_search == "") return false; var name_box_def = ""; if(name_box.length != 1){ name_box_def = name_box[(name_box.length-1)]; }else{ name_box_def = get_lang("Inbox"); } } else { if(this.name_box_search=='local_root') return; if(this.name_box_search=='local_Inbox') name_box_def = get_lang("Inbox"); else if(this.name_box_search.indexOf("/")!="-1") { final_pos = this.name_box_search.lastIndexOf("/"); name_box_def = this.name_box_search.substr(final_pos+1); } else name_box_def = this.name_box_search.substr(6);//Retira o 'local_' } if( sel.length > 0){ for(var i=0; i < sel.options.length; i++){ if(sel.options[i].value == this.name_box_search){ alert(get_lang('This message is already selected!')); return false; } } } var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true); sel[sel.length] = opt; } // Remove as caixas postais na busca; searchE.prototype.del_mailboxes = function(){ var sel = Element("sel_search_nm_box1"); if(sel.length > 0){ for(var i=0; i < sel.options.length; i++){ if(sel.options[i].selected == true){ sel.options[i] = null; i--; } } } } // todas as caixas searchE.prototype.all_mailboxes = function(){ var value = Element("check_all_msg").checked; var cont = parseInt(0); if(value){ if(EsearchE.all_boxes.length > 0){ EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length)); } for(var i=0; i < folders.length; i++){ EsearchE.all_boxes[cont] = folders[i].folder_id; cont++; } }else{ EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length)); } } // Search; searchE.prototype.func_search = function(value){ var fields = "##"; // Verifica se os campos estão preenchidos; if(trim(Element("txt_ass").value) != ""){ fields += "SUBJECT " + "<=>" +url_encode(Element("txt_ass").value) + "##"; } if(trim(Element("txt_body").value) != ""){ fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##"; } if(trim(Element("txt_de").value) != ""){ fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##"; } if(trim(Element("txt_para").value) != ""){ fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##"; } if(trim(Element("txt_cc").value) != ""){ fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##"; } if (trim(Element("since_date").value) != ""){ if (validate_date(Element("since_date").value)) { fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##"; } else { alert(get_lang('Invalid date on field %1'), get_lang('Since Date')); return false; } } if (trim(Element("before_date").value) != ""){ if (validate_date(Element("before_date").value)) { fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##"; } else { alert(get_lang('Invalid date on field %1'), get_lang('Before Date')); return false; } } if(trim(Element("on_date").value) != ""){ if (validate_date(Element("on_date").value)) { fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##"; } else { alert(get_lang('Invalid date on field %1'), get_lang('On Date')); return false; } } if(trim(Element("flagged").options[Element("flagged").selectedIndex].value) != ""){ if (Element("flagged").options[Element("flagged").selectedIndex].value == "FLAGGED"){ fields += "FLAGGED##"; } else { fields += "UNFLAGGED##"; } } if(trim(Element("seen").options[Element("seen").selectedIndex].value) != ""){ if (Element("seen").options[Element("seen").selectedIndex].value == "SEEN"){ fields += "SEEN##"; } else { fields += "UNSEEN##"; } } if(trim(Element("answered").options[Element("answered").selectedIndex].value) != ""){ if (Element("answered").options[Element("answered").selectedIndex].value == "ANSWERED"){ fields += "ANSWERED##"; } else { fields += "UNANSWERED##"; } } if(trim(Element("recent").options[Element("recent").selectedIndex].value) != ""){ if (Element("answered").options[Element("answered").selectedIndex].value == "RECENT"){ fields += "RECENT##"; } else { fields += "OLD##"; } } if(value) { fields = "##ALL " + "<=>" +url_encode(value) + "##"; } if(fields == "##"){ alert(get_lang("Define some search parameters!")); return false; } var local_folders = new Array(); var temp; if(Element("check_all_msg").checked){ this.all_mailboxes(); var nm_box = new Array; for(var i=0; i < EsearchE.all_boxes.length; i++){ nm_box[i] = EsearchE.all_boxes[i] + fields; } if (preferences.use_local_messages == 1) { temp = expresso_local_messages.list_local_folders(); for (var x in temp) { local_folders.push(temp[x][0]); } } }else{ var nm_box = new Array; var sel_combo = Element("sel_search_nm_box1"); if( sel_combo.options.length <= 0){ alert(get_lang("Define the boxes to search!")); return false; } for(var i=0; i < sel_combo.options.length; i++){ sel_combo.options[i].selected = true; } for(var i=0; i < sel_combo.options.length; i++){ if(sel_combo.options[i].selected == true){ if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value)) nm_box[nm_box.length] = sel_combo.options[i].value + fields; else local_folders.push(sel_combo.options[i].value.substr(6)); } } } var handler = function(data){ var tmp; if (local_folders.length > 0) { tmp = expresso_local_messages.search(local_folders, fields); if (tmp!=false) { var tmp2 = tmp.substr(2, data.length - 4); } } // if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));} // if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number)) // { // EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp); // } // else if (data == 'many results' || countTmp.length >= preferences.search_result_number) // { // alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number)); // } if ((data == "none") || (data.length==0)){ alert(get_lang("None result was found.")); } else { EsearchE.mount_result(data); } } var args = "expressoMail1_2.imap_functions.search_msg"; var params = "&condition=" + url_encode(nm_box); if(expresso_offline) handler('none'); else cExecute(args+params,handler); } // clean; searchE.prototype.func_clean = function(){ // Limpa os campos; for(var i=0; i < this.txtfields.length; i++){ if(Element(this.txtfields[i]) != null){Element(this.txtfields[i]).value = "";} } for(i = 0; i < this.selectFields.length; i++) { if (Element(this.selectFields[i])) { Element(this.selectFields[i]).selectedIndex = 0; } } if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;} EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length)); EsearchE.del_mailboxes(); } // close searchE.prototype.func_close = function(type){ var _this = this; _this.name_box_search = ""; EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length)); _this.type = type; _this.searchW['window_search'].close(); } // Monta a janela em tela; searchE.prototype.showWindow = function(div){ if(!this.searchW[div.id]) { div.style.width = "804px"; div.style.height = "440px"; div.style.visibility = "hidden"; div.style.position = "absolute"; div.style.zIndex = "10003"; var title = ":: "+ get_lang("Search")+" ::"; var wHeight = div.offsetHeight + "px"; var wWidth = div.offsetWidth + "px"; win = new dJSWin({ id: 'ccList'+div.id, content_id: div.id, width: wWidth, height: wHeight, title_color: '#3978d6', bg_color: '#eee', title: title, title_text_color: 'white', button_y_img: '../phpgwapi/images/win_min.gif', button_x_img: '../phpgwapi/images/winclose.gif', border: true }); this.searchW[div.id] = win; win.draw(); }else{ var _this = this; win = this.searchW[div.id]; if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();} win.draw(); } win.open(); } searchE.prototype.aux_local_folder_display = function(folder) { if(!expresso_offline) return "(Local) " + lang_folder(folder.substr(6)); else return lang_folder(folder.substr(6)); } // Cria o objeto var EsearchE; EsearchE = new searchE();