function emQuickCatalogSearch () { this.arrayWin = new Array(); this.el; this.cc_contacts = new Array(); this.cc_groups = new Array(); } emQuickCatalogSearch.prototype.showList = function(data, begin, end){ id = '1'; _this = this; var el = document.createElement("DIV"); el.style.visibility = "hidden"; el.style.position = "absolute"; el.style.left = "0px"; el.style.top = "0px"; el.style.width = "0px"; el.style.height = "0px"; el.id = 'window_QuickCatalogSearch'; document.body.appendChild(el); el.innerHTML = ""; if (document.getElementById('select_QuickCatalogSearch') == null){ var title_innerHTML = get_lang('Select a name') + ':'; if (data.quickSearch_only_in_userSector) title_innerHTML += " ("+get_lang('Showing only the results found in your organization')+".)" var title = document.createElement("SPAM"); title.id = 'window_QuickCatalogSearch_title'; title.innerHTML = "  "+title_innerHTML+"
  "; el.appendChild(title); var cmb = document.createElement("SELECT"); cmb.id = "select_QuickCatalogSearch"; cmb.style.width = "685px"; cmb.size = "12"; cmb.onkeypress = function (e) { if (is_ie) { if ((window.event.keyCode) == 13) { QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); } else if ((window.event.keyCode) == 27) { QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); } } else { if ((e.keyCode) == 13) { QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); } else if ((e.keyCode) == 27) { QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); } } }; el.appendChild(cmb); var space = document.createElement('SPAN'); space.innerHTML = "
  "; el.appendChild(space); var butt = document.createElement('BUTTON'); var buttext = document.createTextNode('OK'); butt.id = "QuickCatalogSearch_button_ok"; butt.appendChild(buttext); butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);}; el.appendChild(butt); var space = document.createElement('SPAN'); space.innerHTML = "  "; el.appendChild(space); var butt = document.createElement('BUTTON'); butt.id = "QuickCatalogSearch_button_close"; var buttext = document.createTextNode(get_lang('Close')); butt.appendChild(buttext); butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);}; el.appendChild(butt); } else{ var title_innerHTML = get_lang('Select a name') + ':'; if (data.quickSearch_only_in_userSector) title_innerHTML += " ("+get_lang('Showing only the results found in your organization')+".)" var title = Element('window_QuickCatalogSearch_title'); title.innerHTML = "  "+title_innerHTML+"
  "; var cmb = document.getElementById('select_QuickCatalogSearch'); cmb.onkeypress = function (e) { if (is_ie) { if ((window.event.keyCode) == 13) { QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); } else if ((window.event.keyCode) == 27) { QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); } } else { if ((e.keyCode) == 13) { QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end); } else if ((e.keyCode) == 27) { QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID); } } }; for (i=0; i'; cmb.options.add(Op); } cmb.options[0].selected = true; _this.showWindow(el); } emQuickCatalogSearch.prototype.showWindow = function (div) { if(! div) { alert(get_lang('The list has no participant.')); return; } if(! this.arrayWin[div.id]) { div.style.width = "700px"; div.style.height = "230px"; var title = get_lang('The results were found in the Global Catalog')+':'; var wHeight = div.offsetHeight + "px"; var wWidth = div.offsetWidth + "px"; div.style.width = div.offsetWidth - 5; win = new dJSWin({ id: 'QuickCatalogSearch_'+div.id, content_id: div.id, width: wWidth, height: wHeight, title_color: '#3978d6', bg_color: '#eee', title: title, title_text_color: 'white', button_x_img: '../phpgwapi/images/winclose.gif', border: true }); this.arrayWin[div.id] = win; win.draw(); } else { win = this.arrayWin[div.id]; } //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = ""; win.open(); document.getElementById('select_QuickCatalogSearch').focus(); } emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){ cm = document.getElementById('select_QuickCatalogSearch'); option_selected = cm.options[cm.selectedIndex].value + ", "; emailList = document.getElementById(field + "_" + ID).value; new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length); document.getElementById(field + "_" + ID).value = new_emailList; document.getElementById(field + "_" + ID).focus(); //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none"; this.arrayWin['window_QuickCatalogSearch'].close(); } emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){ //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none"; document.getElementById(field + "_" + ID).focus(); this.arrayWin['window_QuickCatalogSearch'].close(); } emQuickCatalogSearch.prototype.close_window = function(id) { this.arrayWin[id].close(); var group_values = Element('list_values'); var user_values = Element('user_values'); } emQuickCatalogSearch.prototype.showCatalogList = function (border_id){ var el = Element('catalog_list'); if(el) { Element('border_id').value = border_id; win = this.arrayWin[el.id]; win.open(); return; } var border_input = document.createElement("INPUT"); border_input.type = 'hidden'; border_input.id = 'border_id'; border_input.value = border_id; document.body.appendChild(border_input); el = document.createElement("DIV"); el.id = 'catalog_list'; document.body.appendChild(el); el.style.visibility = "hidden"; el.style.position = "absolute"; el.style.width = "700px"; el.style.height = is_ie ? "360px" : "375px"; el.style.left = "0px"; el.style.top = "0px"; el.innerHTML = ""+ ""+ ""+ '
"+get_lang('Global Catalog')+""+get_lang('Personal Catalog')+"
'+ '

'+ ''+ ''+ ''+ ''+ ''+ ''+ '
'+get_lang("Select an organization and click on button Search")+' :
 '+ ' '+ '  
'+get_lang('Public Lists')+'  '+get_lang('Users')+'     '+ '
'+ ''+ ''+ '
'+get_lang('Click here to add into the fields')+':  '+ ' '+ ''+ '
'+ '
'+ ''; var title = get_lang('Search in the Global Catalog'); var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px"; var wWidth = el.offsetWidth + "px"; el.style.width = el.offsetWidth; Element('search_for').onkeypress = function (e) { if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) { QuickCatalogSearch.searchCatalogList(true); } }; win = new dJSWin({ id: 'win_'+el.id, content_id: el.id, width: wWidth, height: wHeight, title_color: '#3978d6', bg_color: '#eee', title: title, title_text_color: 'white', button_x_img: '../phpgwapi/images/winclose.gif', border: true }); this.arrayWin[el.id] = win; win.draw(); win.open(); var handler_catalogs = function(data){ var user_catalog = get_lang("Global Catalog"); if(data.length > 1) { Element('select_catalog').style.display = ''; for(i = 0; i < data.length; i++) { Element('select_catalog').options[i] = new Option(data[i],i); if(user_catalog.toUpperCase() == data[i].toUpperCase()) Element('select_catalog').options[i].selected = true; } } } cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs); this.update_organizations(); var handler_cc_contacts= function(data){ if(data && data.length > 0){ var aux = data.split(","); for(var i=0; i< aux.length; i++){ QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i]; } } } cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts); var handler_cc_groups = function(data){ if(data && data.length > 0){ var aux = data.split(","); for(var i=0; i < data.length; i++){ QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i]; } } } cExecute("$this.db_functions.get_cc_groups",handler_cc_groups); } emQuickCatalogSearch.prototype.select_div = function(element){ if(element == 'tab1'){ Element('tab1').style.display = ''; Element('tab2').style.display = 'none'; Element('td1').style.background = '#eee'; Element('td2').style.background = '#cecece'; } if(element == 'tab2'){ Element('tab1').style.display = 'none'; Element('tab2').style.display = ''; Element('td1').style.background = '#cecece'; Element('td2').style.background = '#eee'; } } emQuickCatalogSearch.prototype.load_catalog = function(){ var _this = this; var content = new Array; var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal'); if(Element('list_personal').style.display == 'none'){ content = _this.cc_groups; }else{ content = _this.cc_contacts; } if(select.options.length > 0){ for(var i=0; i < select.options.length; i++){ select.options[i] = null; i--; } } for(var i=0; i < content.length; i++){ if(content[i] != undefined){ var aux = content[i].split(";"); var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false); select[select.length] = opt; } } content.splice(0,(content.lenght)); } emQuickCatalogSearch.prototype.update_organizations = function(){ while(Element('select_organization').options.length > 0) { Element('select_organization').remove(0); } var handler_org = function(data){ Element('select_organization').options[0] = new Option(get_lang('all'),'all'); if (data != null){ var user_organization = Element('user_organization').value; for(x = 0; x < data.length; x++) { Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]); if(user_organization.toUpperCase() == data[x].toUpperCase()) Element('select_organization').options[x+1].selected = true; } } } cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org); } emQuickCatalogSearch.prototype.changeOptions = function(type){ switch(type){ case 'u': Element('list_values').style.display = 'none'; Element('user_values').style.display = ''; break; case 'l': Element('user_values').style.display = 'none'; Element('list_values').style.display = ''; break; case 'p': Element('list_personal').style.display = ''; Element('list_groups').style.display = 'none' QuickCatalogSearch.load_catalog(); break; case 'g': Element('list_personal').style.display = 'none'; Element('list_groups').style.display = '' QuickCatalogSearch.load_catalog(); break; } } emQuickCatalogSearch.prototype.addContacts = function(field) { var border_id = Element('border_id').value; var select = Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values'); if(field == "to1" || field == "cc1" || field == "cco1"){ field = field.substr(0,field.length - 1); var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal'); } var fieldOpener = Element(field+"_"+border_id); var not_selected = true; for (i = 0 ; i < select.length ; i++) { if (select.options[i].selected && select.options[i].value != '-1') { if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length -1))){ fieldOpener.value += ","; } fieldOpener.value += select.options[i].value + ","; not_selected = false; select.options[i].selected = false; } } if(not_selected) return false; if(field != 'to'){ a_link = Element("a_"+field+"_link_"+border_id); if(a_link) a_link.onclick(); } } emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){ if(itemSearch && Element('search_for').value.length < 4){ alert(get_lang('your search argument must be longer than 4 characters.')); Element('search_for').focus(); return false; } var organization = Element('select_organization').value; var search = itemSearch ? Element('search_for').value : ''; var catalog = Element('select_catalog').value; var max_result = 300; var handler_searchResults = function(data){ Element('msg_search').style.visibility = 'hidden'; if(data.error){ alert(get_lang('More than %1 results. Please, try to refine your search.',max_result)); return false; }else if(data.users.length == 0 && data.groups.length == 0){ alert(get_lang('None result was found.')); } var group = Element('list_span'); var user = Element('user_span'); if(is_ie){ group.innerHTML = ''; user.innerHTML = ''; } else { group = Element('list_values'); user = Element('user_values'); for(var i = 0;i < group.options.length; i++) group.options[i--] = null; for(var i = 0;i < user.options.length; i++) user.options[i--] = null; } var arr = new Array(max_result); for(i = 0; data.groups && i < data.groups.length; i++) { // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento. if(is_ie) arr[i] = ''; else group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>'); } if(is_ie) group.innerHTML = ''; arr = new Array(max_result); for(i = 0; data.users && i < data.users.length; i++) { /*******************************************************************************************/ /* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela, ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o resultado apresentado em tela sera exibido de maneira mais apresentavel; */ //verifica se departamento eh null ou nao; var department = data.users[i].department ? " - " + data.users[i].department : ""; //verifica se email eh null ou nao; var email = data.users[i].email ? data.users[i].email : ""; // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento. if(is_ie) arr[i] = ''; else { user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email; } } if(is_ie) user.innerHTML = ''; // Display entries found. var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u'; Element("type_"+type).checked = true; QuickCatalogSearch.changeOptions(type); } Element('msg_search').style.visibility = 'visible'; cExecute ("$this.ldap_functions.catalogsearch&max_result="+max_result+"&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults); } /* Build the Object */ var QuickCatalogSearch; QuickCatalogSearch = new emQuickCatalogSearch();