Index: /sandbox/2.2.0.2/contactcenter/inc/class.bo_ldap_manager.inc.php
===================================================================
--- /sandbox/2.2.0.2/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 4500)
+++ /sandbox/2.2.0.2/contactcenter/inc/class.bo_ldap_manager.inc.php	(revision 4538)
@@ -57,5 +57,6 @@
 						'branch' => $ou, //strtolower('ou'),
 						'montaDN'=> $subLevels, //$data['cc_ldap_subLevels'],
-						'visible'=> $data['cc_ldap_query_automatic']
+						'visible'=> $data['cc_ldap_query_automatic'],
+						'max_results' => $data['cc_ldap_max_results']
 					)
 				);
@@ -93,5 +94,5 @@
 		/*
 		* @function get_external_ldap_sources
-		* @author Mï¿œrio Cï¿œsar Kolling <mario.kolling@serpro.gov.br>
+		* @author Mário César Kolling <mario.kolling@serpro.gov.br>
 		* @abstract returns an array with the external sources
 		* @return (array) the external sources
Index: /sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
===================================================================
--- /sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 4353)
+++ /sandbox/2.2.0.2/contactcenter/inc/class.bo_global_ldap_catalog.inc.php	(revision 4538)
@@ -115,98 +115,162 @@
 		function find($what, $rules=false, $other=false, $area=false, $recursive=false)
 		{
-			$restric_fields = $this->get_restrictions_without_branch($rules);
-			
-			$trans_f = $this->translate_fields($what, $restric_fields);
-			
-			foreach($trans_f as $orig => $field_a)
-			{
-				foreach($field_a as $field)
-				{
-					$fields[] = $field;
-				}
-			}
-
-			$fields = array_unique($fields);
-                        
-            //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=*))";
-            
+		    $find = '';
+		    if($rules)
+		    {
+			foreach ($rules as $rule)
+			{
+			    if($rule['field'] == 'contact.names_ordered' && $find === '')
+				$find .= $rule['value'];
+			    else if($rule['field'] == 'contact.names_ordered')
+				$find .= ' '.$rule['value'];
+			}
+		    }
+
+		    if(!((strlen($find) == 2 && substr($find, -1) == '%') || $find == '%' ))
+                          return $this->findAddress($find,$other);
+
+		    $restric_fields = $this->get_restrictions_without_branch($rules);
+
+		    $trans_f = $this->translate_fields($what, $restric_fields);
+
+		    foreach($trans_f as $orig => $field_a)
+		    {
+			foreach($field_a as $field)
+			{
+			    $fields[] = $field;
+			}
+		    }
+
+		    $fields = array_unique($fields);
+
+		    //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);
+		    }
+
+		    // Find objects where 'mail' attribute is not null.
+		    $filter = "(&".$filter."(mail=*))";
 			$ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true);
 			$result_r = $recursive ? ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']) :
-            ldap_list($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']);
-
-			if (!$result_r)
+			ldap_list($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']);
+
+			 if (!$result_r)
 			{
 				return false;
 			}
-			
-			if ($other['order'])
-			{
-				$sort_f = array($other['order']);
-				$ldap_sort_by = $this->translate_fields($sort_f, $restric_fields);
-			}
-
-			if ($ldap_sort_by)
-			{
+
+		    if ($other['order'])
+		    {
+			    $sort_f = array($other['order']);
+			    $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields);
+			}
+
+		    if ($ldap_sort_by)
+		    {
 				if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0]))
 				{
-					return false;
-				}
-			}
-			
-			$result_u = ldap_get_entries($ldap, $result_r);
-			// 	No entries found.
-			if(!$result_u)
-				return true;
-			
-			$i = 0;
-			foreach ($result_u as $index => $result_p)
-			{
-				if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1'))
-				{
-					continue;
-				}
-				
-				foreach ($trans_f as $orig => $trans)
-				{
-					$orig = substr($orig, strrpos($orig, '.')+1, strlen($orig));
-					foreach ($trans as $f)
-					{
-						if ($f === 'dn')
-						{
-							$return[$i][$orig] = $result_p['dn'];
-						}
-						else if ($result_p[$f][0])
-						{
-							$return[$i][$orig] = $result_p[$f][0];
-						}
-					}
-				}
-				$i++;
-			}
-			if($return)
-				usort($return, array($this, "compareObjects"));
-			return $return;
-		}
+				    return false;
+			    }
+		    }
+
+		    $iTotalEntries = ldap_count_entries( $ldap, $result_r );
+
+		    if($iTotalEntries < 1 )
+			    return true;
+
+		    $iEnd = $iTotalEntries;
+
+		    $return = array();
+
+		    $rEntry = ldap_first_entry( $ldap, $result_r );
+		    for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++)
+		    {
+
+			$result_p = ldap_get_attributes($ldap, $rEntry );
+
+			if(!$this->external and $result_p['phpgwaccountvisible'][0] == '-1'){
+			    continue;
+			}
+
+			$returnTemp = array();
+			$returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry);
+			$returnTemp['names_ordered'] = $result_p['cn']['0'];
+
+			array_push( $return, $returnTemp );
+			$rEntry = ldap_next_entry( $ldap, $rEntry );
+
+		    }
+
+
+		    usort($return, array($this, "compareObjects"));
+		    return $return;
+		}
+
+ 		function findAddress($find, $other=false)
+		{
+
+                    require_once $_SESSION['rootPath'].'/API/class.servicelocator.php';
+                    $ldapService = ServiceLocator::getService('ldap');
+                    $filter =  $ldapService->getSearchFilter($find);
+                    $fields = array('cn','dn');
+                    $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);
+
+
+                    if (!$result_r)
+                    {
+                            return false;
+                    }
+
+                    if ($other['order'])
+                    {
+                            $sort_f = array($other['order']);
+                            $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields);
+                    }
+
+                    if ($ldap_sort_by)
+                    {
+                            if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0]))
+                            {
+                                    return false;
+                            }
+                    }
+
+                    $iTotalEntries = ldap_count_entries( $ldap, $result_r );
+
+                    if($iTotalEntries < 1 )
+                            return true;
+
+                    $iEnd = $iTotalEntries;
+
+                    $return = array();
+
+                    $rEntry = ldap_first_entry( $ldap, $result_r );
+                    for ( $iCurrent = 0; $iCurrent < $iEnd ;$iCurrent++)
+                    {
+
+                        $result_p = ldap_get_attributes($ldap, $rEntry );
+
+                        $returnTemp = array();
+                        $returnTemp['id_contact'] = ldap_get_dn($ldap, $rEntry);
+                        $returnTemp['names_ordered'] = $result_p['cn']['0'];
+
+                        array_push( $return, $returnTemp );
+                        $rEntry = ldap_next_entry( $ldap, $rEntry );
+
+                    }
+
+
+                    usort($return, array($this, "compareObjects"));
+                    return $return;
+		}
+
 		// Compare function for usort.
 		function compareObjects($a, $b)	{
Index: /sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php
===================================================================
--- /sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php	(revision 2)
+++ /sandbox/2.2.0.2/contactcenter/inc/class.abo_catalog.inc.php	(revision 4538)
@@ -685,4 +685,5 @@
 					case 'LIKE':
 					case 'iLIKE':
+					case 'LIKE and ~=':
 					case 'NOT NULL':
 					case 'NOT IN':
@@ -726,4 +727,9 @@
 						$return_t[] = 'UPPER( '.$associative_tree[$restrict_data['field']]['table'].'.'.
 						              $associative_tree[$restrict_data['field']]['field'].') LIKE UPPER(\''.$restrict_data['value'].'\')';
+						break;
+					
+					case 'LIKE and ~=':
+						$return_t[] = 'UPPER( '.$associative_tree[$restrict_data['field']]['table'].'.'.
+						              $associative_tree[$restrict_data['field']]['field'].') LIKE UPPER(\''."%".$restrict_data['value']."%".'\')';	
 						break;
 					
Index: /sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- /sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php	(revision 4513)
+++ /sandbox/2.2.0.2/contactcenter/inc/class.ui_data.inc.php	(revision 4538)
@@ -3172,10 +3172,10 @@
 			if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields']))
 			{
-				echo serialize(array(
-					'msg'    => lang('Invalid parameters'),
-					'status' => 'abort'
-				));
-
-				return array('error' => lang('Invalid parameters'));
+			    echo serialize(array(
+				    'msg'    => lang('Invalid parameters'),
+				    'status' => 'abort'
+			    ));
+
+			    return array('error' => lang('Invalid parameters'));
 			}
 
@@ -3211,19 +3211,19 @@
 			else
 			{
-				$names = explode(' ', $data['search_for']);
-
-				if (!is_array($names))
-				{
-					if(!$full_search) {
-						echo serialize(array(
-							'msg'    => lang('Invalid Search Parameter'),
-							'status' => 'abort'
-						));
-						exit;
-					}
-					else 
-						$names = array();
-
-				}
+			    $names = explode(' ', $data['search_for']);
+
+			    if (!is_array($names))
+			    {
+				    if(!$full_search) {
+					    echo serialize(array(
+						    'msg'    => lang('Invalid Search Parameter'),
+						    'status' => 'abort'
+					    ));
+					    exit;
+				    }
+				    else 
+					    $names = array();
+
+			    }
 
 				if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
@@ -3287,8 +3287,8 @@
 							array_push($rules,array(
 											'field' => $this->aux_full_search($field,false),
-											'type' => 'iLIKE',
-											'value' => '%'.$value.'%'
+											'type'  => 'LIKE and ~=',
+											'value' => $name
 											));
-					}
+            					}
 				
 				}
@@ -3300,6 +3300,6 @@
 						array_push($rules, array(
 							'field' => $data['fields']['search'],
-							'type'  => 'iLIKE',
-							'value' => '%'.$name.'%'
+							'type'  => 'LIKE and ~=',
+							'value' => $name
 						));
 					}
Index: /sandbox/2.2.0.2/contactcenter/templates/classic/config.tpl
===================================================================
--- /sandbox/2.2.0.2/contactcenter/templates/classic/config.tpl	(revision 285)
+++ /sandbox/2.2.0.2/contactcenter/templates/classic/config.tpl	(revision 4538)
@@ -60,4 +60,9 @@
 		</td>
 	</tr>
+	<tr class="row_on">
+		<td>{lang_LDAP_max_results}:</td>
+		<td><input name="newsettings[cc_ldap_max_results]" value="{value_cc_ldap_max_results}" size="40" /></td>
+	</tr>
+
   
   <!-- <tr class="row_on">
Index: /sandbox/2.2.0.2/contactcenter/templates/default/config.tpl
===================================================================
--- /sandbox/2.2.0.2/contactcenter/templates/default/config.tpl	(revision 4500)
+++ /sandbox/2.2.0.2/contactcenter/templates/default/config.tpl	(revision 4538)
@@ -53,4 +53,8 @@
 		<td><input name="newsettings[cc_ldap_pw0]" type="password" value="" size="40" /></td>
 	</tr>
+	<tr class="row_on">
+		<td>{lang_LDAP_max_results}:</td>
+		<td><input name="newsettings[cc_ldap_max_results]" value="{value_cc_ldap_max_results}" size="40" /></td>
+	</tr>
 	<tr class="row_off">
 		<td>{lang_Open_automatic_contact} :</td>
@@ -62,5 +66,5 @@
 		</td>
 	</tr>
-	<tr class="row_on">
+	<tr class="row_off">
 		<td>{lang_Minimal_character_to_name_search}:</td>
 		<td>
@@ -72,5 +76,5 @@
 		</td>
 	</tr>
-	<tr class="row_off">
+	<tr class="row_on">
 		<td>Montar DN do contatos dinamicamente?</td>
 		<td>
@@ -143,19 +147,6 @@
 		<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 -->
