Index: branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php
===================================================================
--- branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php	(revision 493)
+++ branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php	(revision 3351)
@@ -166,6 +166,7 @@
 		function add_maillists()
 		{
-			$GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
-
+			if($this->current_config['users_auto_search'] == "true"){
+				$GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
+			}
 			$manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
 			$manager_acl = $this->functions->read_acl($manager_lid);
@@ -205,5 +206,7 @@
 				'combo_manager_org'			=> $combo_manager_org,
 				'combo_all_orgs'			=> $combo_all_orgs,
-				'defaultDomain'				=> $this->current_config['expressoAdmin_defaultDomain']
+				'defaultDomain'				=> $this->current_config['expressoAdmin_defaultDomain'],
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
@@ -304,5 +307,7 @@
 				'phpgwAccountVisible_checked'	=> $maillist_info['phpgwAccountVisible'] == '-1' ? 'CHECKED' : '',
 				'ea_select_usersInMaillist'		=> $ea_select_usersInMaillist,
-				'defaultDomain'					=> $this->current_config['expressoAdmin_defaultDomain']
+				'defaultDomain'					=> $this->current_config['expressoAdmin_defaultDomain'],
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
@@ -373,5 +378,7 @@
 				'accountRestrictive_checked'	=> $maillist_info['accountRestrictive'] == 'mailListRestriction' ? 'CHECKED' : '',
 				'participantCanSendMail_checked'=> $maillist_info['participantCanSendMail'] == 'TRUE' ? 'CHECKED' : '',
-				'ea_select_users_SCL_Maillist'	=> $ea_select_users_SCL_Maillist
+				'ea_select_users_SCL_Maillist'	=> $ea_select_users_SCL_Maillist,
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
Index: branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 3171)
+++ branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 3351)
@@ -764,36 +764,37 @@
 
 		if ($recursive == 'true')
-		{
-			$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);
 			$users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese);
-		}
-		else
-		{
-			$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+		else
 			$users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese);
-		}
-		
+
 		/* email lists */
-		$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
-		
-		for ($i=0; $i<$lists_entries["count"]; $i++)
-		{
-			$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
-		}
-			
-		if (count($l_tmp))
-			natcasesort($l_tmp);
-			
-		$i = 0;
-		$lists = array();
-		
-		$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
-		if (count($l_tmp))
-		{
-			foreach ($l_tmp as $mail => $cn)
-			{
-				$options .= "<option value=$mail>$cn</option>";
-			}
-			unset($l_tmp);
+		if($params['listSearch'] == 'true'){
+			if ($recursive == 'true')
+				$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);			
+			else			
+				$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+
+			$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
+
+			for ($i=0; $i<$lists_entries["count"]; $i++)
+			{
+				$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
+			}
+
+			if (count($l_tmp))
+				natcasesort($l_tmp);
+
+			$i = 0;
+			$lists = array();
+
+			$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
+			if (count($l_tmp))
+			{
+				foreach ($l_tmp as $mail => $cn)
+				{
+					$options .= "<option value=$mail>$cn</option>";
+				}
+				unset($l_tmp);
+			}
 		}
 		
@@ -2626,4 +2627,98 @@
 		return $return;
 	}
+
+	function search_available_users_and_maillist($params)
+	{
+		$context = $params['context'];
+		$recursive = $params['recursive'];
+		 $filtro =utf8_encode($params['filter']);
+		//Usado para retirar a própria lista das possibilidades de inclusão.
+		$denied_uidnumber = $params['denied_uidnumber'];
+		
+		$justthese = array("cn", "uidNumber", "mail");				
+		
+		$users_filter="(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))";
+		$lists_filter = $denied_uidnumber == '' ? "(&(phpgwAccountType=l)(cn=*$filtro*))" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber))(|(cn=*$filtro*)(mail=$filtro*)))";
+		
+		$users = Array();
+		$lists = Array();		
+
+		/* folling referral connection */
+		$ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']);
+		if ($ldap_conn_following_ref)
+		{
+			ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3);
+			ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1);
+
+			if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') )
+				ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']);
+		}
+		else
+			return false;
+		
+		if ($recursive == 'true')
+			$users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese);
+		else
+			$users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese);
+		
+		/* email lists */
+		if($params['listSearch'] == 'true'){
+			if ($recursive == 'true')
+				$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);			
+			else			
+				$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+				
+			$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
+			
+			for ($i=0; $i<$lists_entries["count"]; $i++)
+			{
+				$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
+			}
+				
+			if (count($l_tmp))
+				natcasesort($l_tmp);
+				
+			$i = 0;
+			$lists = array();
+			
+			$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
+			if (count($l_tmp))
+			{
+				foreach ($l_tmp as $mail => $cn)
+				{
+					$options .= "<option value=$mail>$cn</option>";
+				}
+				unset($l_tmp);
+			}
+		}
+		
+		/* users */
+		$users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search);
+		for ($i=0; $i<$users_entries["count"]; $i++)
+		{
+			$u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0];
+		}
+			
+		if (count($u_tmp))
+			natcasesort($u_tmp);
+			
+		$i = 0;
+		$users = array();
+		
+		$options .= '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
+			
+		if (count($u_tmp))
+		{
+			foreach ($u_tmp as $mail => $cn)
+			{
+				$options .= "<option value=$mail class='line-above'>$cn</option>";
+			}
+			unset($u_tmp);
+		}
+		
+		ldap_close($ldap_conn_following_ref);
+   		return $options;
+	}
+
 }
 ?>
