Index: /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 325)
+++ /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 342)
@@ -1,4 +1,5 @@
 <?php			
 include_once("class.imap_functions.inc.php");
+include_once("class.functions.inc.php");
 
 function ldapRebind($ldap_connection, $ldap_url)
@@ -13,33 +14,39 @@
 	var $ldap_context;
 	var $imap;
-	
-	// usa o host e context do contact center.
-	function ldapConnect($refer = false,$catalogo = 0){
-	include("../contactcenter/setup/external_catalogs.inc.php");
-		if ($catalogo == 0){
+	var $external_srcs;
+	var $max_result;
+	var $functions;
+	function ldap_functions(){
+	// todo: Page Configuration for External Catalogs.
+		@include("../contactcenter/setup/external_catalogs.inc.php");
+		$this->external_srcs= $external_srcs;
+		$this->max_result 	= 200;		
+		$this->functions = new functions();		
+	}	
+	// Using ContactCenter configuration.
+	function ldapConnect($refer = false,$catalog = 0){
+		if ($catalog > 0 && is_array($this->external_srcs)){
+			$this->ldap_host 	= $this->external_srcs[$catalog]['host'];
+			$this->ldap_context = $this->external_srcs[$catalog]['dn'];
+			$this->bind_dn 		= $this->external_srcs[$catalog]['acc'];
+			$this->bind_dn_pw 	= $this->external_srcs[$catalog]['pw'];
+			$this->object_class = $this->external_srcs[$catalog]['obj'];
+			$this->base_dn 		= $this->external_srcs[$catalog]['dn'];
+			$this->branch 		= $this->external_srcs[$catalog]['branch'];
+		}else {
 			$this->ldap_host 	= $_SESSION['phpgw_info']['expressomail']['ldap_server']['host'];
 			$this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
 			$this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'];
 			$this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw'];
-			$this->branch = 'ou';			
-		}else {
-			
-			$this->ldap_host 	=   $external_srcs[$catalogo]['host'];
-			$this->ldap_context =   $external_srcs[$catalogo]['dn'];
-			$this->bind_dn = $external_srcs[$catalogo]['acc'];
-			$this->bind_dn_pw = $external_srcs[$catalogo]['pw'];
-			$this->object_class = $external_srcs[$catalogo]['obj'];
-			$this->base_dn = $external_srcs[$catalogo]['dn'];
-			$this->branch = $external_srcs[$catalogo]['branch'];
-
-		}
+			$this->branch = 'ou';				
+		}
+		
 		$this->ds = ldap_connect($this->ldap_host);
 		ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
 		ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer);
-		if ($refer){
+		if ($refer)	{
 			ldap_set_rebind_proc($this->ds, ldapRebind);
 		}
-		@ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw );				
-		
+		@ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw );		
 	}
 
@@ -74,5 +81,4 @@
 	function quicksearch($params)
 	{	
-		include_once("../contactcenter/setup/external_catalogs.inc.php");
 		include_once("class.functions.inc.php");
 		$functions = new functions;						
@@ -102,20 +108,22 @@
 		// follow the referral
 		$this->ldapConnect(true);
-		
+				
 		if ($this->ds)
-			{
+		{
 			if (($field != 'null') && ($ID != 'null'))
-				{
+			{
 				$filter="(& (|(phpgwAccountType=u)(phpgwAccountType=l)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )";
 				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou");
-				}
+			}
 			else
-				{
+			{
 				$filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )";
-				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "jpegPhoto", "uid", "employeeNumber", "ou");
-				}
-			$sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, 201);
+				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid", "employeeNumber", "ou");
+			}
+			$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1);
+			if(!$sr)
+				return null;
 			$count_entries = ldap_count_entries($this->ds,$sr);
-			
+
 			// Get user org dn.			
 			$user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn'];
@@ -126,6 +134,6 @@
 			
 			// New search only on user sector
