/**************************************************************************\
Início
\**************************************************************************/
function searchE()
{
this.totalPages = 1;
this.numPages = 5;
this.lastPage = 0;
this.searchW = [];
this.condition = "";
this.sort_type = "";
//this.page = 0;
this.name_box_search = "";
this.all_boxes = [];
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.borderStyle = "outset";
div_form_search.style.borderColor = "black";
div_form_search.style.borderWidth = "1px";
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);
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'
});
}
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 = ''
+ '';
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","","","","");
}
function openpage(data)
{
var _data = [3];
var _gears = [];
var local_folders = [];
// Gears - local
if ( preferences.use_local_messages == 1 )
{
temp = expresso_local_messages.list_local_folders();
for (var x in temp)
{
local_folders.push(temp[x][0]);
}
}
if ( local_folders.length > 0 )
_gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
_data['data'] = data['data'];
_data['num_msgs'] = data['num_msgs'];
_data['gears_num_msgs'] = _gears.length;
delete_border( data['currentTab'], false);
EsearchE.mount_result(_data);
}
searchE.prototype.show_paging = function(size)
{
var span_pg = Element("span_paging"+currentTab);
if( span_pg == null )
{
span_pg = document.createElement('span');
span_pg.id = "span_paging"+currentTab;
}
else
span_pg.innerHTML = "";
if(size > parseInt(preferences.max_email_per_page)) {
this.totalPages = parseInt(size/preferences.max_email_per_page);
if((size/preferences.max_email_per_page) > this.totalPages)
this.totalPages++;
}
if(this.page != 0) {
_link = document.createElement("A");
_link.href = 'javascript:EsearchE.page=0;';
_link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page=0¤t_tab='+currentTab+'");';
}
else {
_link = document.createElement("SPAN");
}
span_pg.appendChild(_link);
_link.innerHTML = "<<";
_link.title = get_lang("First");
span_pg.innerHTML += " ";
if(this.page == this.lastPage + (this.numPages))
{
this.lastPage = this.page - 1;
}
else if((this.lastPage != 0 && this.lastPage == this.page) || this.page == (this.totalPages-1))
{
this.lastPage = this.page - (this.numPages - 1);
}
else if(this.page == 0)
{
this.lastPage = 0;
}
if(this.lastPage < 0)
this.lastPage = 0;
else if(this.lastPage > 0 && (this.lastPage > (this.totalPages -(this.numPages - 1))))
this.lastPage = this.totalPages -(this.numPages);
var hasMarked = false;
for(i = this.lastPage; i <= this.totalPages; i++)
{
if( ( i * preferences.max_email_per_page ) > size)
{
break;
}
if( this.page == i || (i == this.totalPages && !hasMarked) )
{
var _link = document.createElement('span');
_link.setAttribute("style", "font-weight:bold; color:red")
_link.innerHTML = ( this.page + 1 ) + " ";
}
else
{
var _page = i;
var _link = document.createElement('A');
_link.innerHTML = ( _page + 1 ) + " ";
_link.href = 'javascript:EsearchE.page='+i+';';
_link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+_page+'¤t_tab='+currentTab+'");';
}
_link.innerHTML = " ... ";
if(i == (this.lastPage + this.numPages))
{
span_pg.appendChild( _link );
break;
}
else if(this.lastPage == 0 || i != this.lastPage)
{
_link.innerHTML = " "+( i + 1 )+" ";
}
//span_pg.innerHTML += " ";
span_pg.appendChild( _link );
}
if(this.page != (this.totalPages - 1)) {
_link = document.createElement("A");
_link.href = 'javascript:EsearchE.page='+(this.totalPages-1)+';';
_link.href += 'cExecute("$this.imap_functions.search_msg",openpage,"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+(this.totalPages-1)+'¤t_tab='+currentTab+'");';
}
else {
_link = document.createElement("SPAN");
}
span_pg.innerHTML += " ";
span_pg.appendChild(_link);
_link.title = get_lang("Last");
_link.innerHTML += ">>";
Element("div_menu_c3").appendChild(span_pg);
}
searchE.prototype.searchFor = function( borderID, sortType )
{
var border_id = borderID;
var sort_type = sortType;
var is_local = border_id.match('.*_local_.*');
var args = "$this.imap_functions.search_msg";
var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type="+sort_type;
var handler = function( data )
{
var allMsg = [3];
var gears = [];
var local_folders = [];
if ( preferences.use_local_messages == 1 && is_local)
{
temp = expresso_local_messages.list_local_folders();
for (var x in temp)
{
local_folders.push( temp[x][0] );
}
if ( local_folders.length > 0 ){
expresso_local_messages.setSortType(sortType);
gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
}
}
if( data['num_msgs'])
{
allMsg['data'] = data['data'];
allMsg['num_msgs'] = data['num_msgs'];
}
if (gears.length > 0)
{
allMsg['data_gears'] = gears;
}
delete_border( border_id, false );
EsearchE.mount_result( allMsg , sort_type );
};
if (is_local)
{
eval("handler('none')");
}
else
{
cExecute(args,handler,params);
}
}
searchE.prototype.viewLocalMessage = function()
{
var data = [2];
var gears = [];
var local_folders = [];
// Gears - local
if ( preferences.use_local_messages == 1 )
{
temp = expresso_local_messages.list_local_folders();
for (var x in temp)
{
local_folders.push( temp[x][0] );
}
if ( local_folders.length > 0 )
gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
data['data_gears'] = gears;
data['num_msgs'] = gears.length;
write_msg( data['num_msgs'] + " " + get_lang("results found") );
EsearchE.mount_result( data, 'SORTDATE' );
}
}
searchE.prototype.make_tr_message = function(aux,border_id,i) {
var tr = document.createElement("TR");
if(typeof(preferences.line_height) != 'undefined')
tr.style.height = preferences.line_height;
var mailbox = aux.boxname;
var uid_msg = aux.uid;
var subject = aux.subject;
tr.id = uid_msg+"_s"+numBox;
// 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.setAttribute("width", colSizes[1][0]);
var chk_onclick;
if (is_ie)
chk_onclick = "changeBgColor(window.event,"+uid_msg+");";
else
chk_onclick = "changeBgColor(event,"+uid_msg+");";
var td1 = '';
}
if (j == 1)
{
td.setAttribute("width", colSizes[1][1]);
if (aux.flag.match('T'))
{
attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
td1 = "
";
}
else
td1 = '';
}
if (j == 2)
{
td.setAttribute("width", colSizes[1][2]);
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.setAttribute("width", colSizes[1][3]);
td.id = "td_message_important_"+uid_msg;
if (aux.flag.match("F"))
{
add_className(tr, 'flagged_msg');
td1 = "
";
}
else
td1 = '';
}
if (j == 4)
{
td.setAttribute("width", colSizes[1][4]);
td.id = "td_message_sent_"+uid_msg;
td1 = '';
}
if ( j == 5 )
{
td.setAttribute("width", colSizes[1][5]);
td.className = "td_resizable";
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);
td1 = translateFolder(td1);
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.setAttribute("width", colSizes[1][6]);
td.className = "td_resizable";
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.setAttribute("width", colSizes[1][7]);
td.className = "td_resizable";
td.onclick = _onclick;
td.setAttribute("NoWrap","true");
td.style.overflow = "hidden";
var td1 = aux.subject;
}
if( j == 8 )
{
td.setAttribute("width", colSizes[1][8]);
td.className = "td_resizable";
td.align = "center";
td.onclick = _onclick;
if( validate_date( aux.udate ) )
{
var td1 = aux.udate;
}
else
{
var dt = new Date( aux.udate * 1000 );
var td1 = dt.getDate() + "/";
if( !( dt.getMonth() + 1 ).toString().match(/\d{2}/) )
td1 += "0"+( dt.getMonth() + 1 ) + "/";
else
td1 += ( dt.getMonth() + 1 ) + "/";
td1 += dt.getFullYear();
}
}
if( j == 9 )
{
td.setAttribute("width", colSizes[1][9]);
td.className = "td_resizable";
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 = '';
}
if (j<10) {
td.innerHTML = td1;
tr.appendChild(td);
}
}
_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
return tr;
}
// Form resultado
searchE.prototype.mount_result = function( Data, sort_type, keep_border )
{
var data = ( Data['data'] ) ? Data['data'] : Data['data_gears'];
if ( data == undefined )
return;
var cont = parseInt(0);
if ( typeof(sort_type) != 'undefined')
this.sort_type = sort_type;
else
sort_type = this.sort_type;
if ( keep_border ) {
var border_id = currentTab;
}
else {
numBox++;
if( Data['data'] )
var border_id = create_border(get_lang("Server Results"), "search_" + numBox);
if( Data['data_gears'])
var border_id = create_border(get_lang("Local Results"), "search_local_msg" + numBox);
}
if (!border_id)
return;
currentTab = border_id;
openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
openTab.type[currentTab] = 1;
openTab.condition[currentTab] = this.condition;
if ( keep_border ) {
var content_search = Element('content_id_' + border_id);
var div_scroll_result = Element("divScrollMain_"+numBox);
content_search.removeChild(div_scroll_result);
}
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 = EsearchE.make_tr_message(data[i],border_id,i);
tbody.appendChild(tr);
}
//global_search++; //Tabs from search must not have the same id on its tr's // use numBox instead of this!
table.appendChild(tbody);
var colgr_element = buildColGroup(1);
colgr_element.setAttribute("id","colgroup_main_"+numBox);
table.appendChild(colgr_element);
var content_search = Element('content_id_' + border_id);
var div_scroll_result = document.createElement("DIV");
div_scroll_result.id = "divScrollMain_"+numBox;
div_scroll_result.style.overflowY = "scroll";
div_scroll_result.style.overflowX = "hidden";
div_scroll_result.style.width ="100%";
if (is_mozilla){
div_scroll_result.style.overflow = "-moz-scrollbars-vertical";
div_scroll_result.style.width ="100%";
}
if(is_ie)
Element("border_table").width = "99.5%";
// Put header
var table_element = document.createElement("TABLE");
var tbody_element = document.createElement("TBODY");
if (is_ie)
{
table_element.attachEvent("onmousemove",changeCursorState);
table_element.attachEvent("onmousedown",startColResize);
}
else {
table_element.addEventListener("mousemove",changeCursorState,false);
table_element.addEventListener("mousedown",startColResize,false);
}
table_element.setAttribute("id", "table_message_header_box_"+numBox);
table_element.className = "table_message_header_box";
if (!is_ie)
table_element.style.width = "98.8%";
table_element.emptyBody = false;
tr_element = document.createElement("TR");
tr_element.className = "message_header";
td_element0 = createTDElement(1,0);
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(current_folder,'selected','null');
}
else
{
if ((e.keyCode) == 46)
delete_msgs(current_folder,'selected','null');
}
};
td_element0.appendChild(chk_box_element);
td_element01 = createTDElement(1,1);
td_element02 = createTDElement(1,2);
td_element03 = createTDElement(1,3);
td_element04 = createTDElement(1,4);
td_element1 = createTDElement(1,5,"th_resizable","left");
var arrow_ascendant = function(Text)
{
return "" + Text + "
";
}
// Ordernar Pasta
if ( sort_type == 'SORTBOX')
{
if( Data['data'] )
{
td_element1.onclick = function(){ EsearchE.searchFor(border_id, 'SORTBOX_REVERSE'); };
td_element1.innerHTML = ""+get_lang("Folder")+"
";
}
else
{
td_element1.onclick = function(){ EsearchE.searchFor(border_id, 'SORTBOX_REVERSE'); };
td_element1.innerHTML = ""+get_lang("Folder")+"
";
}
}
else
{
if( Data['data'] )
{
td_element1.onclick = function(){ EsearchE.searchFor(border_id, 'SORTBOX'); };
}
else
{
td_element1.onclick = function(){ EsearchE.searchFor(border_id, 'SORTBOX'); };
}
td_element1.innerHTML = ( sort_type == 'SORTBOX_REVERSE' ) ? arrow_ascendant(get_lang("Folder")) : get_lang("Folder");
}
// Ordernar Quem
td_element2 = createTDElement(1,6,"th_resizable","left");
if (sort_type == 'SORTWHO')
{
if(Data['data'])
{
td_element2.onclick = function(){ EsearchE.searchFor(border_id, 'SORTWHO_REVERSE'); };
td_element2.innerHTML = ""+get_lang("who")+"
";
}
else
{
td_element2.onclick = function(){ EsearchE.searchFor(border_id, 'SORTWHO_REVERSE'); };
td_element2.innerHTML = ""+get_lang("who")+"
";
}
}
else
{
if( Data['data'] )
{
td_element2.onclick = function(){ EsearchE.searchFor(border_id, 'SORTWHO'); };
}
else
{
td_element2.onclick = function(){ EsearchE.searchFor(border_id, 'SORTWHO'); };
}
td_element2.innerHTML = ( sort_type == 'SORTWHO_REVERSE' ) ? arrow_ascendant(get_lang("who")) : get_lang("who");
}
// Ordernar Subject
td_element3 = createTDElement(1,7,"th_resizable","left");
if (sort_type == 'SORTSUBJECT')
{
if( Data['data'])
{
td_element3.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT_REVERSE'); };
td_element3.innerHTML = ""+get_lang("subject")+"
";
}
else
{
td_element3.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT_REVERSE'); };
td_element3.innerHTML = ""+get_lang("subject")+"
";
}
}
else
{
if( Data['data'] )
{
td_element3.onclick = function(){ EsearchE.searchFor( border_id, 'SORTSUBJECT'); };
}
else
{
td_element3.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT'); };
}
td_element3.innerHTML = ( sort_type == 'SORTSUBJECT_REVERSE' ) ? arrow_ascendant(get_lang("subject")) : get_lang("subject");
}
// Ordernar Data
td_element4 = createTDElement(1,8,"th_resizable","center");
if ( sort_type == 'SORTDATE' )
{
if( Data['data'] )
{
td_element4.onclick = function(){ EsearchE.searchFor(border_id, 'SORTDATE_REVERSE'); };
td_element4.innerHTML = ""+get_lang("Date")+"
";
}
else
{
td_element4.onclick = function(){ EsearchE.searchFor(border_id, 'SORTDATE_REVERSE'); };
td_element4.innerHTML = ""+get_lang("Date")+"
";
}
}
else
{
if( Data['data'] )
{
td_element4.onclick = function(){ EsearchE.searchFor(border_id, 'SORTDATE'); };
}
else
{
td_element4.onclick = function(){ EsearchE.searchFor(border_id, 'SORTDATE'); };
}
td_element4.innerHTML = ( sort_type == 'SORTDATE_REVERSE' ) ? arrow_ascendant(get_lang("Date")) : get_lang("Date");
}
// Ordernar Tamanho
td_element5 = createTDElement(1,9,"th_resizable","center");
if ( sort_type == 'SORTSIZE' )
{
if( Data['data'] )
{
td_element5.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSIZE_REVERSE'); };
td_element5.innerHTML = ""+get_lang("size")+"
";
}
else
{
td_element5.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSIZE_REVERSE'); };
td_element5.innerHTML = ""+get_lang("size")+"
";
}
}
else
{
if( Data['data'] )
{
td_element5.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSIZE'); };
}
else
{
td_element5.onclick = function(){ EsearchE.searchFor(border_id, 'SORTSIZE'); };
}
td_element5.innerHTML = ( sort_type == 'SORTSIZE_REVERSE' ) ? arrow_ascendant(get_lang("size")) : get_lang("size");
}
tr_element.appendChild(td_element0);
tr_element.appendChild(td_element01);
tr_element.appendChild(td_element02);
tr_element.appendChild(td_element03);
tr_element.appendChild(td_element04);
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);
var colgr_element = buildColGroup(1);
colgr_element.setAttribute("id","colgroup_head_"+numBox);
table_element.appendChild(colgr_element);
if( parseInt( Data['gears_num_msgs'] ) > 0 )
{
var _div_gears = document.createElement("div");
_div_gears.onclick = function(){ EsearchE.viewLocalMessage(); };
_div_gears.className = 'local-messages-search-warning';
_div_gears.innerHTML = get_lang("The search has% 1 messages stored locally. Want to see them ? Click here.", Data['gears_num_msgs']);
content_search.appendChild(_div_gears);
}
var _divScroll = document.getElementById("divScrollHead_"+numBox);
if(!_divScroll){
_divScroll = document.createElement("DIV");
_divScroll.id = "divScrollHead_"+numBox;
_divScroll.style.overflowY = "hidden";
_divScroll.style.overflowX = "hidden";
_divScroll.style.width ="100%";
if (is_mozilla){
_divScroll.style.width ="99.3%";
}
_divScroll.appendChild(table_element);
content_search.appendChild(_divScroll);
}
/*end of "put header"*/
if ( !expresso_offline )
{
div_scroll_result.appendChild(table);
content_search.appendChild(div_scroll_result);
}
else
{
div_scroll_result.appendChild(table);
content_search.appendChild(div_scroll_result);
}
resizeWindow();
if(typeof(Data.data_gears)=="undefined")
EsearchE.show_paging( Data['num_msgs'] );
}
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") );
}
proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
}
// 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;
}
}
}
name_box_def = translateFolder(name_box_def);
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;
}
}
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 allMsg = [3];
var count = ( data['num_msgs'] ) ? data['num_msgs'] : "0";
var tmp = [];
// Gears - local
if ( local_folders.length > 0 ){
expresso_local_messages.setSortType('SORTDATE');
tmp = expresso_local_messages.search( local_folders, fields );
}
if( data['num_msgs'] )
{
allMsg['data'] = data['data'];
allMsg['num_msgs'] = data['num_msgs'];
}
if( tmp.length > 0 )
{
allMsg['gears_num_msgs'] = tmp.length ;
}
if( ( data['num_msgs'] ) == 0 )
{
alert( get_lang("None result was found.") );
}
else
{
if( (tmp.length > 0) && (!data['num_msgs']) )
{
EsearchE.viewLocalMessage();
}
else
{
write_msg( count + " " + get_lang("results found") );
EsearchE.mount_result( allMsg, 'SORTDATE' );
}
}
}
this.condition = nm_box;
this.page = 0;
var args = "$this.imap_functions.search_msg";
var params = "condition=" + nm_box+ "&page=0"+ "&sort_type=SORTDATE";
if( expresso_offline )
handler('none');
else
cExecute( args, handler, params);
}
// 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 = "10";
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));
}
searchE.prototype.refresh = function(alert_new_msg){
var handler_refresh = function(data){
var allMsg = [3];
var count = ( data['num_msgs'] ) ? data['num_msgs'] : "0";
if( data['num_msgs'] )
{
allMsg['data'] = data['data'];
allMsg['num_msgs'] = data['num_msgs'];
}
if( ( data['num_msgs'] ) == 0 )
{
alert( get_lang("None result was found.") );
}
else
{
if( data['num_msgs'] )
{
write_msg( count + " " + get_lang("results found") );
EsearchE.mount_result( allMsg, 'SORTDATE', true );
}
}
}
this.condition = openTab.condition[currentTab];
var sort_type = (this.sort_type ? this.sort_type : 'SORTDATE');
if( expresso_offline )
handler('none');
else
cExecute( "$this.imap_functions.search_msg", handler_refresh, "condition="+openTab.condition[currentTab]+"&page="+EsearchE.page+"&sort_type="+sort_type);
}
// Cria o objeto
var EsearchE;
EsearchE = new searchE();