Index: trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 13)
+++ trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 16)
@@ -200,5 +200,5 @@
 
 			// Pega combo das organizações e seleciona, caso seja um post, o setor que o usuario selecionou.
-			$sectors = $this->functions->get_organizations($manager_context);
+			$sectors = $this->functions->get_organizations2($manager_context);
 
 			// Chama funcao para criar lista de aplicativos disponiveis.
@@ -361,5 +361,5 @@
 							
     		// ORGANIZATIONS
-    		$orgs = $this->functions->get_organizations($manager_context, $user_info['context']);
+    		$orgs = $this->functions->get_organizations2($manager_context, $user_info['context']);
 
 			// GROUPS.
Index: trunk/expressoAdmin1_2/inc/class.uigroups.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uigroups.inc.php	(revision 2)
+++ trunk/expressoAdmin1_2/inc/class.uigroups.inc.php	(revision 16)
@@ -188,6 +188,6 @@
 
 			// Pega combo das organizações e seleciona um dos setores em caso de um erro na validaçao dos dados.
-			$combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
-			$combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
+			$combo_manager_org = $this->functions->get_organizations2($manager_context, trim(strtolower($group_info['context'])));
+			$combo_all_orgs = $this->functions->get_organizations2($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
 			
 			// Chama funcao para criar lista de aplicativos disponiveis.
@@ -250,6 +250,6 @@
 
 			// Pega combo das organizações e seleciona a org do grupo.
-			$combo_manager_org = $this->functions->get_organizations($manager_context, trim(strtolower($group_info['context'])));
-			$combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
+			$combo_manager_org = $this->functions->get_organizations2($manager_context, trim(strtolower($group_info['context'])));
+			$combo_all_orgs = $this->functions->get_organizations2($GLOBALS['phpgw_info']['server']['ldap_context'], trim(strtolower($group_info['context'])));
 
 			// Usuarios do grupo.
Index: trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 9)
+++ trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 16)
@@ -500,5 +500,5 @@
 						$ldap_mod_replace['loginShell']		= '/bin/bash';
 						$ldap_add['sambaSID']				= $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['uidnumber'])+1000);
-						$ldap_add['sambaPrimaryGroupSID']	= $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['gidNumber'])+1001);
+						$ldap_add['sambaPrimaryGroupSID']	= $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['gidnumber'])+1001);
 						$ldap_add['sambaAcctFlags']			= $new_values['sambaacctflags'];
 						$ldap_add['sambaLogonScript']		= $new_values['sambalogonscript'];
Index: trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 11)
+++ trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 16)
@@ -526,5 +526,5 @@
 		$justthese = array("gidnumber","cn");
 		$filter="(&(phpgwAccountType=g)(memberuid=".$result['uid']."))";
-		$search = ldap_search($this->ldap, $context, $filter, $justthese);
+		$search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
     	ldap_sort($this->ldap, $search, "cn");
     	$entries = ldap_get_entries($this->ldap, $search);
Index: trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 13)
+++ trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 16)
@@ -341,4 +341,79 @@
 		}
 		
+		function get_organizations2($context, $selected='')
+		{
+			$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);
+			ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
+			ldap_bind($ldap_conn,$dn,$passwd);
+			
+			$justthese = array("dn");
+			$search=ldap_search($ldap_conn, $context, "ou=*", $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 );
+
+				array_pop ( $array_dn_reverse );
+
+				$inverted_dn[$dn] = implode ( ".", $array_dn_reverse );
+			}
+
+			// Ordenação
+			natcasesort($inverted_dn);
+			
+			// Construção do select
+			$level = 0;
+			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 ) - 4;
+
+                if ($level == 0)
+                        $display .= '+';
+                else {
+                        for ($i=0; $i<$level; $i++)
+                                $display .= '---';
+                }
+
+                reset ( $array_dn );
+                $display .= ' ' . (current ( $array_dn ) );
+				
+				$dn = trim(strtolower($dn));
+				if ( $dn == $selected )
+					$select = ' selected';
+				else
+					$select = '';
+                $options .= "<option value='$dn'$select>$display</option>";
+        	}
+
+			// Cria a primeira entrada na combo 
+			$first_sector_ufn = ldap_dn2ufn($context);
+			$first_sector_string = split(",", $first_sector_ufn);
+			$options = "<option value='$context'>" . strtoupper($first_sector_string[0]) . "</option>" . $options;
+
+    	    return $options;
+		}
+		
 		function get_sectors($context, $selected='')
 		{
