Index: trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 46)
@@ -103,4 +103,8 @@
 						return true;
 					break;
+				case edit_email_groups:
+					if ($array_acl[edit_email_groups])
+						return true;
+					break;
 				
 				case list_maillists:
@@ -175,21 +179,12 @@
 		function read_acl($account_lid)
 		{ 
-			/*
-			$query = "SELECT * FROM phpgw_expressoadmin WHERE manager_lid = '" . $account_lid . "'"; 
-			$GLOBALS['phpgw']->db->query($query);
-			while($GLOBALS['phpgw']->db->next_record())
-			{
-				$result[] = $GLOBALS['phpgw']->db->row();
-			}
-			*/
 			$result = $this->db_functions->read_acl($account_lid);
 			$context_array = ldap_explode_dn($result[0]['context'], 1);
-			$tmp = array_shift($context_array);
-			$result[0]['context_display'] = implode(".", $context_array);
+			$result[0]['context_display'] = ldap_dn2ufn ( $result[0]['context'] );
 			return $result;
 		}
 		
 		// Make a array read humam
-		// Last acl:	33.554.432
+		// Last acl:	33.554.432, 67.108.864
 		function make_array_acl($acl)
 		{
@@ -202,4 +197,5 @@
 			$array_acl['edit_groups'] = $acl & 32;
 			$array_acl['delete_groups'] = $acl & 64;
+			$array_acl['edit_email_groups'] = $acl & 67108864;
 			$array_acl['change_users_password'] = $acl & 128;
 			$array_acl['change_users_quote'] = $acl & 262144;
@@ -234,5 +230,5 @@
 				
 				$justthese = array("uidnumber", "uid", "cn", "mail");
-				$filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)))";
+				$filter="(&(phpgwAccountType=u)(|(uid~=".$query.")(sn~=".$query.")(cn~=".$query.")(givenName~=".$query.")(mail~=$query)(mailAlternateAddress~=$query)))";
 				$search=ldap_search($ldap_conn, $context, $filter, $justthese);
 				ldap_sort($ldap_conn, $search, "uid");
@@ -470,4 +466,5 @@
 		
 		// Get list of all levels, this function is used for sectors module.
+		/*
 		function get_sectors_list($context)
 		{
@@ -477,10 +474,10 @@
 	
 			if ($connection)
-			{
+			{				
 				$bind=ldap_bind($connection);
 				$filter="ou=*";
 				$justthese = array("ou");
 				$search=ldap_list($connection, $context, $filter, $justthese);
-				ldap_sort($connection ,$search, "ou");
+				ldap_sort($connection, $search, "ou");
 				$info = ldap_get_entries($connection, $search);
 				for ($i=0; $i<$info["count"]; $i++)
@@ -496,4 +493,80 @@
 			$this->level--;
 			return $this->sectors_list;
+		}
+		*/
+		
+		// Get list of all levels, this function is used for sectors module.
+		function get_sectors_list($context, $selected='', $referral=false ,$show_invisible_ou=false)
+		{
+			$dn			= $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
+			$passwd		= $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
+			$ldap_conn	= ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
+			
+			ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
+			
+			if ($referral)
+				ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
+			else
+				ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
+			
+			ldap_bind($ldap_conn,$dn,$passwd);
+			
+			$justthese = array("dn");
+			$filter = "(ou=*)";
+			$search=ldap_search($ldap_conn, $context, $filter, $justthese);
+        	
+        	ldap_sort($ldap_conn, $search, "ou");
+        	$info = ldap_get_entries($ldap_conn, $search);
+			ldap_close($ldap_conn);
+
+			// Retiro o count do array info e inverto o array para ordenação.
+	        for ($i=0; $i<$info["count"]; $i++)
+    	    {
+				$dn = $info[$i]["dn"];
+				
+				// Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou. 
+				if (strtolower($dn) == $context)
+					continue;
+
+				$array_dn = ldap_explode_dn ( $dn, 1 );
+
+                $array_dn_reverse  = array_reverse ( $array_dn, true );
+
+				// Retirar o indice count do array.
+				array_pop ( $array_dn_reverse );
+
+				$inverted_dn[$dn] = implode ( "#", $array_dn_reverse );
+			}
+
+			// Ordenação
+			natcasesort($inverted_dn);
+			
+			// Construção do select
+			$level = 0;
+			$options = array();
+			foreach ($inverted_dn as $dn=>$invert_ufn)
+			{
+                $display = '';
+
+                $array_dn_reverse = explode ( "#", $invert_ufn );
+                $array_dn  = array_reverse ( $array_dn_reverse, true );
+
+                $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1);
+
+                if ($level == 0)
+                        $display .= '+';
+                else 
+                {
+					for ($i=0; $i<$level; $i++)
+						$display .= '---';
+                }
+
+                reset ( $array_dn );
+                $display .= ' ' . (current ( $array_dn ) );
+				
+				$dn = trim(strtolower($dn));
+				$options[$dn] = $display;
+        	}
+    	    return $options;
 		}
 		
