Index: /trunk/expressoAdmin1_2/controller.php
===================================================================
--- /trunk/expressoAdmin1_2/controller.php	(revision 2)
+++ /trunk/expressoAdmin1_2/controller.php	(revision 317)
@@ -21,12 +21,18 @@
 	else
 		return $_SESSION['response'] = 'false';
-	
+		
 	// Load dinamically class file.
 	if($app == '$this')
 		$filename = 'inc/class.'.$class.'.inc.php';
+	else if( strpos($app, '$this/') !== false)
+	{
+		$filename = str_replace('$this/','',$app) . '.php';
+		include_once($filename);
+		exit;
+	}
 	else
 		$filename = '../'.$app.'/inc/class.'.$class.'.inc.php';
 		
-	include_once($filename);	
+	include_once($filename);
 	
 	// Create new Object  (class loaded).	
Index: /trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 309)
+++ /trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 317)
@@ -62,5 +62,4 @@
 				$context_display .= '<br>'.$tmp_context;
 			}
-			
 			// Verifica se o administrador tem acesso.
 			if (!$this->functions->check_acl($account_lid,'list_users'))
@@ -136,5 +135,6 @@
 					($this->functions->check_acl($account_lid,'edit_sambausers_attributes')) ||  
 					($this->functions->check_acl($account_lid,'change_users_quote')) ||
-					($this->functions->check_acl($account_lid,'manipulate_corporative_information'))
+					($this->functions->check_acl($account_lid,'manipulate_corporative_information')) ||
+					($this->functions->check_acl($account_lid,'edit_users_phonenumber'))
 					) 
 					$can_edit = True;
@@ -369,5 +369,6 @@
 				(!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) &&
 				(!$this->functions->check_acl($manager_account_lid,'view_users')) &&
-				(!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information'))
+				(!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information')) &&
+				(!$this->functions->check_acl($manager_account_lid,'edit_users_phonenumber'))
 				)
 			{
@@ -385,4 +386,10 @@
 				$disabled = 'disabled';
 				$disabled_samba = '';
+			}
+			// SOMENTE ALTERAÇÃO DE TELEFONE
+			if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && ($this->functions->check_acl($manager_account_lid,'edit_users_phonenumber')))
+			{
+				$disabled = 'disabled';
+				$disabled_phonenumber = '';
 			}
 			// TOTAIS MENOS O SAMBA
Index: /trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 309)
+++ /trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 317)
@@ -132,7 +132,9 @@
 				if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($params['use_attrs_samba'] == 'on'))
 				{
+					
+					// Qualquer um que crie um usuário, deve ter permissão para adicionar a senha samba.
 					// Verifica o acesso do gerente aos atributos samba
-					if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes'))
-					{
+					//if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes'))
+					//{
 						//Verifica se o binario para criar as senhas do samba exite.
 						if (!is_file('/home/expressolivre/mkntpwd'))
@@ -162,5 +164,5 @@
 							$user_info['sambaPwdMustChange']	= '2147483647';
 						}
-					}
+					//}
 				}
 				
@@ -292,5 +294,6 @@
 				(!$this->functions->check_acl($manager_account_lid,'change_users_password')) &&
 				(!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) &&
-				(!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information'))
+				(!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information')) &&
+				(!$this->functions->check_acl($manager_account_lid,'edit_users_phonenumber'))
 				)
 			{
@@ -340,4 +343,5 @@
 					$ldap_mod_replace['mail'] = $new_values['mail'];
 					$this->ldap_functions->replace_user2maillists($new_values['mail'], $old_values['mail']);
+					$this->ldap_functions->replace_mail_from_institutional_account($new_values['mail'], $old_values['mail']);
 					$this->db_functions->write_log("alterado mail do usuario",'',$dn,'','');
 				}
@@ -354,9 +358,4 @@
 				}
 				*/
-				if (($diff['telephonenumber']) && ($old_values['telephonenumber'] != ''))
-				{
-					$ldap_mod_replace['telephonenumber'] = $new_values['telephonenumber'];
-					$this->db_functions->write_log("alterado telephonenumber do usuario",'',$dn,'','');
-				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 				// Passwd Expired - Com atributo
@@ -397,4 +396,14 @@
 					
 					$this->db_functions->write_log("alterado password do usuario",'',$dn,'','');
+				}
+			}
+
+			if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || 
+			     ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_phonenumber')) )
+			{
+				if (($diff['telephonenumber']) && ($old_values['telephonenumber'] != ''))
+				{
+					$ldap_mod_replace['telephonenumber'] = $new_values['telephonenumber'];
+					$this->db_functions->write_log("alterado telephonenumber do usuario",'',$dn,'','');
 				}
 			}
Index: /trunk/expressoAdmin1_2/inc/class.uidomains.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.uidomains.inc.php	(revision 309)
+++ /trunk/expressoAdmin1_2/inc/class.uidomains.inc.php	(revision 317)
@@ -178,11 +178,14 @@
 				return;
 			}
-			
-			$return = $this->ldap_functions->add_sambadomain(strtoupper($_POST['sambadomainname']), $_POST['sambasid'], $_POST['context']);
-			if (!$return['status'])
-			{
-				$_POST['error_messages'] = $return['msg'];
-				ExecMethod('expressoAdmin1_2.uidomains.add');
-				return;
+
+			if (!$this->ldap_functions->exist_domain_name_sid($_POST['sambadomainname'], $_POST['sambasid']))
+			{
+				$return = $this->ldap_functions->add_sambadomain(strtoupper($_POST['sambadomainname']), $_POST['sambasid'], $_POST['context']);
+				if (!$return['status'])
+				{
+					$_POST['error_messages'] = $return['msg'];
+					ExecMethod('expressoAdmin1_2.uidomains.add');
+					return;
+				}
 			}
 			
Index: /trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php	(revision 309)
+++ /trunk/expressoAdmin1_2/inc/class.uimanagers.inc.php	(revision 317)
@@ -256,5 +256,4 @@
 				//Cria vetor da ACL
 				$manager_acl = $this->functions->make_array_acl($manager['acl']);
-
 				//Pesquisa no Banco e pega os valores dos apps.
 				$query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '" . $_GET['manager_lid'] . "' AND context = '" . $_GET['context'] . "'";
@@ -327,7 +326,7 @@
 				{
 					if ($first_time)
-						$p->set_var($atribute, $manager_acl[$atribute] != '' ? 'checked' : '');
+						$p->set_var($atribute, $manager_acl[$atribute] === '1' ? 'checked' : '');
 					else
-						$p->set_var($atribute, $_POST[$atribute] != '' ? 'checked' : ''); 
+						$p->set_var($atribute, $_POST[$atribute] === '1' ? 'checked' : ''); 
 				}
 				// Setar os langs do tpl.
Index: /trunk/expressoAdmin1_2/inc/class.group.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 86)
+++ /trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 317)
@@ -52,5 +52,5 @@
 			//Retira os uids duplicados se existir
 			$array_tmp = array();
-			$array_tmp = array_unique($params['members']);
+			$array_tmp = @array_unique($params['members']);
 			$params['members'] = $array_tmp;
 
@@ -67,8 +67,4 @@
 				$id = $next_id['id'];
 			}
-			// Pega ID do BD e incrementa de 1.
-			//$id = (($this->db_functions->get_next_id()) + 1);
-			// Incrementa o id no BD.
-			//$this->db_functions->increment_id($id,'groups');
 			
 			// Cria array para incluir no LDAP
@@ -90,5 +86,5 @@
 				$group_info['mail'] = $params['email'];
 			
-			if (count($params['members']))
+			if ( (count($params['members'])) && (is_array($params['members'])) )
 			{
 				foreach ($params['members'] as $index => $uidnumber)
@@ -122,5 +118,11 @@
 			{
 				$return['status'] = false;
-				$return['msg'] .= $result['msg'];
+				if ($result['error_number'] == '65')
+					$return['msg'] .= "Não foi possível criar este grupo pois os schemas do servidor LDAP estão desatualizados.\n" .
+										"O Administrador deve atualizar o diretório /etc/ldap/schema/ e re-inicializar o ldap.\n".
+										"Uma versão atualizada deste arquivo pode ser encontrada no site:\n" .
+										"www.expressolivre.org -> Downloads -> schema.tgz";
+				else
+					$return['msg'] .= $result['msg'];
 			}
 			
@@ -215,5 +217,11 @@
 				{
 					$return['status'] = false;
-					$return['msg'] .= $result['msg'];
+					if ($result['error_number'] == '65')
+						$return['msg'] .= "Não foi possível salvar alguns atributos deste grupo pois os schemas do servidor LDAP estão desatualizados.\n" .
+											"O Administrador deve atualizar o diretório /etc/ldap/schema/ e re-inicializar o ldap.\n".
+											"Uma versão atualizada deste arquivo pode ser encontrada no site:\n" .
+											"www.expressolivre.org -> Downloads -> schema.tgz";
+					else
+						$return['msg'] .= $result['msg'];
 				}
 			}			
@@ -283,8 +291,15 @@
 			{
 				$result = $this->ldap_functions->add_user_attributes($dn, $ldap_add);
+				
 				if (!$result['status'])
 				{
 					$return['status'] = false;
-					$return['msg'] .= $result['msg'];
+					if ($result['error_number'] == '65')
+						$return['msg'] .= "Não foi possível adicionar alguns atributos deste gruupo pois os schemas do servidor LDAP estão desatualizados.\n" .
+											"O Administrador deve atualizar o diretório /etc/ldap/schema/ e re-inicializar o ldap.\n".
+											"Uma versão atualizada deste arquivo pode ser encontrada no site:\n" .
+											"www.expressolivre.org -> Downloads -> schema.tgz";
+					else
+						$return['msg'] .= $result['msg'];
 				}
 			}
