Index: /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 1419)
+++ /trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 1598)
@@ -41,6 +41,4 @@
 			'pgp_key'       => true,
 			'notes'         => true,
-			
-			/* Array fields */
 			'companies'     => true,
 			'relations'     => true,
@@ -115,5 +113,5 @@
 		
 		*/
-		function find($what, $rules=false, $other=false)
+		function find($what, $rules=false, $other=false, $area=false)
 		{
 			$restric_fields = $this->get_restrictions_without_branch($rules);
@@ -128,16 +126,43 @@
 				}
 			}
-			
+
 			$fields = array_unique($fields);
-			
-			$filter = $this->process_restrictions($rules, $trans_f);
-			// Find objects where 'mail' attribute is not null.
+                        
+            //Testa se a busca foi realizada com aspas
+            $rules_search = $rules[3]['value'];
+            $rules_len = (strlen($rules_search)) -1;
+
+            if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){
+				$rules_search = substr($rules_search,2,$rules_len-3);
+				$filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))";
+            }
+            else{
+				$filter = $this->process_restrictions($rules, $trans_f);
+            }
+                        
+            if ($area)
+            {
+                 $obj = CreateObject('phpgwapi.config','contactcenter');
+                 $opts = $obj->read_repository();
+                 $filter = substr($filter,0,-1) .'(' . $opts['cc_ldap_atrib'] . '=*' . $area . '*))';
+                 $opts = null;
+                 $obj = null;
+            }
+            // Find objects where 'mail' attribute is not null.
 			$filter = "(&".$filter."(mail=*))";
-			if("ou" === strtolower(substr($this->src_info['context'], 0, 2)) ||
-				(trim($rules[0]['value']) == "phpgwAccount"))	
-			{			
-				$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true);
-				$result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']);
-			}
+
+                        if(strstr($this->src_info['context'], "ldap://")) {
+                                $refer_context  = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $this->src_info['context']));
+                                $host   = preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']);
+                                $this->src_info['host'] = $host;
+                        }
+                        if($refer_context || "ou" === strtolower(substr($this->src_info['context'], 0, 2)))
+                        {
+                                $followReferral = false;
+                        }
+                        elseif(trim($rules[4]['value']) != "inetOrgPerson")
+                        {
+                                $followReferral = true;
+                        }
 			else
 			{				
@@ -145,4 +170,6 @@
 			}
 			
+                        $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], $followReferral);
+                        $result_r = ldap_search($ldap ,($refer_context  ? $refer_context  : $this->src_info['context']), $filter, $fields, 0, $this->src_info['max_results']);
 
 			if (!$result_r)
@@ -192,9 +219,9 @@
 				$i++;
 			}
-			usort($return, array($this, "compareObjects"));							
+			usort($return, array($this, "compareObjects"));
 			return $return;
 		}
 		// Compare function for usort.
-		function compareObjects($a, $b)	{						
+		function compareObjects($a, $b)	{
 			return strnatcasecmp($a['names_ordered'], $b['names_ordered']);
 		}
@@ -580,5 +607,5 @@
 			}
 
-			
+//			print_r($contact);
 			
 		//	$contact_data = $this->fields;
@@ -598,7 +625,26 @@
 						$l_fields['company_name']  = $this->trans_table['contact.company.company_name'];
 						$l_fields['title']         = $this->trans_table['contact.business_info.title'];
-						$l_fields['department']    = $this->trans_table['contact.business_info.department'];
+						//$l_fields['department']    = $this->trans_table['contact.business_info.department'];
 						$l_fields['company_notes'] = $this->trans_table['contact.company.company_notes'];