-			if ($count_entries > 200)
-			{
+			if ($count_entries > $this->max_result)
+ 			{
 				// Close old ldap conection
 				ldap_close($this->ds);
@@ -134,8 +142,10 @@
 				$this->ldapRootConnect(true);
 				
-				$sr=ldap_search($this->ds, $user_sector_dn, $filter, $justthese, 0, 201);
+				$sr= ldap_search($this->ds, $user_sector_dn, $filter, $justthese);
+				if(!$sr)
+					return null;
 				$count_entries = ldap_count_entries($this->ds,$sr);
 				
-				if ($count_entries > 200){
+				if ($count_entries > $this->max_result){
 					$return = array();
 					$return['status'] = false;
@@ -154,44 +164,42 @@
 			$tmp_users_from_user_org = array();
 			
-			if (!$quickSearch_only_in_userSector)
-				{
-				$catalogsNum=count($external_srcs);
-				for ($i=0; $i<=count($external_srcs); $i++)
-					{
-					if ($external_srcs[$i]["quicksearch"])
-						{
+			if (!$quickSearch_only_in_userSector) {
+				$catalogsNum=count($this->external_srcs);
+				for ($i=0; $i<=count($this->external_srcs); $i++)	{
+					if ($this->external_srcs[$i]["quicksearch"]) {
 						$this->ldapConnect(true,$i);
 						$filter="(|(cn=*$search_for*)(mail=*$search_for*))";
-						$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou");
-						$sr=ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, 201);
+						$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou");
+						$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
+						if(!$sr)
+							return null;
 						$count_entries = ldap_count_entries($this->ds,$sr);
 						$search = ldap_get_entries($this->ds, $sr);
-						for ($i=0; $i<$search["count"]; $i++)
-							{
+						for ($i=0; $i<$search["count"]; $i++) {
 							$info[] = $search[$i];
-							}
+						}
 						$info["count"] = count($info)-1;
-						}
 					}
 				}
-			
+			}
+
 			for ($i=0; $i<$info["count"]; $i++)
-				{
+			{
 				if ($quickSearch_only_in_userSector)
+				{
+					$tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]);
+				}
+				else
+				{
+					if (preg_match("/$user_sector_dn/i", $info[$i]['dn']))
 					{
-					$tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]);
+						$tmp_users_from_user_org[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]);
 					}
-				else
+					else
 					{
-					if (preg_match("/$user_sector_dn/i", $info[$i]['dn']))
-						{
-						$tmp_users_from_user_org[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]);
-						}
-					else
-						{
 						$tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]);
-						}
 					}
 				}
+			}
 			natcasesort($tmp_users_from_user_org);
 			natcasesort($tmp);
@@ -242,6 +250,6 @@
 							'<tr class="quicksearchcontacts_unselected">' .
 								'<td colspan="2" width="100%" align="center">' .
-									$functions->getLang('More than 200 results were found') . '.<br>' .
-									$functions->getLang('Showing only the results found in your organization') . '.';
+									str_replace("%1", $this->max_result,$this->functions->getLang('More than %1 results were found')) . '.<br>' .
+									$this->functions->getLang('Showing only the results found in your organization') . '.';
 								'</td>' .
 							'</tr>';
@@ -263,6 +271,6 @@
 							'<tr class="quicksearchcontacts_unselected">' .
 								'<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
-									$functions->getLang('Users from your organization') . '.';
-								'</B></td>' .
+									$this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
+								'</td>' .
 							'</tr>';
 
@@ -270,6 +278,6 @@
 							'<tr class="quicksearchcontacts_unselected">' .
 								'<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
-									$functions->getLang('Users from others organizations') . '.';
-								'</B></td>' .
+									$this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
+								'</td>' .
 							'</tr>';
 					}
@@ -299,7 +307,7 @@
 					
 		if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) {
-			$phoneUser = '<a title="'.$functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>';
+			$phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>';
 			if($contacts_result['mobile']){
-				$phoneUser .= ' / <a title="'.$functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>';
+				$phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>';
 			}
 		}
@@ -307,5 +315,5 @@
 			'<tr class="quicksearchcontacts_unselected">' .
 				'<td class="cc" width="1%">' .
-					'<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
+					'<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
 						$photo_link .
 					'</a>' .
@@ -313,5 +321,5 @@
 				'<td class="cc">' .
 					'<span name="cn">' . $contacts_result['cn'] . '</span>' . '<br>' .
-					'<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
+					'<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' .
 						'<font color=blue>' .
 							'<span name="mail">' . $contacts_result['mail'] . '</span>' . '<br>' .
@@ -324,9 +332,9 @@
 	}
 