Index: /trunk/expressoAdmin1_2/inc/class.institutional_accounts.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.institutional_accounts.inc.php	(revision 317)
+++ /trunk/expressoAdmin1_2/inc/class.institutional_accounts.inc.php	(revision 317)
@@ -0,0 +1,141 @@
+<?php
+	/***********************************************************************************\
+	* Expresso Administração															*
+	* by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)  	*
+	* ----------------------------------------------------------------------------------*
+	*  This program is free software; you can redistribute it and/or modify it			*
+	*  under the terms of the GNU General Public License as published by the			*
+	*  Free Software Foundation; either version 2 of the License, or (at your			*
+	*  option) any later version.														*
+	\***********************************************************************************/
+
+	define('PHPGW_API_INC','../phpgwapi/inc');
+
+	class institutional_accounts
+	{
+		var $public_functions = array
+		(
+			'index' => True
+		);
+		
+		var $functions;
+
+		function institutional_accounts()
+		{			
+			if (function_exists('CreateObject'))
+			{
+				$this->functions = CreateObject('expressoAdmin1_2.functions');
+				
+				if(!@is_object($GLOBALS['phpgw']->js))
+				{
+					$GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
+				}
+				$GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao
+				$GLOBALS['phpgw']->js->validate_file('jscode','institutional_accounts','expressoAdmin1_2');
+				$GLOBALS['phpgw']->js->validate_file('modal','modal','expressoAdmin1_2');
+				
+				/*
+				Move this to expressoAdmin.index.
+				$_SESSION['phpgw_info']['expressoAdmin']['user']['preferences']['common']['lang'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
+				
+				$fn = './expressoAdmin1_2/setup/phpgw_'.$_SESSION['phpgw_info']['expressoAdmin']['user']['preferences']['common']['lang'].'.lang';
+				if (file_exists($fn)){
+					$fp = fopen($fn,'r');
+					while ($data = fgets($fp,16000)){
+						list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));
+						$_SESSION['phpgw_info']['expressoAdmin']['lang'][$message_id] =  $content;
+					}
+					fclose($fp);
+				}*/
+			}
+		}
+
+		function make_lang($ram_lang)
+		{
+			$a_lang = split("_", $ram_lang);
+			$a_lang_reverse  = array_reverse ( $a_lang, true );
+			array_pop ( $a_lang_reverse );
+			$a_lang  = array_reverse ( $a_lang_reverse, true );
+			$a_new_lang = implode ( " ", $a_lang );
+			return lang($a_new_lang);
+		}
+
+		function make_dinamic_lang($template_obj, $block)
+		{
+			$tpl_vars = $template_obj->get_undefined($block);
+			foreach ($tpl_vars as $atribute)
+			{
+				$lang = strstr($atribute, 'lang_');
+				if($lang !== false)
+				{
+					$template_obj->set_var($atribute, $this->make_lang($atribute));
+				}
+			}
+		}
+		
+		function index()
+		{
+			/* Begin:  Check manager access */
+			$account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
+			$acl = $this->functions->read_acl($account_lid);
+			$contexts = $acl['contexts'];
+			foreach ($acl['contexts_display'] as $index=>$tmp_context) {
+				$context_display .= '<br>'.$tmp_context;
+			}
+			
+			if (!$this->functions->check_acl($account_lid,'list_institutional_accounts')) {
+				$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
+			}
+			/* End: Check manager access */
+
+			unset($GLOBALS['phpgw_info']['flags']['noheader']);
+			unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
+			$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Institutional accounts');
+			$GLOBALS['phpgw']->common->phpgw_header();
+
+			$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
+
+			$p->set_file(
+						Array(
+								'institutional_accounts'		=> 'institutional_accounts.tpl',
+								'institutional_accounts_modal'	=>'institutional_accounts_modal.tpl'
+							)
+						);
+			$p->set_block('institutional_accounts','body');
+			
+			/* dinamic load lang */
+			$this->make_dinamic_lang($p, 'body');
+			$this->make_dinamic_lang($p, 'institutional_accounts_modal');
+
+
+			/* Begin: set modal */
+
+			$functions = CreateObject('expressoAdmin1_2.functions');
+			
+			//$organizations = $functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context']);
+			
+			foreach ($contexts as $index=>$context)
+				$combo_manager_org .= $this->functions->get_organizations($context);
+			$combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context']);
+			
+			$p->set_var('manager_organizations', $combo_manager_org);
+			$p->set_var('all_organizations', $combo_all_orgs);
+			
+			$modal_id = 'institutional_accounts_modal';
+			$p->set_var('modal_id', $modal_id);
+			$institutional_accounts_modal_tpl = $p->fp('out','institutional_accounts_modal');
+			/* End: set modal */
+			
+			$var = Array(
+				'th_bg'						=> $GLOBALS['phpgw_info']['theme']['th_bg'],
+				'back_url'					=> $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
+				'context_display'			=> $context_display,
+				'institutional_accounts_modal' => $institutional_accounts_modal_tpl,
+				'onclick_create_institutional_account' => "modal(\"$modal_id\",\"create\")"
+			);
+			$p->set_var($var);
+			$p->pfp('out','body');
+		}
+
+	}
+?>
Index: /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 221)
+++ /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 317)
@@ -616,6 +616,7 @@
 		if (!@ldap_add ( $this->ldap, $dn, $entry ))
 		{
-			$result['status'] = false;
-			$result['msg'] = "Erro na funcao ldap_functions->ldap_add_entry ($dn).\nRetorno do servidor:" . ldap_error($this->ldap);
+			$result['status']		= false;
+			$result['error_number']	= ldap_errno($this->ldap);
+			$result['msg']			= "Erro na funcao ldap_functions->ldap_add_entry ($dn).\nRetorno do servidor:" . ldap_errno($this->ldap) . ldap_error($this->ldap);
 		}
 		else
@@ -743,5 +744,13 @@
 		{
 			$result['status'] = false;
-			$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist ($mail).\nRetorno do servidor:" . ldap_error($ldapMasterConnect);
+			if (ldap_errno($ldapMasterConnect) == '50')
+			{
+				$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\n" .
+								 "O usuário utilizado para gravação no LDAP, DEVE ter direito de escrita.\n".
+								 "O usuário " . $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] . " não tem este direito.\n".
+								 "Edite \"Configuração Global do Catálogo\", no módulo Administrador, Catálogo de Endereços e adicione um usuário com direitos de escrita.";
+			}					 
+			else
+				$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\nRetorno do servidor:" . ldap_error($ldapMasterConnect);
 		}
 		
@@ -794,5 +803,13 @@
 		{
 			$result['status'] = false;
-			$result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist ($mail).\n\nRetorno do servidor:" . ldap_error($this->ldap);
+			if (ldap_errno($ldapMasterConnect) == '50')
+			{
+				$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\n" .
+								 "O usuário utilizado para gravação no LDAP, DEVE ter direito de escrita.\n".
+								 "O usuário " . $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] . " não tem este direito.\n".
+								 "Edite \"Configuração Global do Catálogo\", no módulo Administrador, Catálogo de Endereços e adicione um usuário com direitos de escrita.";
+			}					 
+			else
+				$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\nRetorno do servidor:" . ldap_error($ldapMasterConnect);
 		}
 		ldap_close($ldapMasterConnect);
@@ -1271,4 +1288,5 @@
 		{
 			$return['status'] = false;
+			$return['error_number'] = ldap_errno($this->ldap);
 			$return['msg'] = 'Erro em ldap_funcitons->replace_user_attributes: ' . ldap_error($this->ldap);
 		}
@@ -1284,4 +1302,5 @@
 		{
 			$return['status'] = false;
+			$return['error_number'] = ldap_errno($this->ldap);
 			$return['msg'] = 'Erro em ldap_funcitons->add_user_attributes: ' . ldap_error($this->ldap);
 		}
@@ -1360,5 +1379,23 @@
 			}
 		}
-			
+		
+		//INSTITUTIONAL ACCOUNTS
+		$attrs = array();
+		$attrs['mailForwardingAddress'] = $user_info['mail'];
+		
+		$justthese = array("dn");
+		$filter="(&(phpgwAccountType=i)(mailforwardingaddress=".$user_info['mail']."))";
+		$search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
+	    $entries = ldap_get_entries($this->ldap, $search);
+		
+		for ($i=0; $i<$entries['count']; $i++)
+		{
+			if ( !@ldap_mod_del($this->ldap, $entries[$i]['dn'], $attrs) )
+			{
+				$result['status'] = false;
+				$result['msg'] = "Erro na funcao ldap_functions->delete_user, instutional_accounts.\nRetorno do servidor:" . ldap_error($this->ldap);
+			}
+		}
+		
 		// MAILLISTS
 		$attrs = array();
@@ -1387,5 +1424,13 @@
 				{
 					$return['status'] = false;
-					$return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap);
+					if (ldap_errno($ldapMasterConnect) == '50')
+					{
+						$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\n" .
+										 "O usuário utilizado para gravação no LDAP, DEVE ter direito de escrita.\n".
+										 "O usuário " . $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] . " não tem este direito.\n".
+								 		"Edite \"Configuração Global do Catálogo\", no módulo Administrador, Catálogo de Endereços e adicione um usuário com direitos de escrita.";
+					}
+					else
+						$result['msg'] = "Erro na funcao ldap_functions->add_user2maillist.\nRetorno do servidor:" . ldap_error($ldapMasterConnect);
 				}
 			}
@@ -1601,4 +1646,18 @@
 		return $return;
 	}
+	function exist_domain_name_sid($sambadomainname, $sambasid)
+	{
+		$context = $GLOBALS['phpgw_info']['server']['ldap_context'];
+
+		$justthese = array("dn","sambaDomainName");
+		$filter="(&(objectClass=sambaDomain)(sambaSID=$sambasid)(sambaDomainName=$sambadomainname))";
+		$search = ldap_search($this->ldap, $context, $filter, $justthese);
+	    $count_entries = ldap_count_entries($this->ldap, $search);
+	    
+	    if ($count_entries > 0)
+	    	return true;
+	    else
+	    	return false;
+	}
 	
 	function add_sambadomain($sambadomainname, $sambasid, $context)
@@ -1615,5 +1674,5 @@
 		{
 			$return['status'] = false;
-			$return['msg'] = "Erro na funcao ldap_functions->add_sambadomain ($dn).\nRetorno do servidor: " . ldap_error($this->ldap);
+			$return['msg'] = "Erro ao adicionar Samba Domain";
 		}
 		else
@@ -1670,5 +1729,385 @@
 	}
 	
