Index: trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 5934)
+++ trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 6553)
@@ -464,6 +464,176 @@
 			$sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master);
 			return $sectors_info;
-		}
-		
+		} 
+ 		                 
+                /*  
+                        Funciona de maneira similar ao get_sectors_list, porém retorna a propria OU do contexto 
+                        e monta o array de retorno de forma diferente, necessário para algumas mudanças implementadas 
+                        no método admin.uisectors.list_sectors. 
+                */ 
+                function get_organizations2($contexts, $selected='', $referral=false, $show_invisible_ou=true) {                 
+ 
+                        $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","diskQuota","usersQuota","actualDiskQuota"); 
+                        $filter = "(ou=*)"; 
+                        foreach ($contexts as $context) { 
+                                $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çãoo. 
+                                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[implode ( "#", $array_dn_reverse )] = $info[$i]; 
+                                } 
+                        } 
+                        // Ordenação por chave 
+                        ksort($inverted_dn);                     
+                         
+                        // Construção do select 
+                        $level = 0; 
+                        $options = array(); 
+                        foreach ($inverted_dn as $dn=>$info_ou) 
+                        { 
+                $display = ''; 
+                                $info_retorno = array(); 
+                $array_dn_reverse = explode ( "#", $dn ); 
+                $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 ) ); 
+                                 
+                                $info_retorno['display'] = $display; 
+                                $info_retorno['dn'] = $info_ou['dn']; 
+                                $info_retorno['diskquota'] = $info_ou['diskquota'][0]; 
+                                $info_retorno['usersquota'] = $info_ou['usersquota'][0]; 
+//                              $info_retorno['actualdiskquota'] = round($this->get_actual_disk_usage($info_ou['dn']),2);//$info_ou['actualdiskquota'][0]; 
+//                              $info_retorno['actualnumusers'] = $this->get_num_users($info_ou['dn']); 
+                                 
+                                array_push($options,$info_retorno); 
+                                 
+                } 
+                        return $options; 
+                }        
+                 
+                function get_info($context, $referral = 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); 
+                         
+                        $filter="(objectClass=organizationalUnit)"; 
+                        $search=ldap_search($ldap_conn, $context, $filter); 
+                        $result = ldap_get_entries($ldap_conn, $search); 
+                        return $result; 
+                                 
+                } 
+ 
+                function get_num_users($context,$selected='', $referral=false, $show_invisible_ou=true) { 
+                        $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 = "(objectClass=inetOrgPerson)"; 
+                        $search=ldap_search($ldap_conn, $context, $filter, $justthese); 
+                 
+                $retorno = ldap_count_entries($ldap_conn, $search); 
+                        ldap_close($ldap_conn); 
+                         
+                        return $retorno; 
+                } 
+                 
+                //Checa se existe quota para mais um usuï¿œrio no setor... se existir retorna true, senï¿œo false.               
+                function existe_quota_usuario($setor) { 
+                        $num_users = $this->get_num_users($setor['dn']); 
+                        //return $num_users . " --- " . $setor['usersquota'][0] 
+                        if(($num_users>=$setor['usersquota'][0]) && ($setor['usersquota'][0]!=-1)) { 
+                                return false; 
+                        } 
+                        return true; 
+                } 
+                 
+                //Checa se existe quota em disco para mais um usuï¿œrio no setor... se existir retorna true, senï¿œo false. 
+                function existe_quota_disco($setor,$quota_novo_usuario) { 
+                        settype($quota_novo_usuario,"float");            
+                        $quota_novo_usuario /= 1024; //A quota vï¿œm da interface em megabytes, deve se tornar gigabyte. 
+ 
+                        $nova_quota = $this->get_actual_disk_usage($setor['dn']) + $quota_novo_usuario; 
+                        if(( $nova_quota >= $setor['diskquota'][0] ) && ($setor['diskquota'][0] != -1)) { 
+                                return false; 
+                        } 
+                        return true; 
+                } 
+                 
+                // Soma as quotas de todos os usuï¿œrios daquele contexto. 
+                function get_actual_disk_usage($context) { 
+                        $quota_usada=0; 
+                        $contexts = array($context); 
+                        $usuarios = $this->get_list('accounts', '', $contexts); 
+ 
+                        $imap_functions = new imap_functions(); 
+                        foreach($usuarios as $usuario) { 
+                                $temp = $imap_functions->get_user_info($usuario['account_lid']); 
+                                if($temp['mailquota'] != -1) //Usuï¿œrio sem cota nï¿œo conta... 
+                                        $quota_usada += ($temp['mailquota'] / 1024); 
+                        } 
+                        return $quota_usada; 
+                } 
+
+
 		function get_sectors($selected='', $referral=false, $show_invisible_ou=true)
 		{