-						
+
+						//Relaciona o array com o atributo 'ou' do RHDS; tambem verifica se a
+						//preferencia esta configurada para exibir o campo
+						if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow'])
+						{
+							$l_fields['department']    = $this->trans_table['contact.business_info.department'];
+						}
+						//Relaciona o array com o atributo 'employeeNumber' do RHDS; tambem verifica se a
+						//preferencia esta configurada para exibir o campo
+						if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow'])
+						{
+							$l_fields['empNumber']     = $this->trans_table['contact.business_info.empNumber'];
+						}
+						//Relaciona o array com o atributo 'mobile' do RHDS; tambem verifica se a
+						//preferencia esta configurada para exibir o campo
+						if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow'])
+						{
+							$l_fields['celPhone']     = $this->trans_table['contact.business_info.celPhone'];
+						}
+
 						$contact_data['companies'] = array();
 						foreach($l_fields as $l_field => $l_value)
@@ -920,4 +966,15 @@
 							$l_fields['company_notes'] = $this->trans_table['contact.company.company_notes'];
 
+							//Relaciona o array com o atributo 'employeeNumber' do RHDS
+							if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumberShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumberShow'])
+							{
+								$l_fields['empNumber']     = $this->trans_table['contact.business_info.empNumber'];
+							}
+							//Relaciona o array com o atributo 'mobile' do RHDS
+							$l_fields['celPhone']     = $this->trans_table['contact.business_info.celPhone'];
+
+							//Relaciona o array com o atributo 'mobile' do RHDS
+							$l_fields['celPhone']     = $this->trans_table['contact.business_info.celPhone'];
+
 							$contact_data['companies'] = array();
 							foreach($l_fields as $l_field => $l_value)
Index: /trunk/contactcenter/inc/class.bo_contactcenter.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 752)
+++ /trunk/contactcenter/inc/class.bo_contactcenter.inc.php	(revision 1598)
@@ -206,7 +206,7 @@
 				
 		*/
-		function find($what, $rules=false, $other=false)
-		{
-			return $this->catalog->find($what, $rules, $other);
+		function find($what, $rules=false, $other=false, $area=false)
+		{
+			return $this->catalog->find($what, $rules, $other, $area);
 		}
 		
Index: /trunk/contactcenter/js/cc_tree.js
===================================================================
--- /trunk/contactcenter/js/cc_tree.js	(revision 285)
+++ /trunk/contactcenter/js/cc_tree.js	(revision 1598)
@@ -72,5 +72,4 @@
 			}
 		};
-
 		Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
 	}
@@ -102,5 +101,4 @@
 			
 		};
-
 		Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
 	}
Index: /trunk/contactcenter/js/cc_search.js
===================================================================
--- /trunk/contactcenter/js/cc_search.js	(revision 285)
+++ /trunk/contactcenter/js/cc_search.js	(revision 1598)
@@ -27,5 +27,4 @@
 		this.onClose = null;
 		this.onOpen = null;
-
 		this.DOMholder = params['holder'];
 		this.DOMdiv = document.createElement('div');
@@ -33,4 +32,7 @@
 		this.DOMinput = document.createElement('input');
 		this.DOMbtn = document.createElement('input');
+                this.DOMbtn2 = document.createElement('input');
+                this.DOMbtn3 = document.createElement('input');
+                this.DOMinputx = document.createElement('input');
 		this.DOMprogHold = document.createElement('div');
 		this.DOMresult = document.createElement('div');
@@ -59,4 +61,5 @@
 		this.DOMinput.type = 'text';
 		this.DOMinput.value = params['value'] ? params['value'] : '';
+                this.DOMinput.id = 'DOMinput';
 		this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px';
 		this.DOMinput.onkeypress = function (e) { 
@@ -70,4 +73,20 @@
 				}
 			};
+
+		this.DOMinputx.type = 'text';
+		this.DOMinputx.value = params['value'] ? params['value'] : '';
+                this.DOMinputx.id = 'DOMinputx';
+		this.DOMinputx.style.width = '100px';
+		this.DOMinputx.onkeypress = function (e) {
+				if (is_ie)
+				{
+					if (window.event.keyCode == 13) _this.go();
+				}
+				else
+				{
+					if (e.which == 13) _this.go();
+				}
+			};
+
 		//this.DOMinput.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
 