-	
+	function create_institutional_accounts($params)
+	{
+		/* Begin: Access verification */
+		if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'add_institutional_accounts'))
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have right to create institutional accounts') . ".";
+			return $return;
+		}
+		
+		$access_granted = false;
+		foreach ($this->manager_contexts as $idx=>$manager_context)
+		{
+			if (stristr($params['context'], $manager_context))
+			{
+				$access_granted = true;
+				break;
+			}
+		}
+		if (!$access_granted)
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have access to this organization') . ".";
+			return $return;
+		}
+		/* End: Access verification */
+
+		/* Begin: Validation */
+		if ( (empty($params['cn'])) || (empty($params['mail'])) )
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Field mail or name is empty');
+			return $result;
+		}
+
+		if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) )
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.';
+			return $result;
+		}
+
+		$uid = 'institutional_account_' . $params['mail'];
+		$dn = "uid=$uid," . $params['context'];
+
+		$filter = "(mail=".$params['mail'].")";
+		$justthese = array("cn");
+		$search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
+		$entries = @ldap_get_entries($this->ldap,$search);
+		if ($entries['count'] != 0)
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('Field mail already in use');
+			return $result;
+		}
+		/* End: Validation */
+						
+		$info = array();
+		$info['cn']					= $params['cn'];
+		$info['sn']					= $params['cn'];
+		$info['uid']				= $uid;
+		$info['mail']				= $params['mail'];
+		$info['phpgwAccountType']	= 'i';
+		$info['objectClass'][]		= 'inetOrgPerson';
+		$info['objectClass'][]		= 'phpgwAccount';
+		$info['objectClass'][]		= 'top';
+		$info['objectClass'][]		= 'person';
+		$info['objectClass'][]		= 'qmailUser';
+		$info['objectClass'][]		= 'organizationalPerson';
+		
+		if ($params['accountStatus'] == 'on')
+		{
+			$info['accountStatus'] = 'active';
+		}
+		if ($params['phpgwAccountVisible'] == 'on')
+		{
+			$info['phpgwAccountVisible'] = '-1';
+		}
+		
+		if (!empty($params['owners']))
+		{
+			foreach($params['owners'] as $index=>$uidnumber)
+			{
+				$info['mailForwardingAddress'][] = $this->uidnumber2mail($uidnumber);
+			}
+		}		
+		
+		$result = array();
+		if (!@ldap_add ( $this->ldap, $dn, $info ))
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Error in function') . ' ldap_functions->create_institutional_accounts';
+			$result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap);
+		}
+		else
+			$result['status'] = true;
+		
+		return $result;
+	}
+	
+	function save_institutional_accounts($params)
+	{
+		/* Begin: Access verification */
+		if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'edit_institutional_accounts'))
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have right to edit institutional accounts') . ".";
+			return $return;
+		}
+		$access_granted = false;
+		foreach ($this->manager_contexts as $idx=>$manager_context)
+		{
+			if (stristr($params['context'], $manager_context))
+			{
+				$access_granted = true;
+				break;
+			}
+		}
+		if (!$access_granted)
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have access to this organization') . ".";
+			return $return;
+		}
+		/* End: Access verification */
+		
+		/* Begin: Validation */
+		if ( (empty($params['cn'])) || (empty($params['mail'])) )
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Field mail or name is empty') . '.';
+			return $result;
+		}
+
+		if (! eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $params['mail']) )
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Field mail is not formed correcty') . '.';
+			return $result;
+		}
+
+		$uid = 'institutional_account_' . $params['mail'];
+		$dn = strtolower("uid=$uid," . $params['context']);
+		$anchor = strtolower($params['anchor']);
+
+		$filter = "(mail=".$params['mail'].")";
+		$justthese = array("cn");
+		$search = @ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
+		$entries = @ldap_get_entries($this->ldap,$search);
+		
+		if ( ($entries['count'] > 1) || (($entries['count'] == 1) && ($entries[0]['dn'] != $anchor)) )
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('Field mail already in use.');
+			return $result;
+		}
+		/* End: Validation */
+		
+		$result = array();
+		$result['status'] = true;
+		
+		if ($anchor != $dn)
+		{
+			if (!@ldap_rename($this->ldap, $anchor, "uid=$uid", $params['context'], true))
+			{
+				$result['status'] = false;
+				$result['msg']  = $this->functions->lang('Error in function') . ' ldap_functions->save_institutional_accounts: ldap_rename';
+				$result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap);
+			}
+		}
+		
+		$info = array();
+		$info['cn']					= $params['cn'];
+		$info['sn']					= $params['cn'];
+		$info['uid']				= $uid;
+		$info['mail']				= $params['mail'];
+		
+		if ($params['accountStatus'] == 'on')
+			$info['accountStatus'] = 'active';
+		else
+			$info['accountStatus'] = array();
+		
+		if ($params['phpgwAccountVisible'] == 'on')
+			$info['phpgwAccountVisible'] = '-1';
+		else
+			$info['phpgwAccountVisible'] = array();
+		
+		if (!empty($params['owners']))
+		{
+			foreach($params['owners'] as $index=>$uidnumber)
+			{
+				$mailForwardingAddress = $this->uidnumber2mail($uidnumber);
+				if ($mailForwardingAddress != '')
+					$info['mailForwardingAddress'][] = $mailForwardingAddress;
+			}
+		}
+		else
+			$info['mailForwardingAddress'] = array();
+		
+		if (!@ldap_modify ( $this->ldap, $dn, $info ))
+		{
+			$result['status'] = false;
+			$result['msg']  = $this->functions->lang('Error in function') . ' ldap_functions->save_institutional_accounts: ldap_modify';
+			$result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap);
+		}
+
+		return $result;
+	}
+	
+	function get_institutional_accounts($params)
+	{
+		if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'list_institutional_accounts'))
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have right to list institutional accounts') . ".";
+			return $return;
+		}
+
+		$input = $params['input'];
+		$justthese = array("cn", "mail", "uid");
+		$trs = array();
+				
+		foreach ($this->manager_contexts as $idx=>$context)
+		{
+	    	$institutional_accounts = ldap_search($this->ldap, $context, ("(&(phpgwAccountType=i)(|(mail=$input*)(cn=*$input*)))"), $justthese);
+    		$entries = ldap_get_entries($this->ldap, $institutional_accounts);
+    	    	
+			for ($i=0; $i<$entries['count']; $i++)
+			{
+				$tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['cn'][0] . "</td><td onClick=edit_institutional_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "</td><td align='center' onClick=delete_institutional_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>";
+				$trs[$tr] = $entries[$i]['cn'][0];
+			}
+		}
+    	
+    	$trs_string = '';
+    	if (count($trs))
+    	{
+    		natcasesort($trs);
+    		foreach ($trs as $tr=>$cn)
+    		{
+    			$trs_string .= $tr;
+    		}
+    	}
+    	
+    	$return['status'] = 'true';
+    	$return['trs'] = $trs_string;
+    	return $return;
+	}
+	
+	function get_institutional_account_data($params)
+	{
+		if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'edit_institutional_accounts'))
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have right to list institutional accounts') . ".";
+			return $return;
+		}
+		
+		$uid = $params['uid'];
+		$justthese = array("accountStatus", "phpgwAccountVisible", "cn", "mail", "mailForwardingAddress");
+				
+    	$institutional_accounts = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ("(&(phpgwAccountType=i)(uid=$uid))"), $justthese);
+    	$entrie = ldap_get_entries($this->ldap, $institutional_accounts);
+		
+		if ($entrie['count'] != 1)
+		{
+			$return['status'] = 'false';
+			$return['msg'] = 'Problemas carregando dados.';
+		}
+		else
+		{
+			$tmp_user_context = split(",", $entrie[0]['dn']);
+			$tmp_reverse_user_context = array_reverse($tmp_user_context);
+			array_pop($tmp_reverse_user_context);
+			$return['user_context'] = implode(",", array_reverse($tmp_reverse_user_context));
+			
+			$return['status'] = 'true';
+			$return['accountStatus']		= $entrie[0]['accountstatus'][0];
+			$return['phpgwAccountVisible']	= $entrie[0]['phpgwaccountvisible'][0];
+			$return['cn']					= $entrie[0]['cn'][0];
+			$return['mail']					= $entrie[0]['mail'][0];
+
+			if ($entrie[0]['mailforwardingaddress']['count'] > 0)
+			{
+				$a_cn = array();
+				for ($i=0; $i<$entrie[0]['mailforwardingaddress']['count']; $i++)
+				{
+					$tmp = $this->mailforwardingaddress2uidnumber($entrie[0]['mailforwardingaddress'][$i]);
+					if (!$tmp) {}
+					else
+						$a_cn[$tmp['uidnumber']] = $tmp['cn'];
+				}
+				natcasesort($a_cn);
+				foreach($a_cn as $uidnumber => $cn)
+				{
+					$return['owners'] .= '<option value='. $uidnumber .'>' . $cn . '</option>';
+				}
+			}
+		}
+		
+		return $return;
+	}
+	
+	function mailforwardingaddress2uidnumber($mail)
+	{
+		$justthese = array("uidnumber","cn");
+    	$search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ("(&(phpgwAccountType=u)(mail=$mail))"), $justthese);
+    	$entrie = ldap_get_entries($this->ldap, $search);
+		if ($entrie['count'] != 1)
+			return false;
+		else
+		{
+			$return['uidnumber'] = $entrie[0]['uidnumber'][0];
+			$return['cn'] = $entrie[0]['cn'][0];
+			return $return;
+		}
+	}
+	
+	function delete_institutional_account_data($params)
+	{
+		if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'remove_institutional_accounts'))
+		{
+			$return['status'] = false;
+			$return['msg'] = $this->functions->lang('You do not have right to delete institutional accounts') . ".";
+			return $return;
+		}
+
+		$uid = $params['uid'];
+		$return['status'] = true;
+				
+		$justthese = array("cn");
+    	$search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ("(&(phpgwAccountType=i)(uid=$uid))"), $justthese);
+    	$entrie = ldap_get_entries($this->ldap, $search);
+		if ($entrie['count'] > 1)
+		{
+			$return['status'] = false;
+			$return['msg']  = $this->functions->lang('More then one uid was found');
+			return $return;
+		}		
+		if ($entrie['count'] == 0)
+		{
+			$return['status'] = false;
+			$return['msg']  = $this->functions->lang('No uid was found');
+			return $return;
+		}		
+		
+		$dn = $entrie[0]['dn'];
+		if (!@ldap_delete($this->ldap, $dn))
+		{
+			$return['status'] = false;
+			$return['msg']  = $this->functions->lang('Error in function') . " ldap_functions->delete_institutional_accounts: ldap_delete";
+			$return['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap);
+			return $return;
+		}
+		
+		return $return;
+	}
+	
+	function replace_mail_from_institutional_account($newMail, $oldMail)
+	{
+		$filter = "(&(phpgwAccountType=i)(mailforwardingaddress=$oldMail))";
+		$justthese = array("dn");
+		$search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
+		$entries = ldap_get_entries($this->ldap, $search);
+		$result['status'] = true;
+		for ($i=0; $i<$entries['count']; $i++)
+		{
+			$attrs['mailforwardingaddress'] = $oldMail;
+			$res1 = @ldap_mod_del($this->ldap, $entries[$i]['dn'], $attrs);
+			$attrs['mailforwardingaddress'] = $newMail;
+			$res2 = @ldap_mod_add($this->ldap, $entries[$i]['dn'], $attrs);
+		
+			if ((!$res1) || (!$res2))
+			{
+				$result['status'] = false;
+				$return['msg']  = $this->functions->lang('Error in function') . " ldap_functions->replace_mail_from_institutional_account.";
+			}
+		}
+		
+		return $result;
+	}
 }
 ?>
