/**************************************************************************\
Início
\**************************************************************************/
function searchE(){
this.searchW = new Array;
this.name_box_search = "";
this.all_boxes = new Array;
this.type = "";
this.fields = new Array("_ass","_de","_body","_para","_cc","_cco");
}
//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 = "635px";
div_form_search.style.height = "200px";
div_form_search.style.borderStyle = "outset";
div_form_search.style.borderColor = "black";
div_form_search.style.borderWidth = "1px";
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);
}
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.left = "10px";
div_button_search.style.top = "223px";
div_button_search.style.width = "600px";
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 = "";
return form_sch;
}
// Pastas;
searchE.prototype.mount_folders = function(){
connector.loadScript("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","","","","");
}
//This func returns the most recent date
function date_comp(a,b)
{
var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
data1 = data1[0].substr(0, data1[0].indexOf('--'))
with ( data1 )
data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
data2 = data2[0].substr(0, data2[0].indexOf('--'))
with ( data2 )
data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
return data2 - data1;
}
function box_comp(a,b)
{
var compare = [];
compare[0] = a.substr(0, a.indexOf('--'));
compare[0] = compare[0].toLowerCase();
var temp=compare[0];
compare[1] = b.substr(0, b.indexOf('--'))
compare[1] = compare[1].toLowerCase();
compare.sort();
if (temp != compare[0])
return +1;
else
return -1;
}
function who_comp(a,b)
{
var compare = [];
compare[0] = a.substr(a.indexOf('--')+2);
compare[0] = compare[0].toLowerCase();
var temp=compare[0];
compare[1] = b.substr(b.indexOf('--')+2);
compare[1] = compare[1].toLowerCase();
compare.sort();
if (temp != compare[0])
return +1;
else
return -1;
}
function subject_comp(a,b)
{
var compare = [];
compare[0] = a.substr(a.indexOf('--')+2);
compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
compare[0] = compare[0].toLowerCase();
var temp=compare[0];
compare[1] = b.substr(b.indexOf('--')+2);
compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
compare[1] = compare[1].toLowerCase();
compare.sort();
if (temp != compare[0])
return +1;
else
return -1;
}
function size_comp(a,b)
{
var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
data1 = data1[0].substr(data1[0].indexOf('--')+2)
data1 = data1.substr(0,data1.indexOf('--'))
var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
if (data1.match("k"))
size_a = size_a * 1024;
else
if (data1.match("m"))
size_a = size_a * 1048576;
var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
data2 = data2[0].substr(data2[0].indexOf('--')+2)
data2 = data2.substr(0,data2.indexOf('--'))
var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
if (data2.match("k"))
size_b = size_b * 1024;
else
if (data2.match("m"))
size_b = size_b * 1048576;
return size_b - size_a;
}
// Form resultado;
searchE.prototype.mount_result = function(data,sort_type){
var nw_array = new Array;
var var_tmp = data.substr(2, data.length - 4);
var_tmp = var_tmp.split("####");
var cont = parseInt(0);
switch (sort_type)
{
case 'SORTDATE':
var_tmp.sort(date_comp);
break;
case 'SORTBOX':
var_tmp.sort(box_comp);
break;
case 'SORTSUBJECT':
var_tmp.sort(subject_comp);
break;
case 'SORTWHO':
var_tmp.sort(who_comp);
break;
case 'SORTSIZE':
var_tmp.sort(size_comp);
break;
default:
var showMsg = 1;
}
for(var i=0; i < var_tmp.length; i++){
if(var_tmp[i] != "")
{
nw_array[cont] = var_tmp[i];
cont++;
}
}
if(nw_array.length > 0 && showMsg)
write_msg(nw_array.length + " "+ get_lang('results found'));
numBox++;
var border_id = create_border(get_lang("Search Results"), "search_" + numBox);
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_resultsearch_" + numBox;
for( var i=0; i < nw_array.length; i++){
var tr = document.createElement("TR");
tr.style.height = preferences.line_height;
if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
{
var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
aux1 = aux1[0].split("--");
nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
var aux = [];
aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
aux = aux.concat(aux1);
}
else
{
var aux = nw_array[i].split("--");
}
var mailbox = aux[0];
var uid_msg = aux[6];
var subject = aux[2];
tr.id = uid_msg;
tr.name = mailbox;
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%";
td1 = '';
}
if (j == 2)
{
td.style.width = "1%";
td.id = "td_message_answered_"+uid_msg;
td1 = '';
}
if (j == 3)
{
td.style.width = "1%";
td.id = "td_message_important_"+uid_msg;
td1 = '';
}
if (j == 4)
{
td.style.width = "1%";
td.id = "td_message_sent_"+uid_msg;
td1 = '';
}
if (j == 5)
{
td.style.width = "14%";
var nm_box = aux[0].split(cyrus_delimiter);
var td1 = nm_box.pop();
td.setAttribute("NoWrap","true");
td.style.overflow = "hidden";
td.style.color = "#42795b";
td.style.fontWeight = "bold";
if(td1 == "INBOX"){
var td1 = get_lang("Inbox");
}
if(proxy_mensagens.is_local_folder(td1)) {
var td1 = this.aux_local_folder_display(td1);
}
}
if( j == 6)
{
var subject_encode = url_encode(aux[1]);
td.style.width = "20%";
var td1 = ''+aux[1]+"
";
}
if( j == 7)
{
var subject_encode = url_encode(subject);
if (! subject_encode)
aux[2] = get_lang("no subject") + "...";
td.style.width = "35%";
var td1 = '';
}
if( j == 8)
{
td.style.width = "15%";
td.align = "center";
var td1 = aux[3];
}
if( j == 9)
{
td.style.width = "10%";
td.align = "center";
var td1 = aux[4];
}
if (j == 10)
{
if (aux[5].match("U"))
tr.className = 'tr_msg_unread';
else
tr.className = 'tr_msg_read';
if (aux[5].match("F"))
tr.className = 'flagged_msg';
var td1 = '';
}
td.innerHTML = td1;
tr.appendChild(td);
}
aux.splice(0,(aux.length));
_dragArea.makeDragged(tr, uid_msg, subject_encode, true, mailbox);
tbody.appendChild(tr);
}
table.appendChild(tbody);
var content_search = Element('content_id_search_' + numBox);
// BEGIN MAKE THE SCROLL HEIGHT
var defaultWidth = document.body.offsetWidth - 31;
var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
if(!menuHidden)
defaultWidth -= Element("folderscol").offsetWidth;
var bar = Element("toolbar");
var offset = 0;
if(bar.style.visibility != 'hidden')
offset = bar.offsetHeight ? bar.offsetHeight : bar.clientHeight;
var div_scroll_result = document.createElement("DIV");
div_scroll_result.id = "divScrollMain_"+numBox;
div_scroll_result.style.background = 'WHITE';
div_scroll_result.style.height = document.body.clientHeight - offset - 120;
content_search.style.height = document.body.clientHeight - offset - 80;
div_scroll_result.style.overflow = "auto";
div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
// END MAKE THE SCROLL HEIGHT
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 = "chk_box_select_all_messages";
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(get_current_folder(),'selected','null');
}
else
{
if ((e.keyCode) == 46)
delete_msgs(get_current_folder(),'selected','null');
}
};
td_element0.appendChild(chk_box_element);
td_element1 = document.createElement("TD");
td_element1.setAttribute("width", "20%");
td_element1.align = "left";
td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
td_element1.innerHTML = (sort_type == 'SORTBOX')?""+get_lang("folder")+"":get_lang("folder");
td_element2 = document.createElement("TD");
td_element2.setAttribute("width", "20%");
td_element2.align = "left";
td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
td_element2.innerHTML = (sort_type == 'SORTWHO')?""+get_lang("Who")+"":get_lang("Who");
td_element3 = document.createElement("TD");
td_element3.setAttribute("width", "35%");
td_element3.align = "left";
td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
td_element3.innerHTML = (sort_type == 'SORTSUBJECT')?""+get_lang("Subject")+"":get_lang("Subject");
td_element4 = document.createElement("TD");
td_element4.setAttribute("width", "15%");
td_element4.align = "center";
td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
td_element4.innerHTML = (sort_type == 'SORTDATE')?""+get_lang("Date")+"":get_lang("Date");
td_element5 = document.createElement("TD");
td_element5.setAttribute("width", "10%");
td_element5.align = "center";
td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
td_element5.innerHTML = (sort_type == 'SORTSIZE')?""+get_lang("Size")+"":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"*/
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);
}
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 = "$this.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
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(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;
var countTmp= new Array();
if (local_folders.length > 0) {
tmp = expresso_local_messages.search(local_folders, fields);
if (tmp!=false) {
var tmp2 = tmp.substr(2, data.length - 4);
countTmp = tmp.split('####');
}
}
if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
else if(countTmp.length > 50){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
else if(data == "many results"){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
else{EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);}
}
var args = "$this.imap_functions.search_msg";
var params = "condition=" + nm_box;
cExecute(args,handler,params);
}
// clean;
searchE.prototype.func_clean = function(){
// Limpa os campos;
for(var i=0; i < this.fields.length; i++){
if(Element("txt" + this.fields[i]) != null){Element("txt" + this.fields[i]).value = "";}
}
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 = "660px";
div.style.height = "255px";
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) {
return "(Local) " + lang_folder(folder.substr(6));
}
// Cria o objeto
var EsearchE;
EsearchE = new searchE();