Index: trunk/expressoAdmin1_2/inc/class.uigroups.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uigroups.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.uigroups.inc.php	(revision 46)
@@ -225,8 +225,13 @@
 				'type'						=> 'create_group',
 				'ldap_context'				=> $GLOBALS['phpgw_info']['server']['ldap_context'],
+				'ufn_ldap_context'			=> ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']),
 				'lang_back'					=> lang('Back'),
 				'lang_save'					=> lang('save'),
 				'lang_org'					=> lang('Organizations'),
 				'lang_group_name'			=> lang('group name'),
+				'lang_description'			=> lang('Description'),
+				'lang_email'				=> lang('E-mail'),
+				'concatenateDomain'			=> $this->current_config['expressoAdmin_concatenateDomain'],
+				'defaultDomain'				=> $this->current_config['expressoAdmin_defaultDomain'],
 				'lang_group_users'			=> lang('Group users'),
 				'lang_applications'			=> lang('Applications'),
@@ -239,4 +244,5 @@
 				'disabled_samba'			=> 'disabled',
 				'display_samba_options'		=> $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : '"display:none"',
+				'disable_email_groups'		=> $this->functions->check_acl($account_lid,'edit_email_groups') ? '' : 'disabled',
 				'sambadomainname_options'	=> $sambadomainname_options,
 				'back_url'					=> $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uigroups.list_groups'),
@@ -338,4 +344,6 @@
 				'lang_org'					=> lang('Organizations'),
 				'lang_group_name'			=> lang('group name'),
+				'lang_description'			=> lang('Description'),
+				'lang_email'				=> lang('E-mail'),
 				'lang_group_users'			=> lang('Group users'),
 				'lang_applications'			=> lang('Applications'),
@@ -347,8 +355,10 @@
 				'cn'						=> $group_info['cn'],
 				'user_count'				=> $user_count,
+				'email'						=> $group_info['email'],
 				'description'				=> $group_info['description'],
 				'apps'						=> $apps,
 				'use_attrs_samba_checked'	=> $group_info['sambaGroup'] ? 'CHECKED' : '',
 				'disabled_samba'			=> $group_info['sambaGroup'] ? '' : 'disabled',
+				'disable_email_groups'		=> $this->functions->check_acl($account_lid,'edit_email_groups') ? '' : 'disabled',
 				'sambadomainname_options'	=> $sambadomainname_options,
 				'phpgwaccountvisible_checked'	=> $group_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
Index: trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 46)
@@ -429,5 +429,5 @@
 						if ($alert_warning == '')
 							$alert_warning = "O expressoAdmin corrigiu as seguintes inconsistências:\\n";
-						$alert_warning .= "Incluido atributo memberUid do usuário no grupo $cn - $gidnumber.\\n";
+						$alert_warning .= "Incluido atributo memberUid do usuário no grupo:\\n$cn - gidnumber: $gidnumber.";
 					}
 					else
Index: trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 46)
@@ -81,5 +81,14 @@
 				$user_info['uidnumber']					= $id;
 				$user_info['userPassword']				= '{md5}' . base64_encode(pack("H*",md5($params['password1'])));
-			
+				
+				// Gerenciar senhas RFC2617
+				if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true')
+				{
+					$realm		= $this->current_config['expressoAdmin_realm_userPasswordRFC2617'];
+					$uid		= $user_info['uid'];
+					$password	= $params['password1'];
+					$user_info['userPasswordRFC2617'] = $realm . ':      ' . md5("$uid:$realm:$password");
+				}
+				
 				if ($params['phpgwaccountstatus'] == '1')
 					$user_info['phpgwAccountStatus'] = 'A';
@@ -315,4 +324,5 @@
 				{
 					$ldap_mod_replace['userPassword'] = '{md5}' . base64_encode(pack("H*",md5($new_values['password1'])));
+					
 					// Suporte ao SAMBA
 					if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on'))
@@ -321,4 +331,19 @@
 						$ldap_mod_replace['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N '.$new_values['password1']);
 					}
+					
+					// Gerenciar senhas RFC2617
+					if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true')
+					{
+						$realm		= $this->current_config['expressoAdmin_realm_userPasswordRFC2617'];
+						$uid		= $new_values['uid'];
+						$password	= $new_values['password1'];
+						$passUserRFC2617 = $realm . ':      ' . md5("$uid:$realm:$password");
+						
+						if ($old_values['userPasswordRFC2617'] != '')
+							$ldap_mod_replace['userPasswordRFC2617'] = $passUserRFC2617;
+						else
+							$ldap_add['userPasswordRFC2617'] = $passUserRFC2617;
+					}
+					
 					$this->db_functions->write_log("alterado password do usuario",'',$dn,'','');
 				}