Index: /trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 283)
+++ /trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 317)
@@ -49,5 +49,5 @@
 			{
 				case list_users:
-					if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information])
+					if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information] || $array_acl[acl_edit_users_phonenumber] )
 						return true;
 					break;
@@ -85,4 +85,10 @@
 						return true;
 					break;
+
+				case list_institutional_accounts:
+					if ($array_acl[acl_add_institutional_accounts] || $array_acl[acl_edit_institutional_accounts] || $array_acl[acl_delete_institutional_accounts])
+						return true;
+					break;
+
 
 				default:
@@ -288,5 +294,8 @@
 		
 		// Make a array read humam
-		// Last acl:	1.073.741.824
+		// Last acl:	2.147.483.648 -> edit users phonephone
+		// Last acl:	4.294.967.296 -> add institutional accounts
+		// Last acl:	8.589.934.592 -> edit institutional accounts
+		// Last acl:   17.179.869.184 -> remove institutional accounts
 		function make_array_acl($acl)
 		{
@@ -322,5 +331,9 @@
 							 	"acl_manipulate_corporative_information",
 							 	"acl_edit_users_picture",
-							 	"acl_edit_scl_email_lists"
+							 	"acl_edit_scl_email_lists",
+							 	"acl_edit_users_phonenumber",
+							 	"acl_add_institutional_accounts",
+							 	"acl_edit_institutional_accounts",
+							 	"acl_remove_institutional_accounts"
 							 	);
 			
@@ -334,40 +347,19 @@
 				$bin = '1' . $bin;
 				
-				$array_acl[$right] = $acl & bindec($bin);
-			}			
+				$array_acl[$right] = $this->safeBitCheck(bindec($bin), $acl);
+			}
 			return $array_acl;
-			/*
-			$array_acl['acl_add_users'] = $acl & 1;
-			$array_acl['acl_edit_users'] = $acl & 2;
-			$array_acl['acl_delete_users'] = $acl & 4;
-			//8
-			$array_acl['acl_add_groups'] = $acl & 16;
-			$array_acl['acl_edit_groups'] = $acl & 32;
-			$array_acl['acl_delete_groups'] = $acl & 64;
-			$array_acl['acl_change_users_password'] = $acl & 128;
-			$array_acl['acl_add_maillists'] = $acl & 256;
-			$array_acl['acl_edit_maillists'] = $acl & 512;
-			$array_acl['acl_delete_maillists'] = $acl & 1024;
-			//2048
-			$array_acl['acl_create_sectors'] = $acl & 4096;
-			$array_acl['acl_edit_sectors'] = $acl & 8192;
-			$array_acl['acl_delete_sectors'] = $acl & 16384;
-			$array_acl['acl_edit_sambausers_attributes'] = $acl & 32768;
-			$array_acl['acl_view_global_sessions'] = $acl & 65536;
-			$array_acl['acl_view_logs'] = $acl & 131072;
-			$array_acl['acl_change_users_quote'] = $acl & 262144;
-			$array_acl['acl_set_user_default_password'] = $acl & 524288;
-			$array_acl['acl_create_computers'] = $acl & 1048576;
-			$array_acl['acl_edit_computers'] = $acl & 2097152;
-			$array_acl['acl_delete_computers'] = $acl & 4194304;
-			$array_acl['acl_rename_users'] = $acl & 8388608;
-			$array_acl['acl_edit_sambadomains'] = $acl & 16777216;
-			$array_acl['acl_view_users'] = $acl & 33554432;
-			$array_acl['acl_edit_email_groups'] = $acl & 67108864;
-			$array_acl['acl_empty_user_inbox'] = $acl & 134217728;
-			$array_acl['acl_manipulate_corporative_information'] = $acl & 268435456;
-			$array_acl['acl_edit_users_picture'] = $acl & 536870912;
-			return $array_acl;
-			*/
+		}
+
+		function safeBitCheck($number,$comparison)
+		{
+        	$binNumber = base_convert($number,10,2);
+	        $binComparison = strrev(base_convert($comparison,10,2));
+			$str = strlen($binNumber);
+	        
+	        if ( ($str <= strlen($binComparison)) && ($binComparison{$str-1}==="1") )
+        		return '1';
+	        else
+	        	return '0';
 		}
 		
@@ -748,4 +740,11 @@
 		}
 		
+		function lang($key)
+		{
+			if ($_SESSION['phpgw_info']['expressoAdmin']['lang'][$key])
+				return $_SESSION['phpgw_info']['expressoAdmin']['lang'][$key];
+			else
+				return $key . '*';
+		}
 	}
 	