-	function get_catalogs(){
-		include("../contactcenter/setup/external_catalogs.inc.php");
+	function get_catalogs(){		
 		$catalogs = array();
-		$catalogs[0] = "Catalogo geral"; 
-		foreach ($external_srcs as $key => $valor ){
+		$catalogs[0] = $this->functions->getLang("Global Catalog");		
+		if($this->external_srcs) 
+			foreach ($this->external_srcs as $key => $valor ){
 			$catalogs[$key] = $valor['name'];
 		}
@@ -334,5 +342,4 @@
 	}
 	function get_organizations($params){
-
 		$organizations = array();
 		$params['referral']?$referral = $params['referral']:$referral = false;
@@ -344,16 +351,16 @@
 				$filter=$this->branch."=*";
 				$justthese = array("$this->branch");
-				$sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
-				$info = ldap_get_entries($this->ds, $sr);
-
-				for ($i=0; $i<$info["count"]; $i++)
-					$organizations[$i] = $info[$i]["ou"][0];
-
-				ldap_close($this->ds);
-				sort($organizations);
-				return $organizations;
+			$sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese);
+			$info = ldap_get_entries($this->ds, $sr);
+			
+			for ($i=0; $i<$info["count"]; $i++)
+				$organizations[$i] = $info[$i]["ou"][0];
+
+			ldap_close($this->ds);
+			sort($organizations);					
+		return $organizations;
 			}else{
 			return null;
-		}
+	}
 	}
 	function get_organizations2($params){
@@ -381,14 +388,12 @@
 	function catalogsearch($params)
 	{	
-		//$this->ldapConnect(true);
-		include("../contactcenter/inc/external_catalogs.inc.php");
 		$cn	= $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*";
-		$max_result	  = $params['max_result'] ? $params['max_result'] : '200';
+		$max_result	  = $params['max_result'] ? $params['max_result'] : $this->max_result;		
 		$catalog = $params['catalog'];
 		$error = False;
-			
+		
 		$this->ldapConnect(false,$catalog);
 		
-		$params['organization'] == 'todos'?$user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;		
+		$params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context;		
 		
 		if ($this->ds) {											
@@ -405,7 +410,9 @@
 			}
 			
-			$sr=ldap_search($this->ds, $user_context, $filter, $justthese,0,200);
+			$sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $this->max_result+1);
+			if(!$sr)
+				return null;
 			$count_entries = ldap_count_entries($this->ds,$sr);
-			if ($count_entries > $max_result){
+			if ($count_entries > $this->max_result){
 				$info = null;
 				$error = True;						
@@ -429,10 +436,9 @@
 			natcasesort($u_tmp);
 			natcasesort($g_tmp);
-
+			
 			$i = 0;
-			$users = array();
-
-
-			foreach ($u_tmp as $mail => $cn){
+			$users = array();			
+			
+			foreach ($u_tmp as $mail => $cn){				
 
 				$tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp;
@@ -442,5 +448,4 @@
 
 			}
-
 			unset($u_tmp);
 			
@@ -479,9 +484,9 @@
 	}
 	
-	//Busca usuï¿œrios de um contexto e jï¿œ retorna as options do select;
+	//Busca usuarios de um contexto e ja retorna as options do select;
 	function get_available_users($params)
     {
         $this->ldapRootConnect();
-        //Monta lista de Grupos e Usuï¿œrios
+        //Monta lista de Grupos e Usuarios
         $users = Array();
         $groups = Array();
@@ -535,5 +540,5 @@
     }
 
-	//Busca usuï¿œrios de um contexto e jï¿œ retorna as options do select;
+	//Busca usuarios de um contexto e ja retorna as options do select;
 	function get_available_users2($params)
 	{
@@ -626,5 +631,5 @@
 		if ($ds)
 		{			
-			$sr=ldap_search($ds, $ldap_context, $filter, $justthese);
+			$sr=@ldap_search($ds, $ldap_context, $filter, $justthese);
 			
 			if (!$sr)
Index: /trunk/expressoMail1_2/js/QuickCatalogSearch.js
===================================================================
--- /trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 325)
+++ /trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 342)
@@ -139,5 +139,4 @@
 			Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
 			cmb.options.add(Op);
-
 		}
 		cmb.options[0].selected = true;
@@ -153,5 +152,5 @@
 							
 		if(! this.arrayWin[div.id]) {
-			div.style.width = "700px"; //na comunidade valor eh 600px
+			div.style.width = "700px";
 			div.style.height = "230px";
 			var title = get_lang('The results were found in the Global Catalog')+':';
@@ -226,5 +225,5 @@
 		el.style.visibility = "hidden";
 		el.style.position = "absolute";
-		el.style.width = "700px"; // na comunidade valor eh 495px
+		el.style.width = "700px";
 		el.style.height = is_ie ? "360px" : "375px";		
 		el.style.left = "0px";
@@ -239,6 +238,6 @@
   					'<tr><td><select style="width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select>&nbsp'+
 					'<select id="select_organization" style="width:100px" name="select_organization"></select>&nbsp;'+   
-					'<input type="text" id="search_for" name="search_for" value="" size="10" maxlength="15"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:none" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
-					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
+					'<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="20"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:none" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
+					   //'<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
 					   '<span style="visibility:hidden;background:#cc4444" id=msg_search>&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font>&nbsp;</span></td></tr>'+
 					   '<tr><td>'+
@@ -298,13 +297,16 @@
 			var user_catalog = "Catalogo Geral";
 
-			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;
+			if(data.length <= 1) 
+				Element('select_catalog').style.display = 'none';
+			else {
+				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();
 	
@@ -383,9 +385,9 @@
                 
 	 	var handler_org = function(data){
-                        Element('select_organization').options[0] = new Option('todos','todos');
+                        Element('select_organization').options[0] = new Option(get_lang('all'),'all');
 			if (data != null){
 			
 			for(x = 0; x < data.length; x++) {
-				Element('select_organization').options[x+1] = new Option(data[x],data[x]);
+				Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]);
 				}
 			}
@@ -512,5 +514,5 @@
 				}
 				else{
-
+	
 				/*******************************************************************************************/
 				/* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela,