@@ -78,4 +97,13 @@
 		this.DOMbtn.onclick = function () {_this.go();};
 
+		this.DOMbtn2.type = 'button';
+		//this.DOMbtn2.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
+		this.DOMbtn2.style.width = '60px';
+		this.DOMbtn2.value = 'Nome:';
+
+		this.DOMbtn3.type = 'button';
+		//this.DOMbtn3.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
+		this.DOMbtn3.style.width = '60px';
+		this.DOMbtn3.value =  v_label;
 		this.DOMprogHold.style.position = 'absolute';
 		this.DOMprogHold.style.top = params['progress_top'] ? params['progress_top'] : '0px';
@@ -98,5 +126,11 @@
 		this.DOMholder.appendChild(this.DOMdiv);	
 		this.DOMdiv.appendChild(this.DOMfields);
+                this.DOMdiv.appendChild(this.DOMbtn2);
 		this.DOMdiv.appendChild(this.DOMinput);
+                if(v_label != false &  v_atrib != false)
+                    {
+                        this.DOMdiv.appendChild(this.DOMbtn3)
+                        this.DOMdiv.appendChild(this.DOMinputx);
+                    }
 		this.DOMdiv.appendChild(spacer);
 		this.DOMdiv.appendChild(this.DOMbtn);
@@ -126,10 +160,23 @@
 		
 		data['search_for']       = this.DOMinput.value;
+                data['search_for_area']       = this.DOMinputx.value;
+
 		var search_for = data['search_for'].split(' ');
 		var greaterThan4 = false;
+                var use_length = v_min;
+
+                if (search_for.length == 1)
+                    {
+                        if(search_for[0].length == 0)
+                            {
+                                search_for[0] = "*";
+                                data['search_for'] = "*";
+                                use_length = 1;
+                            }
+                    }
 
 		for (i = 0; i < search_for.length; i++)
 		{
-			if (search_for[i].length >= 4)
+			if (search_for[i].length >= use_length)
 			{
 				greaterThan4 = true;
@@ -138,5 +185,5 @@
 
 		if (!greaterThan4){
-			alert("Favor fazer a consulta com pelo menos 4 caracteres!");
+			alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!");
 			return;
 		}
@@ -240,5 +287,5 @@
 			}
 		};
-		
-		this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
+
+                this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
 	}
Index: /trunk/contactcenter/js/ccMain.js
===================================================================
--- /trunk/contactcenter/js/ccMain.js	(revision 1496)
+++ /trunk/contactcenter/js/ccMain.js	(revision 1598)
@@ -13,5 +13,5 @@
 var ccSearch, ccTree;
 var Main_load = function () 
-	{ 	
+	{
 		Connector.setProgressBox(Element('cc_loading'), true);
 		Connector.setProgressHolder(Element('cc_loading_inner'));		
@@ -91,5 +91,5 @@
 		submenu = [];
 		textmenu = [];
-
+			
 		textmenu[0] = ["cc_msg_contact_qa","cc_msg_contact_full","cc_msg_contact_sh","cc_msg_group"];
 		textmenu[1] = ["cc_quick_add", "cc_full_add_button", "cc_full_add_button_sh", "cc_add_group_button"];
@@ -104,5 +104,4 @@
 			
 		if(document.getElementById) {
-
 			menu = document.getElementById("Layer1");
 				
@@ -128,5 +127,5 @@
 		Element("cc_full_add_button").onclick = newContact;
 		Element("cc_full_add_button_sh").onclick = newSharedContact;
-
+			 
 			
 		ccQuickAdd.afterSave = function ()
@@ -159,5 +158,6 @@
 	}
 	else
-	{		
+	{
+                
 		Main_load();	
 			
Index: /trunk/contactcenter/index.php
===================================================================
--- /trunk/contactcenter/index.php	(revision 498)
+++ /trunk/contactcenter/index.php	(revision 1598)
@@ -24,4 +24,29 @@
 
 	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['telephone_number'] = $GLOBALS['phpgw_info']['user']['telephonenumber'];
+
+	$prefs = CreateObject('contactcenter.ui_preferences');
+	$actual = $prefs->get_preferences();
+
+	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow'] = false;
+	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow'] = false;
+	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow'] = false;
+
+	if ($actual['empNum'])
+	{
+		$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow'] = true;
+	}
+
+	if ($actual['cell'])
+	{
+		$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow'] = true;
+	}
+
+	if ($actual['department'])
+	{
+		$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow'] = true;
+	}
+
+
+        
 	//Enable/Disable VoIP Service -> Voip Server Config
 	$_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] = false;	
@@ -38,5 +63,6 @@
 			}
 		}
-	}    
+	}
+
 	// Verificar se há contatos compartilhados para o usuario logado
 	$acl = CreateObject("phpgwapi.acl",$GLOBALS['phpgw_info']['user']['account_id']); 