Index: /trunk/expressoAdmin1_2/js/jscode/institutional_accounts.js
===================================================================
--- /trunk/expressoAdmin1_2/js/jscode/institutional_accounts.js	(revision 317)
+++ /trunk/expressoAdmin1_2/js/jscode/institutional_accounts.js	(revision 317)
@@ -0,0 +1,310 @@
+countFiles = 1;
+
+function create_institutional_accounts()
+{
+	select_owners = Element('ea_select_owners');
+	for(var i = 0;i < select_owners.options.length; i++)
+		select_owners.options[i].selected = true;	
+	cExecuteForm ("$this.ldap_functions.create_institutional_accounts", document.forms['institutional_accounts_form'], handler_create_institutional_accounts);
+}
+
+function handler_create_institutional_accounts(data_return)
+{
+	handler_create_institutional_accounts2(data_return);
+	return;
+}
+
+function handler_create_institutional_accounts2(data_return)
+{
+	if (!data_return.status)
+	{
+		write_msg(data_return.msg, 'error');
+	}
+	else
+	{
+		close_lightbox();
+		write_msg(get_lang('Institutional account successful created') + '.', 'normal');
+	}
+	return;
+}
+
+function set_onload()
+{
+	sinc_combos_org(Element('ea_combo_org').value);
+	get_available_users(Element('ea_combo_org').value);
+}
+
+function get_available_users(context)
+{
+	var	handler_get_users = function(data)
+	{
+		select_available_users = Element('ea_select_available_users');
+		
+		//Clean select
+		for(var i=0; i<select_available_users.options.length; i++)
+		{
+			select_available_users.options[i] = null;
+			i--;
+		}
+
+		if ((data) && (data.length > 0))
+		{
+			// Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
+			select_available_users.innerHTML = '&nbsp;' + data;
+			select_available_users.outerHTML = select_available_users.outerHTML;
+			
+			select_available_users.disabled = false;
+			select_available_users_clone = Element('ea_select_available_users').cloneNode(true);
+			//document.getElementById('ea_input_searchUser').value = '';
+		}
+	}
+	cExecute ('$this.ldap_functions.get_available_users&context='+context, handler_get_users);
+}
+
+function search_organization(key, element)
+{
+	var organizations = Element(element);
+	var RegExp_org = new RegExp("\\b"+key, "i");
+	
+	for(i = 0; i < organizations.length; i++)
+	{
+		if (RegExp_org.test(organizations[i].text))
+		{
+			organizations[i].selected = true;
+			return;
+		}
+	}
+}
+
+function sinc_combos_org(context)
+{
+	combo_org_available_users = Element('ea_combo_org_available_users');
+
+	for (i=0; i<combo_org_available_users.length; i++)
+	{
+		if (combo_org_available_users.options[i].value == context)
+		{
+			combo_org_available_users.options[i].selected = true;
+			get_available_users(context);
+			break;
+		}
+	}
+}
+
+var finderTimeout = '';
+function optionFinderTimeout(obj)
+{
+	clearTimeout(finderTimeout);
+	var oWait = Element("ea_span_searching");
+	oWait.innerHTML = get_lang('searching') + '...';
+	finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
+}
+function optionFinder(id) {
+	var oWait = Element("ea_span_searching");
+	var oText = Element(id);
+		
+	//Limpa todo o select
+	var select_available_users_tmp = Element('ea_select_available_users')
+
+	for(var i = 0;i < select_available_users_tmp.options.length; i++)
+		select_available_users_tmp.options[i--] = null;
+
+	var RegExp_name = new RegExp("\\b"+oText.value, "i");
+	
+	//Inclui usuário começando com a pesquisa
+	for(i = 0; i < select_available_users_clone.length; i++){
+		if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) )
+		{
+			sel = select_available_users_tmp.options;
+			option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
+
+			if (select_available_users_clone[i].value == -1)
+				option.disabled = true;
+
+			sel[sel.length] = option;
+		}
+	}
+	oWait.innerHTML = '&nbsp;';
+}			
+
+function add_user()
+{
+	select_available_users = Element('ea_select_available_users');
+	select_owners = Element('ea_select_owners');
+
+	var count_available_users = select_available_users.length;
+//	var count_owners = select_owners.options.length;
+	var new_options = '';
+
+	for (i = 0 ; i < count_available_users ; i++)
+	{
+		if (select_available_users.options[i].selected)
+		{
+			if(document.all)
+			{
+				if ( (select_owners.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
+				{
+					new_options +=  "<option value="
+								+ select_available_users.options[i].value
+								+ ">"
+								+ select_available_users.options[i].text
+								+ "</options>";
+				}
+			}
+			else
+			{
+				if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
+				{
+					new_options +=  "<option value="
+								+ select_available_users.options[i].value
+								+ ">"
+								+ select_available_users.options[i].text
+								+ "</options>";
+				}
+			}
+		}
+	}
+
+	if (new_options != '')
+	{
+		select_owners.innerHTML = '&nbsp;' + new_options + select_owners.innerHTML;
+		select_owners.outerHTML = select_owners.outerHTML;
+		document.getElementById('ea_input_searchUser').value = "";
+	}
+}
+
+function remove_user()
+{
+	select_owners = Element('ea_select_owners');
+	for(var i = 0;i < select_owners.options.length; i++)
+		if(select_owners.options[i].selected)
+			select_owners.options[i--] = null;
+}
+
+function get_institutional_accounts_timeOut(input)
+{
+	var head_table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("delete")+'</td></tr></table>';
+	
+	if (input.length > 4)
+	{
+		clearTimeout(finderTimeout);
+		finderTimeout = setTimeout("get_institutional_accounts('"+input+"')",500);
+	}
+	else
+	{
+		Element('institutional_accounts_content').innerHTML = head_table;
+	}
+}
+
+function get_institutional_accounts(input)
+{
+	var handler_get_institutional_accounts = function(data)
+	{
+		if (data.status == 'true')
+		{
+			var table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("delete")+'</td></tr>'+data.trs+'</table>';
+			Element('institutional_accounts_content').innerHTML = table;
+		}
+		else
+			write_msg(data.msg, 'error');
+	}
+	cExecute ('$this.ldap_functions.get_institutional_accounts&input='+input, handler_get_institutional_accounts);
+}
+
+function edit_institutional_account(uid)
+{
+	var handle_edit_institutional_account = function(data)
+	{
+		if (data.status == 'true')
+		{
+			modal('institutional_accounts_modal','save');
+			
+			var combo_org = Element('ea_combo_org');
+			for (i=0; i<combo_org.length; i++)
+			{
+				if (combo_org.options[i].value == data.user_context)
+				{
+					combo_org.options[i].selected = true;
+					break;
+				}
+			}
+			
+			// anchor
+			Element('anchor').value = "uid=" + uid + ',' + data.user_context;
+			
+			if (data.accountStatus != 'active')
+				Element('accountStatus').checked = false;
+				
+			if (data.phpgwAccountVisible == '-1')
+				Element('phpgwAccountVisible').checked = true;
+			
+			Element('cn').value = data.cn;
+			
+			Element('mail').value = data.mail;
+			
+			Element('ea_select_owners').innerHTML = data.owners;
+
+			sinc_combos_org(data.user_context);
+		}
+		else
+			write_msg(data.msg, 'error');
+	}
+	cExecute ('$this.ldap_functions.get_institutional_account_data&uid='+uid, handle_edit_institutional_account);
+}
+
+function save_institutional_accounts()
+{
+	if (is_ie){
+		var i = 0;
+		while (document.forms(i).name != "institutional_accounts_form"){i++}
+		form = document.forms(i);
+	}
+	else
+		form = document.forms["institutional_accounts_form"];
+	
+	select_owners = Element('ea_select_owners');
+	for(var i = 0;i < select_owners.options.length; i++)
+		select_owners.options[i].selected = true;	
+	cExecuteForm ("$this.ldap_functions.save_institutional_accounts", form, handler_save_institutional_accounts);
+}
+
+function handler_save_institutional_accounts(data_return)
+{
+	handler_save_institutional_accounts2(data_return);
+	return;
+}
+function handler_save_institutional_accounts2(data_return)
+{
+	if (!data_return.status)
+	{
+		write_msg(data_return.msg, 'error');
+	}
+	else
+	{
+		get_institutional_accounts(Element('ea_institutional_account_search').value);
+		close_lightbox();
+		write_msg(get_lang('Institutional account successful saved') + '.', 'normal');
+	}
+	return;
+}
+
+function delete_institutional_accounts(uid)
+{
+	if (!confirm(get_lang('Are you sure that you want to delete this institutional account') + "?"))
+		return;
+	
+	var handle_delete_institutional_account = function(data_return)
+	{
+		if (!data_return.status)
+		{
+			write_msg(data_return.msg, 'error');
+		}
+		else
+		{
+			write_msg(get_lang('Institutional account successful deleted') + '.', 'normal');
+			get_institutional_accounts(Element('ea_institutional_account_search').value);
+		}
+		return;
+	}
+	cExecute ('$this.ldap_functions.delete_institutional_account_data&uid='+uid, handle_delete_institutional_account);
+}
Index: /trunk/expressoAdmin1_2/js/jscode/connector.js
===================================================================
--- /trunk/expressoAdmin1_2/js/jscode/connector.js	(revision 18)
+++ /trunk/expressoAdmin1_2/js/jscode/connector.js	(revision 317)
@@ -46,5 +46,6 @@
 			var div = document.getElementById('divProgressBar');
 		
-			if(! div) {												
+			if(! div) {
+			try{
 				div = document.createElement("DIV");
 				div.style.visibility	= "hidden";		
@@ -79,4 +80,6 @@
 					document.body.appendChild(div);																
 				}
+			}
+			catch(e){}
 			}								
 	}	
@@ -340,6 +343,9 @@
 								var data = _thisObject.unserialize(oxmlhttp.responseText);
 								if(debug_controller) {
-									document.getElementById("debug_controller").innerHTML += oxmlhttp.responseText;
-									document.getElementById("debug_controller").innerHTML += "<br>-------------------------------------------------------------------------------------<br>";
+									try{
+										document.getElementById("debug_controller").innerHTML += oxmlhttp.responseText;
+										document.getElementById("debug_controller").innerHTML += "<br>-------------------------------------------------------------------------------------<br>";
+									}
+									catch(e){}
 								}									
 								handler(data);
@@ -421,13 +427,21 @@
 	{
 		div = document.getElementById('divProgressBar');
-		div.style.visibility = 'hidden';
-		this.isVisibleBar = false;
+		if ( (div) && (this.isVisibleBar) )
+		{
+			div.style.visibility = 'hidden';
+			this.isVisibleBar = false;
+		}
 	}
 	
 	cConnector.prototype.showProgressBar = function()
 	{
-	div = document.getElementById('divProgressBar');
-		div.style.visibility = 'visible';
-		this.isVisibleBar = true;
+		div = document.getElementById('divProgressBar');
+		if(div)
+		{
+			div.style.visibility = 'visible';
+			this.isVisibleBar = true;
+		}
+		else
+			this.isVisibleBar = false;
 	}
 
Index: /trunk/expressoAdmin1_2/js/jscode/managers.js
===================================================================
--- /trunk/expressoAdmin1_2/js/jscode/managers.js	(revision 309)
+++ /trunk/expressoAdmin1_2/js/jscode/managers.js	(revision 317)
@@ -2,6 +2,9 @@
 function copy_manager(manager)
 {
-	var new_manager = prompt("Digite o login do novo gerente:","");
-	
+	if (!(new_manager = prompt("Digite o login do novo gerente:","")))
+	{
+		return;
+	}
+
 	var handler_copy_manager = function(data)
 	{
Index: /trunk/expressoAdmin1_2/js/jscode/maillists.js
===================================================================
--- /trunk/expressoAdmin1_2/js/jscode/maillists.js	(revision 309)
+++ /trunk/expressoAdmin1_2/js/jscode/maillists.js	(revision 317)
@@ -320,5 +320,5 @@
 var finderTimeout = '';
 
-// Funcoes											
+// Funcoes
 function optionFinderTimeout(obj)
 {
Index: /trunk/expressoAdmin1_2/js/modal/modal.js
===================================================================
--- /trunk/expressoAdmin1_2/js/modal/modal.js	(revision 317)
+++ /trunk/expressoAdmin1_2/js/modal/modal.js	(revision 317)
@@ -0,0 +1,293 @@
+function modal(id, type)
+{
+	try{
+		//content = Element(id).innerHTML;
+		content = Element(id).cloneNode(true);
+		title   = Element(id + '_title').value;
+		width   = Element(id + '_width').value;
+		height  = Element(id + '_height').value;
+		close_action = Element(id + '_close_action').value;
+		create_action = Element(id + '_create_action').value;
+		save_action = Element(id + '_save_action').value;
+		onload_action = Element(id + '_onload_action').value
+	}
+	catch(e){}
+	
+	var objBody = document.getElementsByTagName("body").item(0);
+	
+	/* the Overlay */ // create overlay div and hardcode some functional styles
+	var objOverlay = document.createElement("div");
+	objOverlay.setAttribute('id','overlay');
+	objOverlay.style.position = 'absolute';
+	objOverlay.style.top = '0';
+	objOverlay.style.left = '0';
+	objOverlay.style.zIndex = '90';
+ 	objOverlay.style.width = '100%';
+	
+	var arrayPageSize = getPageSize();
+	var arrayPageScroll = getPageScroll();
+
+	// set height of Overlay to take up whole page and insert. Show at the end of this function.
+	objOverlay.style.height = (arrayPageSize[1] + 'px');
+	objOverlay.style.display = 'none';
+	objBody.insertBefore(objOverlay, objBody.firstChild);
+
+
+	/* the div */ // create lightbox div, same note about styles as above
+	
+	var objLightbox = document.createElement("div");
+	objLightbox.setAttribute('id','lightbox');
+	
+	objLightbox.style.position = 'absolute';
+	objLightbox.style.display = 'none';
+	objLightbox.style.zIndex = '100';	
+
+	
+	var objLightbox_height = height;
+	var objLightbox_width = width;
+	
+	objLightbox.style.height = objLightbox_height + "px";
+	objLightbox.style.width = objLightbox_width + "px";
+	
+	var lightboxTop = ((arrayPageSize[3] - objLightbox_height) / 2);
+	var lightboxLeft = ((arrayPageSize[0] - objLightbox_width) / 2 );
+	
+	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
+	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
+	
+	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
+		
+		
+	// create caption
+	var objCaption = document.createElement("div");
+	objCaption.setAttribute('id','lightboxCaption');
+	objCaption.innerHTML = title;
+	objLightbox.appendChild(objCaption);
+
+	// create warnings
+	var objWarning = document.createElement("div");
+	objWarning.setAttribute('id','lightboxWarning');
+	objWarning.style.height = '21px';
+	objLightbox.appendChild(objWarning);
+
+	// Create Content
+	var objContent = document.createElement("div");
+	objContent.setAttribute('id','lightboxContent');
+	objContent.style.height = (objLightbox_height - 65) + "px";
+	objContent.innerHTML = content.innerHTML;
+	objLightbox.appendChild(objContent);
+
+	// create foot
+	var objCaption = document.createElement("div");
+	objCaption.setAttribute('id','lightboxFoot');
+	
+	var close_button = '<input type=button value="Fechar" onClick='+close_action+'>';
+	if (type == 'create')
+		var create_save_button = '<input type=button value="Criar" onClick='+create_action+'>';
+	else if(type == 'save')
+		var create_save_button = '<input type=button value="Salvar" onClick='+save_action+'>';
+	objCaption.innerHTML = '<table width=100% cellspacing="0" cellpadding="0"><tr><td align=left>'+close_button+'</td><td align=right>'+create_save_button+'</td></tr></table>'
+	
+	objLightbox.appendChild(objCaption);
+
+	if (onload_action)
+	{
+		eval(onload_action);
+	}
+
+	//Show the modal.
+	objOverlay.style.display = 'block';
+	objLightbox.style.display = '';
+}
+
+function close_lightbox()
+{
+	var objBody = document.getElementsByTagName("body").item(0);
+	var lightbox = document.getElementById('overlay');
+	lightbox_div = document.getElementById('lightbox');
+	objBody.removeChild(lightbox);
+	objBody.removeChild(lightbox_div);
+	return;
+}
+
+function getPageSize(){
+	
+	var xScroll, yScroll;
+	
+	if (window.innerHeight && window.scrollMaxY) {	
+		xScroll = document.body.scrollWidth;
+		yScroll = window.innerHeight + window.scrollMaxY;
+	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
+		xScroll = document.body.scrollWidth;
+		yScroll = document.body.scrollHeight;
+	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
+		xScroll = document.body.offsetWidth;
+		yScroll = document.body.offsetHeight;
+	}
+	
+	var windowWidth, windowHeight;
+	if (self.innerHeight) {	// all except Explorer
+		windowWidth = self.innerWidth;
+		windowHeight = self.innerHeight;
+	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
+		windowWidth = document.documentElement.clientWidth;
+		windowHeight = document.documentElement.clientHeight;
+	} else if (document.body) { // other Explorers
+		windowWidth = document.body.clientWidth;
+		windowHeight = document.body.clientHeight;
+	}	
+	
+	// for small pages with total height less then height of the viewport
+	if(yScroll < windowHeight){
+		pageHeight = windowHeight;
+	} else { 
+		pageHeight = yScroll;
+	}
+
+	// for small pages with total width less then width of the viewport
+	if(xScroll < windowWidth){	
+		pageWidth = windowWidth;
+	} else {
+		pageWidth = xScroll;
+	}
+	
+	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
+	return arrayPageSize;
+}
+
+function getPageScroll(){
+
+	var yScroll;
+
+	if (self.pageYOffset) {
+		yScroll = self.pageYOffset;
+	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
+		yScroll = document.documentElement.scrollTop;
+	} else if (document.body) {// all other Explorers
+		yScroll = document.body.scrollTop;
+	}
+
+	arrayPageScroll = new Array('',yScroll) 
+	return arrayPageScroll;
+}
+
+function Element(id)
+{
+	return document.getElementById(id);
+}
+
+function add_css(){
+	var headID = document.getElementsByTagName("head")[0];         
+	var cssNode = document.createElement('link');
+	cssNode.type = 'text/css';
+	cssNode.rel = 'stylesheet';
+	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1)
+		cssNode.href = "./expressoAdmin1_2/js/modal/css/modal_ie.css";
+	else
+		cssNode.href = "./expressoAdmin1_2/js/modal/css/modal_fx.css";
+	
+	cssNode.media = 'screen';
+	headID.appendChild(cssNode);
+	return;
+}
+
+function load_lang(){
+	cExecute ('$this/js/modal/inc/load_lang', handler_load_lang);
+}
+
+var global_langs = new Array();
+function handler_load_lang(data)
+{
+	global_langs = eval(data);
+}
+
+function get_lang(key_raw)
+{
+	key = key_raw.replace(/ /g,"_");
+
+	try{
+		lang = eval("global_langs."+key.toLowerCase());
+		return lang;
+	}
+	catch(e){
+		return key_raw + '*';
+	}
+}
+
+function make_msg(msg, type)
+{
+	var html_msg = 
+	'<table cellspacing="0" cellpadding="0" border="0"><tbody>'+
+	'<tr><td class="zIVQRb_'+type+'"/><td class="Ptde9b_'+type+'"/><td class="Qrjz3e_'+type+'"/></tr>'+
+	'<tr><td class="Ptde9b_'+type+'"/><td class="m14Grb_'+type+'">' + msg + '</td><td class="Ptde9b_'+type+'"/></tr>' +
+	'<tr><td class="Gbtri_'+type+'"/><td class="Ptde9b_'+type+'"/><td class="gmNpMd_'+type+'"/></tr></tbody></table>';
+	return html_msg;
+}
+
+function write_msg(msg, type)
+{
+	try
+	{
+		clearTimeout(setTimeout_write_msg);
+	}
+	catch(e){}
+		
+	var objLightbox = Element("lightbox");
+	if (objLightbox != null)
+	{
+		var old_divStatusBar = Element("lightboxWarning");
+		var bgColor = "#EEEEEE";
+	}
+	else
+	{
+		var old_divStatusBar = Element("divStatusBar");
+		var bgColor = "#f7f8fa";
+	}
+	
+	var msg_div = Element('em_div_write_msg');
+	if(!msg_div) {
+		msg_div = document.createElement('DIV');
+		msg_div.id = 'em_div_write_msg';
+		//msg_div.style.height = '2px';
+		msg_div.style.background = bgColor;
+		msg_div.style.display = 'none';
+		msg_div.align = "center";
+		msg_div.valign = "middle";
+	}
+	
+	msg_div.innerHTML = make_msg(msg, type);
+	
+	clean_msg();
+	old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
+	
+	old_divStatusBar.style.display = 'none';
+	msg_div.style.display = '';
+	
+	setTimeout_write_msg = setTimeout("clean_msg();", 4000);
+}
+
+function clean_msg()
+{
+	var msg_div = Element('em_div_write_msg');
+	if ( (msg_div) && (msg_div.style.display != 'none') )
+	{
+		// Msg esta em outra tela. Precisa apaga-la.
+		/*
+		if ( (Element("lightbox") != null) && (msg_div.nextSibling.id == 'lightboxWarning') ) {}
+		else if ( (Element("lightbox") == null) && (msg_div.nextSibling.id == 'divStatusBar') ) {}
+		else
+		{*/
+			msg_div.style.display = 'none';
+			msg_div.nextSibling.style.display = '';
+//		}
+	}
+}
+
+if (document.all)
+{
+	navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
+	is_ie = true;
+}
+
+add_css();
+load_lang();
Index: /trunk/expressoAdmin1_2/js/modal/css/modal_fx.css
===================================================================
--- /trunk/expressoAdmin1_2/js/modal/css/modal_fx.css	(revision 317)
+++ /trunk/expressoAdmin1_2/js/modal/css/modal_fx.css	(revision 317)
@@ -0,0 +1,160 @@
+#lightbox{
+	background-color:#eee;
+	padding: 10px;
+	border-bottom: 2px solid #666;
+	border-right: 2px solid #666;
+}
+
+#lightboxCaption {
+	font-size: 1.8em;
+	text-align: center;
+	border-bottom: 2px solid #666;
+	
+	position: relative;
+	width: 100%;
+	height: auto;
+	top: 0;
+	right: 0;
+	bottom: auto;
+	left: 0;
+}
+
+#lightboxContent {
+	position:relative;
+	top:0pt;
+	left:0pt;
+	right:0pt;
+	width:auto;
+	overflow: auto;
+}
+
+#lightboxFoot {
+	border-top:2px solid #666666;
+	position:relative;
+	text-align:left;
+	top:0pt;
+	width:100%;
+}
+
+#keyboardMsg{ float: right; }
+
+#closeButton{ top: 5px; right: 5px; }
+
+#lightbox img{ border: none; clear: both;} 
+
+#overlay img{ border: none; }
+
+#overlay{
+	background: url(../images/overlay.png);
+}
+
+#divStatusBar{
+	height:22px;
+}
+
+.info_msg {
+	font-family: Arial, sans-serif, Helvetica, Verdana;
+	font-size: 13px;
+	border-width: 0px 0px 0px 0px;
+	padding: 1px 10px 0px 10px;	
+	border-style: inset inset inset inset;
+	border-color: gray gray gray gray;
+	background-color: rgb(250, 209, 99);
+	-moz-border-radius: 6px 6px 6px 6px;
+}
+
+.error_msg {
+	font-family: Arial, sans-serif, Helvetica, Verdana;
+	font-size: 13px;
+	font-weight: bold;
+	color: rgb(255, 255, 255);
+	background-color: rgb(240, 0, 0);
+	border-width: 0px 0px 0px 0px;
+	padding: 1px 10px 0px 10px;	
+	border-style: inset inset inset inset;
+	border-color: gray gray gray gray;
+	-moz-border-radius: 6px 6px 6px 6px;
+}
+
+/* NORMAL - yellow */
+/* superior esquerdo */
+.zIVQRb_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll 0pt 0pt;
+}
+
+/* superior direito */ 
+.Qrjz3e_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll -4px 0pt;
+}
+ 
+/* inferior esquerdo */ 
+.Gbtri_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll 0pt -4px;
+}
+
+/* inferior direito */
+.gmNpMd_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll -4px -4px;
+}
+
+/* linha do meio, entre os cantos */
+.Ptde9b_normal {
+	background:#FFF1A8 none repeat scroll 0%;
+	color:#FFFFFF;
+}
+
+/* Conteudo */
+.m14Grb_normal {
+	color: black;
+	background: #FFF1A8;
+	font-size:80%;
+	font-weight:bold;
+	font-family: arial,sans-serif;
+	padding:0pt 5px;
+	text-align:center;
+}
+
+/* ERROR - red */
+/* superior esquerdo */
+.zIVQRb_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll 0pt 0pt;
+}
+
+/* superior direito */ 
+.Qrjz3e_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll -4px 0pt;
+}
+ 
+/* inferior esquerdo */ 
+.Gbtri_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll 0pt -4px;
+}
+
+/* inferior direito */
+.gmNpMd_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll -4px -4px;
+}
+
+/* linha do meio, entre os cantos */
+.Ptde9b_error {
+	background:#CC0000 none repeat scroll 0%;
+	color:#FFFFFF;
+}
+
+/* Conteudo */
+.m14Grb_error {
+	color: white;
+	background: #cc0000;
+	font-size:80%;
+	font-weight:bold;
+	font-family: arial,sans-serif;
+	padding:0pt 5px;
+	text-align:center;
+}
+
+/* todas os cantos */
+.zIVQRb_error, .Qrjz3e_error, .Gbtri_error, .gmNpMd_error, .zIVQRb_normal, .Qrjz3e_normal, .Gbtri_normal, .gmNpMd_normal {
+	font-size:0pt;
+	height:4px;
+	width:4px;
+}
Index: /trunk/expressoAdmin1_2/js/modal/css/modal_ie.css
===================================================================
--- /trunk/expressoAdmin1_2/js/modal/css/modal_ie.css	(revision 317)
+++ /trunk/expressoAdmin1_2/js/modal/css/modal_ie.css	(revision 317)
@@ -0,0 +1,160 @@
+#lightbox{
+	background-color:#eee;
+	padding: 10px;
+	border-bottom: 2px solid #666;
+	border-right: 2px solid #666;
+}
+
+#lightboxCaption {
+	font-size: 1.8em;
+	text-align: center;
+	border-bottom: 2px solid #666;
+	
+	position: relative;
+	width: 100%;
+	height: auto;
+	top: 0;
+	right: 0;
+	bottom: auto;
+	left: 0;
+}
+
+#lightboxContent {
+	position:relative;
+	top:0pt;
+	left:0pt;
+	right:0pt;
+	width:auto;
+	overflow: auto;
+}
+
+#lightboxFoot {
+	border-top:2px solid #666666;
+	position:relative;
+	text-align:left;
+	top:0pt;
+	width:100%;
+}
+
+#keyboardMsg{ float: right; }
+
+#closeButton{ top: 5px; right: 5px; }
+
+#lightbox img{ border: none; clear: both;} 
+
+#overlay img{ border: none; }
+
+#overlay{
+	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/expresso/expressoAdmin1_2/js/modal/images/overlay.png', sizingMethod='scale');
+}
+
+#divStatusBar{
+	height:22px;
+}
+
+.info_msg {
+	font-family: Arial, sans-serif, Helvetica, Verdana;
+	font-size: 13px;
+	border-width: 0px 0px 0px 0px;
+	padding: 1px 10px 0px 10px;	
+	border-style: inset inset inset inset;
+	border-color: gray gray gray gray;
+	background-color: rgb(250, 209, 99);
+	-moz-border-radius: 6px 6px 6px 6px;
+}
+
+.error_msg {
+	font-family: Arial, sans-serif, Helvetica, Verdana;
+	font-size: 13px;
+	font-weight: bold;
+	color: rgb(255, 255, 255);
+	background-color: rgb(240, 0, 0);
+	border-width: 0px 0px 0px 0px;
+	padding: 1px 10px 0px 10px;	
+	border-style: inset inset inset inset;
+	border-color: gray gray gray gray;
+	-moz-border-radius: 6px 6px 6px 6px;
+}
+
+/* NORMAL - yellow */
+/* superior esquerdo */
+.zIVQRb_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll 0pt 0pt;
+}
+
+/* superior direito */ 
+.Qrjz3e_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll -4px 0pt;
+}
+ 
+/* inferior esquerdo */ 
+.Gbtri_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll 0pt -4px;
+}
+
+/* inferior direito */
+.gmNpMd_normal {
+	background:transparent url(../images/rc_normal.png) no-repeat scroll -4px -4px;
+}
+
+/* linha do meio, entre os cantos */
+.Ptde9b_normal {
+	background:#FFF1A8 none repeat scroll 0%;
+	color:#FFFFFF;
+}
+
+/* Conteudo */
+.m14Grb_normal {
+	color: black;
+	background: #FFF1A8;
+	font-size:80%;
+	font-weight:bold;
+	font-family: arial,sans-serif;
+	padding:0pt 5px;
+	text-align:center;
+}
+
+/* ERROR - red */
+/* superior esquerdo */
+.zIVQRb_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll 0pt 0pt;
+}
+
+/* superior direito */ 
+.Qrjz3e_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll -4px 0pt;
+}
+ 
+/* inferior esquerdo */ 
+.Gbtri_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll 0pt -4px;
+}
+
+/* inferior direito */
+.gmNpMd_error {
+	background:transparent url(../images/rc_error.png) no-repeat scroll -4px -4px;
+}
+
+/* linha do meio, entre os cantos */
+.Ptde9b_error {
+	background:#CC0000 none repeat scroll 0%;
+	color:#FFFFFF;
+}
+
+/* Conteudo */
+.m14Grb_error {
+	color: white;
+	background: #cc0000;
+	font-size:80%;
+	font-weight:bold;
+	font-family: arial,sans-serif;
+	padding:0pt 5px;
+	text-align:center;
+}
+
+/* todas os cantos */
+.zIVQRb_error, .Qrjz3e_error, .Gbtri_error, .gmNpMd_error, .zIVQRb_normal, .Qrjz3e_normal, .Gbtri_normal, .gmNpMd_normal {
+	font-size:0pt;
+	height:4px;
+	width:4px;
+}
Index: /trunk/expressoAdmin1_2/js/modal/inc/load_lang.php
===================================================================
--- /trunk/expressoAdmin1_2/js/modal/inc/load_lang.php	(revision 317)
+++ /trunk/expressoAdmin1_2/js/modal/inc/load_lang.php	(revision 317)
@@ -0,0 +1,29 @@
+<?
+/*
+	$fn = './setup/phpgw_'.$_SESSION['phpgw_info']['expressoAdmin']['user']['preferences']['common']['lang'].'.lang';
+	
+	if (file_exists($fn))
+	{
+		$lang = array();
+		
+		$fp = fopen($fn,'r');
+		while ($data = fgets($fp,16000))
+		{
+			list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));			
+			$lang[str_replace(" ", "_", (strtolower($message_id)) )] = $content;
+		}
+		fclose($fp);
+		
+		echo serialize($lang);
+	}		
+	exit;
+*/
+
+	$lang = array();
+	foreach($_SESSION['phpgw_info']['expressoAdmin']['lang'] as $message_id=>$content)
+	{
+		$lang[str_replace(" ", "_", (strtolower($message_id)) )] = $content;
+	}
+	echo serialize($lang);
+	exit;
+?>
Index: /trunk/expressoAdmin1_2/index.php
===================================================================
--- /trunk/expressoAdmin1_2/index.php	(revision 309)
+++ /trunk/expressoAdmin1_2/index.php	(revision 317)
@@ -35,4 +35,5 @@
 	$var = Array(
 		'lang_user_accounts'	=> lang('User Accounts'),
+		'lang_institutional_accounts'=> lang('Institutional Accounts'),
 		'lang_user_groups'		=> lang('User Groups'),
 		'lang_email_lists'		=> lang('Email Lists'),
@@ -47,4 +48,27 @@
 	$template->pfp('out','body');
 	
+	/* save lang and session */
+	/*
+	if (!empty($GLOBALS['phpgw_info']['expresso']))
+	{
+		$_SESSION['phpgw_info']['expresso'] = $GLOBALS['phpgw_info']['expresso'];
+	}*/
+	
+	if (empty($_SESSION['phpgw_info']['expressoAdmin']['lang']))
+	{
+		$_SESSION['phpgw_info']['expressoAdmin']['user']['preferences']['common']['lang'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
+		$fn = './setup/phpgw_'.$_SESSION['phpgw_info']['expressoAdmin']['user']['preferences']['common']['lang'].'.lang';
+		if (file_exists($fn))
+		{
+			$fp = fopen($fn,'r');
+			while ($data = fgets($fp,16000))
+			{
+				list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));
+				$_SESSION['phpgw_info']['expressoAdmin']['lang'][$message_id] = $content;
+			}
+			fclose($fp);
+		}
+	}
+
 	$GLOBALS['phpgw']->common->phpgw_footer();
 ?>