Index: trunk/expressoAdmin1_2/inc/class.bomanagers.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.bomanagers.inc.php	(revision 32)
+++ trunk/expressoAdmin1_2/inc/class.bomanagers.inc.php	(revision 46)
@@ -38,4 +38,5 @@
 			'edit_groups'				=> $_POST['edit_groups'],
 			'delete_groups'				=> $_POST['delete_groups'],
+			'edit_email_groups'			=> $_POST['edit_email_groups'],
 			'change_users_password'		=> $_POST['change_users_password'],
 			'change_users_quote'		=> $_POST['change_users_quote'],
@@ -60,5 +61,5 @@
 			$acl = 0;
 			$acl = $acl + $manager['add_users'] + $manager['edit_users'] + $manager['delete_users'] + $manager['rename_users'] + $manager['view_users'];
-			$acl = $acl + $manager['add_groups'] + $manager['edit_groups'] + $manager['delete_groups'];
+			$acl = $acl + $manager['add_groups'] + $manager['edit_groups'] + $manager['delete_groups'] + $manager['edit_email_groups'];
 			$acl = $acl + $manager['change_users_password'] + $manager['change_users_quote'] + $manager['set_user_default_password'];
 			$acl = $acl + $manager['edit_sambausers_attributes'] + $manager['edit_sambadomains'];
@@ -108,5 +109,6 @@
 			'add_groups'				=> $_POST['add_groups'],
 			'edit_groups'				=> $_POST['edit_groups'],
-			'delete_groups'				=> $_POST['delete_groups'],			
+			'delete_groups'				=> $_POST['delete_groups'],
+			'edit_email_groups'			=> $_POST['edit_email_groups'],			
 			'change_users_password'		=> $_POST['change_users_password'],
 			'change_users_quote'		=> $_POST['change_users_quote'],
@@ -131,5 +133,5 @@
 			$acl = 0;
 			$acl = $acl + $manager['add_users'] + $manager['edit_users'] + $manager['delete_users'] + $manager['rename_users'] + $manager['view_users'];
-			$acl = $acl + $manager['add_groups'] + $manager['edit_groups'] + $manager['delete_groups'];
+			$acl = $acl + $manager['add_groups'] + $manager['edit_groups'] + $manager['delete_groups'] + $manager['edit_email_groups'];
 			$acl = $acl + $manager['change_users_password'] + $manager['change_users_quote'] + $manager['set_user_default_password'];
 			$acl = $acl + $manager['edit_sambausers_attributes'] + $manager['edit_sambadomains'];
Index: trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 2)
+++ trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 46)
@@ -28,5 +28,5 @@
 			return $result;
 		}
-		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Enviados"))
+		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Sent"))
 		{
 			$error = imap_errors();
@@ -35,5 +35,5 @@
 			return $result;
 		}
-		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Rascunhos"))
+		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Drafts"))
 		{
 			$error = imap_errors();
@@ -42,5 +42,5 @@
 			return $result;
 		}
-		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Lixeira"))
+		if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . "Trash"))
 		{
 			$error = imap_errors();
Index: trunk/expressoAdmin1_2/inc/class.uisectors.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 46)
@@ -60,6 +60,7 @@
 			$p->set_block('sectors','row_empty','row_empty');
 			
+			//$sectors_info = $this->functions->get_sectors_list($manager_context);
+			//_debug_array($sectors_info);
 			$sectors_info = $this->functions->get_sectors_list($manager_context);
-			//_debug_array($sectors_info);
 			
 			$var = Array(
@@ -94,22 +95,12 @@
 				}
 