@@ -47,6 +73,12 @@
 		}
 	}
-	$obj = CreateObject('contactcenter.ui_data');	
-	$obj->index();
+        $obj = CreateObject('phpgwapi.config','contactcenter');
+        $opts = $obj->read_repository();
+        echo '<script> var v_label = \'' . $opts['cc_ldap_legend'] . '\'; var v_atrib = \'' . $opts['cc_ldap_atrib'] . '\';  v_min = \'' . $opts['cc_ldap_min'] . '\' </script>';
+        $opts = null;
+	$obj = CreateObject('contactcenter.ui_data');
+		$obj->index();
+       
+   	
 	$GLOBALS['phpgw']->common->phpgw_footer();
 ?>
Index: /trunk/contactcenter/templates/default/config.tpl
===================================================================
--- /trunk/contactcenter/templates/default/config.tpl	(revision 1158)
+++ /trunk/contactcenter/templates/default/config.tpl	(revision 1598)
@@ -52,5 +52,5 @@
 	</tr>
 	<tr class="row_off">
-		<td>Abrir Consulta Automática :</td>
+		<td>{lang_Open_automatic_contact} :</td>
 		<td>
 			<select name="newsettings[cc_ldap_query_automatic]">
@@ -60,5 +60,23 @@
 		</td>
 	</tr>
-  
+	<tr class="row_on">
+		<td>{lang_Minimal_character_to_name_search}:</td>
+		<td>
+			<select name="newsettings[cc_ldap_min]">
+				<option value="2" {selected_cc_ldap_min_2}>2</option>
+				<option value="3" {selected_cc_ldap_min_3}>3</option>
+				<option value="4" {selected_cc_ldap_min_4}>4</option>
+			</select>
+		</td>
+	</tr>
+	<tr class="th">
+		<td colspan="2">&nbsp;</td>
+	</tr>
+	<tr>
+   		<td></td>
+	</tr>
+	<tr>
+   		<td></td>
+	</tr>
   <!-- <tr class="row_on">
   	<td>{lang_objectClass_to_be_used_as_a_Contact}:</td>
@@ -104,4 +122,19 @@
 		<td><input type="text" size="40" name="newsettings[cc_ldap_ass_fulln0]" value="{value_cc_ldap_ass_fulln0}"></td>
 	</tr>-->
+	<tr class="th">
+		<td colspan="2" align="center"><b>{lang_Extended_search_configuration}:</b></td>
+	</tr>
+	<tr>
+   		<td></td>
+	</tr>
+	<tr class="row_off">
+		<td>{lang_LDAP_attribute_to_search} :</td>
+		<td><input name="newsettings[cc_ldap_atrib]" value="{value_cc_ldap_atrib}" size="40" /></td>
+	</tr>
+	<tr class="row_on">
+		<td>{lang_Label} :</td>
+		<td><input name="newsettings[cc_ldap_legend]" value="{value_cc_ldap_legend}" size="40" /></td>
+	</tr>
+
 <!-- END body -->
 <!-- BEGIN footer -->