Index: /trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl	(revision 317)
+++ /trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl	(revision 317)
@@ -0,0 +1,64 @@
+<input type="hidden" id="{modal_id}_title" value="{lang_criation_of_institutional_accounts}">
+<input type="hidden" id="{modal_id}_height" value="483">
+<input type="hidden" id="{modal_id}_width" value="930">
+<input type="hidden" id="{modal_id}_close_action" value="close_lightbox()">
+<input type="hidden" id="{modal_id}_create_action" value="create_institutional_accounts()">
+<input type="hidden" id="{modal_id}_save_action" value="save_institutional_accounts()">
+<input type="hidden" id="{modal_id}_onload_action" value="set_onload({manager_context})">
+
+<form enctype="multipart/form-data" name="institutional_accounts_form" method="post">
+<input type="hidden" id="anchor" name="anchor">
+
+<table border="0" width="80%" cellspacing="4">
+	<tr>
+		<td bgcolor="#DDDDDD">
+			{lang_search_organization}:<br>
+			<input type="text" id="organization_search" autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org');" onBlur="javascript:sinc_combos_org(context.value);">
+			<br>
+			{lang_organization}:<br>
+			<select id="ea_combo_org" name="context" onchange="javascript:sinc_combos_org(this.value);">{manager_organizations}</select><br>
+							
+			{lang_full_name}: <font color="blue">{lang_eg}: Setor Diser</font><br>
+			<input id="cn" name="cn" size="35" autocomplete="off"><br>
+						
+			{lang_mail}: <font color="blue">{lang_eg}: diser@celepar.pr.gov.br</font><br>
+			<input id="mail" name="mail" size="35" autocomplete="off"><br>
+							
+			{lang_is_account_active}: <input type="checkbox" id="accountStatus" name="accountStatus" checked><br>
+			{lang_omit_account_from_the_catalog}: <input type="checkbox" id="phpgwAccountVisible" name="phpgwAccountVisible"><br>
+							
+			<b>{lang_owners}:</b><br>
+			<select id="ea_select_owners" name="owners[]" style="width:400px; height:200px" multiple size="13"></select>
+		</td>
+						
+		<td valign="middle" align="center" bgcolor="#DDDDDD">
+			<button type="button" onClick="javascript:add_user();"><img src="expressoAdmin1_2/templates/default/images/add.png" style="vertical-align: middle;" >&nbsp;{lang_add_owner}</button>
+			<br><br>
+			<button type="button" onClick="javascript:remove_user();"><img src="expressoAdmin1_2/templates/default/images/rem.png" style="vertical-align: middle;" >&nbsp;{lang_remove_owner}</button>
+		</td>
+						
+		<td valign="bottom" bgcolor="#DDDDDD">
+			{lang_search_organization}:<br>
+			<input type="text" id="organization_search" autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org_available_users');" onBlur="javascript:get_available_users(org_context.value);">
+			<br>
+							
+			{lang_organizations}:<br>
+			<select name="org_context" id="ea_combo_org_available_users" onchange="javascript:get_available_users(this.value);">{all_organizations}</select>
+			<br>
+			<!--
+			<input type="checkbox" name="ea_check_allUsers" id="ea_check_allUsers" onclick="javascript:get_available_users(org_context.value, this.checked);">{lang_all_users}.
+			-->
+			<br><br>
+							
+			{lang_search_user}:<br>
+			<input id="ea_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this)"><br>
+							
+			<font color="red"><span id="ea_span_searching">&nbsp;</span></font>
+			<br>
+			<b>{lang_users}:</b><br>
+			<select id="ea_select_available_users" style="width:400px; height:200px" multiple size="13"></select>
+		</td>
+	</tr>
+</table>
+
+</form>
Index: /trunk/expressoAdmin1_2/templates/default/institutional_accounts.css
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/institutional_accounts.css	(revision 317)
+++ /trunk/expressoAdmin1_2/templates/default/institutional_accounts.css	(revision 317)
@@ -0,0 +1,8 @@
+.normal {
+	background-color: #DDDDDD;	
+}
+
+.selected {
+	cursor: pointer;
+	background-color: #CCCBBB;
+}
Index: /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 309)
+++ /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 317)
@@ -42,5 +42,5 @@
 		<tr bgcolor={row_on}>
 			<td>{lang_search_organization}:</td>
