Index: trunk/expressoAdmin1_2/inc/class.db_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.db_functions.inc.php	(revision 7673)
+++ trunk/expressoAdmin1_2/inc/class.db_functions.inc.php	(revision 7769)
@@ -625,5 +625,4 @@
 		$sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) "
 		. "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')";
-		
 		if (!$this->db->query($sql))
 		{
Index: trunk/expressoAdmin1_2/inc/class.shared_accounts.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.shared_accounts.inc.php	(revision 7655)
+++ trunk/expressoAdmin1_2/inc/class.shared_accounts.inc.php	(revision 7769)
@@ -50,6 +50,8 @@
                                    $result &= $this->db_functions->save_calendar_acls($this->ldap_functions->uid2uidnumber($user),$acl,$owner);
                                 }
+                $this->db_functions->write_log('Create Shared account',$params['uid']);
+			}
 
-			} 		
+
 			return $return;
 		}
@@ -62,8 +64,6 @@
                         $result = $this->ldap_functions->save_shared_accounts($params);
 
-
-                        if( $result['status']){
-                            $result = $this->imap_functions->save_shared_account($params);                            
-
+            if( $result['status']){
+                            $result = $this->imap_functions->save_shared_account($params);
                             $owners_calendar_acl_new = unserialize($params['owners_calendar_acl']);
 
@@ -72,4 +72,6 @@
                               $this->db_functions->save_calendar_acls($this->ldap_functions->uid2uidnumber($user),$acl,$owner);
                             }
+
+                            $this->db_functions->write_log('Update Shared account','Old UID:'.$params['old_uid'].' New UID '.$params['uid']);
                         }
 
@@ -161,5 +163,9 @@
                 function delete($params){
                     $result = $this->ldap_functions->delete_shared_account_data($params);
-                    if( $result['status'] ) $result = $this->imap_functions->delete_mailbox($params['uid']);
+                    if( $result['status'] )
+                    {
+                        $result = $this->imap_functions->delete_mailbox($params['uid']);
+                        $this->db_functions->write_log('Removed Shared account',$params['uid']);
+                    }
                     return $result;
                 }
Index: trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 7552)
+++ trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 7769)
@@ -321,5 +321,5 @@
                             $result['msg']  = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl';
                             $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error();
-                            break;
+//                            break;
                         }
 		}
@@ -384,4 +384,20 @@
 				return $result;
             }
+
+            if(count($owners_to_remove) > 0)
+            {
+                foreach($owners_to_remove as $user => $acl)
+                {
+                    $this->functions->write_log("User removed from the shared account",'USER: '.$user.' - SHARED ACCOUNT: '.$params['uid']);
+                }
+            }
+            if(count($owners_to_add) > 0)
+            {
+                foreach($owners_to_add as $user => $acl)
+                {
+                    $this->functions->write_log("User added from the shared account",'USER: '.$user.' - SHARED ACCOUNT: '.$params['uid']);
+                }
+            }
+
             //file_put_contents("/tmp/saida", "old ".print_r($owners_acl_old, true)."remove ".print_r($owners_to_remove, true)."add ".print_r($owners_to_add, true)."update ".print_r($owners_to_update, true));
             if( is_array($owners_acl_new)){
@@ -442,8 +458,8 @@
 	    require_once('class.ldap_functions.inc.php');
 
-	    if( !$ldap )
-	    {
+//	    if( !$ldap )
+//	    {
 		$ldap = new ldap_functions();
-	    }
+//	    }
 
 	    $to = $ldap->uid2mailforwardingaddress( $user );
@@ -468,5 +484,5 @@
 	    $keys = array_keys( $tpls );
 
-	    if( !array_diff_key( $tpl, array_keys( $keys ) ) )
+	    if( !array_diff_key( $tpls, array_keys( $keys ) ) )
 	    {
 		$newTpls = array();
Index: trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 7681)
+++ trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 7769)
@@ -39,4 +39,9 @@
 			$this->current_config = $c->config_data;
 		}
+
+        function write_log($action, $about)
+        {
+            return $this->db_functions->write_log($action, $about);
+        }
 		
 		// Account and type of access. Return: Have access ? (true/false)
Index: trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 7681)
+++ trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 7769)
@@ -242,4 +242,34 @@
 		}
 
+        $institutional_accounts = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], ('('.substr($params['anchor'], 0 , strpos($params['anchor'],','))).')');
+        $old  = ldap_get_entries($this->ldap, $institutional_accounts);
+        $oldOwners = array();
+
+
+        foreach($old[0]['mailforwardingaddress'] as $mailP)
+        {
+            $tmp = $this->mailforwardingaddress2uidnumber($mailP);
+            $oldOwners[$tmp['uidnumber']] = true;
+        }
+
+        if (!empty($params['owners']))
+        {
+            foreach($params['owners'] as $index => $uidnumber)
+            {
+                if(array_key_exists($uidnumber, $oldOwners))
+                    unset( $oldOwners[$uidnumber] );
+                else
+                    $this->functions->write_log("User added from the institutional account",'USER: '.$uidnumber.' - SHARED ACCOUNT: '.$params['anchor']);
+            }
+        }
+
+        if(count($oldOwners) > 0)
+            foreach($oldOwners as $i=>$v )
+            {
+                $this->functions->write_log("User removed from the institutional account",'USER: '.$i.' - SHARED ACCOUNT: '.$params['anchor']);
+            }
+
+
+
 		$uid = 'institutional_account_' . $params['mail'];
 		$dn = strtolower("uid=$uid," . $params['context']);
@@ -295,5 +325,5 @@
 		if (!empty($params['owners']))
 		{
-			foreach($params['owners'] as $index=>$uidnumber)
+			foreach($params['owners'] as $index => $uidnumber)
 			{
 				$mailForwardingAddress = $this->uidnumber2mail($uidnumber);
@@ -311,4 +341,7 @@
 			$result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . ldap_error($this->ldap);
 		}
+
+
+        $this->functions->write_log('Update institutional account','Old DN:'.$params['anchor'].' New DN '.$dn);
 
 		return $result;
@@ -2852,5 +2885,7 @@
 			return $return;
 		}
-		
+
+        $this->db_functions->write_log('Removed institutional account',$dn);
+
 		return $return;
 	}