-				foreach($sectors_info as $sector)
+				foreach($sectors_info as $context=>$sector)
 				{
 					$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
 					
-					if ($sector->sector_level == 1)
-					{
-						$sector->sector_name = '+'.$sector->sector_name;
-					}
-					else
-					{
-						for ($i=1; $i < $sector->sector_level; $i++)
-							$sector->sector_name = '----'.$sector->sector_name;
-					}
-					
 					$var = Array(
 						'tr_color'    => $tr_color,
-						'sector_name'  => (!$sector->sector_name?'&nbsp;':$sector->sector_name),
-						'add_link' => $this->row_action('add','sector',$sector->sector_context)
+						'sector_name'  => $sector,
+						'add_link' => $this->row_action('add','sector',$context)
 					);
 					$p->set_var($var);
@@ -117,5 +108,5 @@
 					if ($can_edit)
 					{
-						$p->set_var('edit_link',$this->row_action('edit','sector',$sector->sector_context));
+						$p->set_var('edit_link',$this->row_action('edit','sector',$context));
 					}
 					else
@@ -126,5 +117,5 @@
 					if ($can_delete)
 					{
-						$p->set_var('delete_link',$this->row_action('delete','sector',$sector->sector_context));
+						$p->set_var('delete_link',$this->row_action('delete','sector',$context));
 					}
 					else
Index: trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php	(revision 32)
+++ trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php	(revision 46)
@@ -210,4 +210,5 @@
 				'lang_edit_groups'				=> lang('Edit groups'),
 				'lang_delete_groups'			=> lang('Delete groups'),
+				'lang_edit_email_attribute_from_the_groups'	=> 	lang('Edit email attribute from the groups'),
 				'lang_change_user_password'		=> lang('Change users password'),
 				'lang_change_users_quote'		=> lang('Change users quote'),
@@ -337,4 +338,5 @@
 				$_POST['edit_groups']			= $acl['edit_groups'];
 				$_POST['delete_groups']			= $acl['delete_groups'];
+				$_POST['edit_email_groups']		= $acl['edit_email_groups'];
 				$_POST['change_users_password']	= $acl['change_users_password'];
 				$_POST['change_users_quote']	= $acl['change_users_quote'];
@@ -453,5 +455,6 @@
 				'lang_add_groups'				=> lang('Add groups'),
 				'lang_edit_groups'				=> lang('Edit groups'),
-				'lang_delete_groups'			=> lang('Delete groups'),				
+				'lang_delete_groups'			=> lang('Delete groups'),
+				'lang_edit_email_attribute_from_the_groups'	=> 	lang('Edit email attribute from the groups'),
 				'lang_change_user_password'		=> lang('Change users password'),
 				'lang_change_users_quote'		=> lang('Change users quote'),
@@ -483,4 +486,5 @@
 				'edit_groups'					=> $_POST['edit_groups'] != '' ? 'checked' : '',
 				'delete_groups'			 		=> $_POST['delete_groups'] != '' ? 'checked' : '',
+				'edit_email_groups'			 	=> $_POST['edit_email_groups'] != '' ? 'checked' : '',
 				'change_users_password'			=> $_POST['change_users_password'] != '' ? 'checked' : '',
 				'change_users_quote'			=> $_POST['change_users_quote'] != '' ? 'checked' : '',
@@ -561,5 +565,5 @@
 				if ($num_registros != 0)
 				{
-					$_POST['error_messages'] = lang('Este Gerente neste contexto já exite !!');
+					$_POST['error_messages'] = lang('Este Gerente, neste contexto já exite !!');
 					$this->add_managers();
 					return;
Index: trunk/expressoAdmin1_2/inc/class.group.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 46)
@@ -75,4 +75,8 @@
 			$group_info['userPassword']			= '';
 			
+			// E-mail for groups
+			if ($params['email'] != '')
+				$group_info['mail'] = $params['email'];
+			
 			if (count($params['members']))
 			{
@@ -93,5 +97,5 @@
 			{
 				$group_info['objectClass'][]  = 'sambaGroupMapping';
-				$group_info['sambaSID']		  = $params['sambadomain'] . '-' . (($id * 2) + 1001);
+				$group_info['sambaSID']		  = $params['sambasid'] . '-' . (($id * 2) + 1001);
 				$group_info['sambaGroupType'] = '2';
 			}
@@ -166,10 +170,11 @@
 			}
 			
+			$ldap_mod_replace = array();
 			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 			// REPLACE SAMBASID OF SAMBA
-			if ( ($this->current_config['expressoAdmin_samba_support'] == 'true') && ($diff['sambadomain']) ) 
-			{
-				$ldap_mod_replace['sambaSID'] = $new_values['sambadomain'] . '-' . ((2 * $new_values['uidnumber'])+1001);
-				$this->db_functions->write_log("Alterado dominio samba do grupo $dn para " . $new_values['sambadomain'],'',$dn,'','');
+			if ( ($this->current_config['expressoAdmin_samba_support'] == 'true') && ($diff['sambasid']) && ($old_values['sambasid']))
+			{
+				$ldap_mod_replace['sambasid'] = $new_values['sambasid'] . '-' . ((2 * $new_values['gidnumber'])+1001);
+				$this->db_functions->write_log("Alterado dominio samba do grupo $dn para " . $new_values['sambasid'],'',$dn,'','');
 			}
 			
@@ -183,5 +188,14 @@
 
 			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-			// CALL LDAP_REPLACE FUNCTION			
+			// REPLACE E-Mail
+			if ((($old_values['email']) && ($diff['email'])) && 
+				$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'edit_email_groups'))
+			{
+				$ldap_mod_replace['mail'] = $new_values['email'];
+				$this->db_functions->write_log("Modificado E-Mail do grupo $dn",'',$dn,'','');
+			}
+
+			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+			// CALL LDAP_REPLACE FUNCTION
 			if (count($ldap_mod_replace))
 			{
@@ -226,5 +240,5 @@
 					$ldap_add['objectClass'][] 		= 'sambaGroupMapping';
 					$ldap_add['sambagrouptype']		= '2';
-					$ldap_add['sambasid']			= $new_values['sambadomain'] . '-' . ((2 * $new_values['gidnumber'])+1001);
+					$ldap_add['sambasid']			= $new_values['sambasid'] . '-' . ((2 * $new_values['gidnumber'])+1001);
 					
 					$result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
@@ -241,7 +255,20 @@
 			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 			// ADD ATTRIBUTES
+			$ldap_add = array();
 			if (($new_values['phpgwaccountvisible'] == 'on') && ($old_values['phpgwaccountvisible'] != '-1'))
 			{
 				$ldap_add['phpgwaccountvisible'] = '-1';
+				$this->db_functions->write_log("Adicionado atributo phpgwaccountvisible ao grupo $dn",'','','','');
+			}
+			if ((($new_values['email']) && (!$old_values['email'])) &&
+				$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'edit_email_groups'))
+			{
+				$ldap_add['mail'] = $new_values['email'];
+				$this->db_functions->write_log("Adicionado atributo mail ao grupo $dn",'','','','');
+			}
+			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+			// CALL LDAP_ADD FUNCTION			
+			if (count($ldap_add))
+			{
 				$result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
 				if (!$result['status'])
@@ -250,12 +277,24 @@
 					$return['msg'] .= $result['msg'];
 				}
-				else
-					$this->db_functions->write_log("Adicionado atributo phpgwaccountvisible ao grupo $dn",'','','','');
-			}
-			
+			}
+						
+			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 			// REMOVE ATTRIBUTES
+			$ldap_remove = array();
 			if (($new_values['phpgwaccountvisible'] != 'on') && ($old_values['phpgwaccountvisible'] == '-1'))
 			{
 				$ldap_remove['phpgwaccountvisible'] = array();
+				$this->db_functions->write_log("Removido atributo phpgwaccountvisible do grupo $dn",'','','','');
+			}
+			if (((!$new_values['email']) && ($old_values['email'])) &&
+				$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'edit_email_groups'))
+			{
+				$ldap_remove['mail'] = array();
+				$this->db_functions->write_log("Removido atributo mail do grupo $dn",'','','','');
+			}
+			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+			// CALL LDAP_REMOVED FUNCTION			
+			if (count($ldap_remove))
+			{
 				$result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove);
 				if (!$result['status'])
@@ -264,6 +303,4 @@
 					$return['msg'] .= $result['msg'];
 				}
-				else
-					$this->db_functions->write_log("Removido atributo phpgwaccountvisible do grupo $dn",'','','','');
 			}
 
Index: trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 33)
+++ trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 46)
@@ -299,5 +299,5 @@
 		
 		$justthese = array("cn", "uidNumber");
-		$users_filter="(&(phpgwAccountType=u)(!(phpgwAccountVisible=-1)))";
+		$users_filter="(phpgwAccountType=u)";
 		$lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))";
 		
@@ -637,4 +637,5 @@
 		$result['mailforwardingaddress']= $entry[0]['mailforwardingaddress'][0];
 		$result['deliverymode']			= $entry[0]['deliverymode'][0];
+		$result['userPasswordRFC2617']	= $entry[0]['userpasswordrfc2617'][0];
 
 		//Photo
@@ -705,4 +706,5 @@
 		$result['gidnumber']			= $entry[0]['gidnumber'][0];
 		$result['phpgwaccountvisible']	= $entry[0]['phpgwaccountvisible'][0];
+		$result['email']				= $entry[0]['mail'][0];
 		
 		//MemberUid
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;
 		}
 		