-			<td><input type="text" id="organization_search" autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org_info');" onBlur="javascript:sinc_combos_org(context.value); get_available_groups(context.value); get_available_maillists(context.value); get_available_sambadomains(context.value, '{type}')"></td>
+			<td><input type="text" id="organization_search" {disabled} autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org_info');" onBlur="javascript:sinc_combos_org(context.value); get_available_groups(context.value); get_available_maillists(context.value); get_available_sambadomains(context.value, '{type}')"></td>
 		</tr>
 
@@ -86,5 +86,5 @@
 		<tr bgcolor={row_off}>
 			<td width="15%">{lang_phone}:</td>
-			<td width="35%"><input type="text" name="telephonenumber" id="telephonenumber" value="{telephonenumber}" autocomplete="off" {disabled} size=20 onkeyUp="FormataValor(event, this);"></input>&nbsp;</td>
+			<td width="35%"><input type="text" name="telephonenumber" id="telephonenumber" value="{telephonenumber}" autocomplete="off" {disable_phonenumber} size=20 maxlength=13 onkeyUp="FormataValor(event, this);"></input>&nbsp;</td>
 			<td>&nbsp;</td>
 			<td rowspan="4" width="35%" style="display:{display_picture}">
Index: /trunk/expressoAdmin1_2/templates/default/institutional_accounts.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/institutional_accounts.tpl	(revision 317)
+++ /trunk/expressoAdmin1_2/templates/default/institutional_accounts.tpl	(revision 317)
@@ -0,0 +1,33 @@
+<!-- BEGIN body -->
+	<link rel="stylesheet" type="text/css" href="./expressoAdmin1_2/templates/default/institutional_accounts.css">
+	<div style="display:none" id="{modal_id}">{institutional_accounts_modal}</div>
+
+	<div align="center">
+		<table border="0" width="90%">
+			<tr>
+				<td align="left" width="25%">
+					<input type="button" value="{lang_create_institutional_account}" "{create_institutional_account_disabled}" onClick='{onclick_create_institutional_account}'>
+					<input type="button" value="{lang_back}" onClick="document.location.href='{back_url}'">
+				</td>
+				<td align="center" "left" width="50%">
+					{lang_contexts}: <font color="blue">{context_display}</font>
+				</td>
+				<td align="right" "left" width="25%">
+						{lang_to_search}:
+						<input type="text" onKeyUp="javascript:get_institutional_accounts_timeOut(this.value)" id="ea_institutional_account_search" autocomplete="off" value="{query}">
+				</td>
+			</tr>
+		</table>
+	</div>
+ 
+	<div align="center" id="institutional_accounts_content">
+		<table border="0" width="90%">
+			<tr bgcolor="{th_bg}">
+				<td width="30%">{lang_full_name}</td>
+				<td width="30%">{lang_mail}</td>
+				<td width="5%" align="center">{lang_delete}</td>
+			</tr>
+		</table>
+	</div>	
+
+<!-- END body -->
Index: /trunk/expressoAdmin1_2/templates/default/index.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/index.tpl	(revision 309)
+++ /trunk/expressoAdmin1_2/templates/default/index.tpl	(revision 317)
@@ -1,4 +1,4 @@
 <!-- BEGIN body -->
-<table width="90%" border="0" cellspacing="4" cellpadding="0" align="center"> 
+<table width="90%" border="0" cellspacing="10" cellpadding="0" align="center"> 
 	<tr>
 		<td width="1%" align="center">
@@ -7,4 +7,12 @@
   		<td>
   			<a href="../index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users">{lang_user_accounts}</a>
+  		</td>
+  	</tr> 
+	<tr>
+		<td width="1%" align="center">
+			<img HEIGHT='24' WIDTH='24' src='./templates/default/images/institutional_account.png'>
+  		</td>
+  		<td>
+  			<a href="../index.php?menuaction=expressoAdmin1_2.institutional_accounts.index">{lang_institutional_accounts}</a>
   		</td>
   	</tr> 
Index: /trunk/expressoAdmin1_2/templates/default/managers_form.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/managers_form.tpl	(revision 309)
+++ /trunk/expressoAdmin1_2/templates/default/managers_form.tpl	(revision 317)
@@ -55,4 +55,5 @@
 					
 					<!-- BEGIN ACL CONTROL -->
+					<!-- last acl: 2147483648 -->
 					<table id="ea_table_acl">
 					    <tr bgcolor="{color_font2}">
@@ -101,25 +102,40 @@
 							<td><input type="checkbox" name="acl_manipulate_corporative_information" value="268435456" {acl_manipulate_corporative_information}></td>
 						</tr>
+						
 						<tr bgcolor="{color_font2}" align='right'>
 							<td>{lang_view_user}:</td>
 							<td><input type="checkbox" name="acl_view_users" value="33554432" {acl_view_users}></td>
+							
+							<td>{lang_add_institutional_accounts}:</td>
+							<td><input type="checkbox" name="acl_add_institutional_accounts" value="4294967296" {acl_add_institutional_accounts}></td>
 						</tr>
 						<tr bgcolor="{color_font1}" align='right'>
 							<td>{lang_edit_users_picture}:</td>
 							<td><input type="checkbox" name="acl_edit_users_picture" value="536870912" {acl_edit_users_picture}></td>
-						</tr>
-						<tr bgcolor="{color_font2}" align='right'>
+							
+							<td>{lang_edit_institutional_accounts}:</td>
+							<td><input type="checkbox" name="acl_edit_institutional_accounts" value="8589934592" {acl_edit_institutional_accounts}></td>
+						</tr>
+						<tr bgcolor="{color_font2}" align='right'>
+							<td>{lang_edit_users_phonenumber}:</td>
+							<td><input type="checkbox" name="acl_edit_users_phonenumber" value="2147483648" {acl_edit_users_phonenumber}></td>
+							
+							<td>{lang_remove_institutional_accounts}:</td>
+							<td><input type="checkbox" name="acl_remove_institutional_accounts" value="17179869184" {acl_remove_institutional_accounts}></td>
+						</tr>
+						
+						<tr bgcolor="{color_font1}" align='right'>
 							<td>{lang_change_users_password}:</td>
 							<td><input type="checkbox" name="acl_change_users_password" value="128" {acl_change_users_password}></td>
 						</tr>
-						<tr bgcolor="{color_font1}" align='right'>
+						<tr bgcolor="{color_font2}" align='right'>
 							<td>{lang_change_users_quote}:</td>
 							<td><input type="checkbox" name="acl_change_users_quote" value="262144" {acl_change_users_quote}></td>
 						</tr>
-						<tr bgcolor="{color_font2}" align='right'>
+						<tr bgcolor="{color_font1}" align='right'>
 							<td>{lang_set_default_users_password}:</td>
 							<td><input type="checkbox" name="acl_set_user_default_password" value="524288" {acl_set_user_default_password}></td>
 						</tr>
-						<tr bgcolor="{color_font1}" align='right'>
+						<tr bgcolor="{color_font2}" align='right'>
 							<td>{lang_empty_user_inbox}:</td>
 							<td><input type="checkbox" name="acl_empty_user_inbox" value="134217728" {acl_empty_user_inbox}></td>
