Index: trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 493)
+++ trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 507)
@@ -55,5 +55,5 @@
 				{
 					$return['status'] = false;
-					$return['msg'] = lang('problems getting user id') . ".\n" . $id['msg'];
+					$return['msg'] = $this->functions->lang('problems getting user id') . ".\n" . $id['msg'];
 					return $return;
 				}
@@ -142,7 +142,7 @@
 							$return['status'] = false;
 							$return['msg'] .= 
-									lang("the binary file /home/expressolivre/mkntpwd does not exist") . ".\\n" .
-									lang("it is needed to create samba passwords") . ".\\n" . 
-									lang("alert your administrator about this") . ".";
+									$this->functions->lang("the binary file /home/expressolivre/mkntpwd does not exist") . ".\\n" .
+									$this->functions->lang("it is needed to create samba passwords") . ".\\n" . 
+									$this->functions->lang("alert your administrator about this") . ".";
 						}
 						else
@@ -310,5 +310,5 @@
 			{
 				$return['status'] = false;
-				$return['msg'] = lang('You do not have access to edit user informations') . '.';
+				$return['msg'] = $this->functions->lang('You do not have access to edit user informations') . '.';
 				return $return;
 			}
@@ -508,5 +508,5 @@
 					{
 						$return['status'] = false;
-						$return['msg'] .= lang('User photo could not be save because is bigger the 10 kb') . '.';
+						$return['msg'] .= $this->functions->lang('User photo could not be save because is bigger the 10 kb') . '.';
 					}
 					else
@@ -712,7 +712,7 @@
 					{
 						$return['status'] = false;
-						$return['msg'] .= lang("The file /home/expressolivre/mkntpwd does not exist") . ".\n";
-						$return['msg'] .= lang("It is necessery to create samba passwords") . ".\n";
-						$return['msg'] .= lang("Inform your system administrator about this") . ".\n";
+						$return['msg'] .= $this->functions->lang("The file /home/expressolivre/mkntpwd does not exist") . ".\n";
+						$return['msg'] .= $this->functions->lang("It is necessery to create samba passwords") . ".\n";
+						$return['msg'] .= $this->functions->lang("Inform your system administrator about this") . ".\n";
 					}
 					else
@@ -898,5 +898,6 @@
 		function get_user_info($uidnumber)
 		{
-			$user_info_ldap = $this->ldap_functions->get_user_info($uidnumber);
+			if (!$user_info_ldap = $this->ldap_functions->get_user_info($uidnumber))
+				return false;
 			$user_info_db1 = $this->db_functions->get_user_info($uidnumber);
 			$user_info_db2 = $this->ldap_functions->gidnumbers2cn($user_info_db1['groups']);
@@ -951,4 +952,5 @@
 		{
 			$return['status'] = true;
+			$this->db_functions->write_log('delete user: start', $params['uid']);
 			
 			// Verifica o acesso do gerente
@@ -956,6 +958,12 @@
 			{
 				$uidnumber = $params['uidnumber'];
-				$user_info = $this->get_user_info($uidnumber);
-			
+				if (!$user_info = $this->get_user_info($uidnumber))
+				{
+					$this->db_functions->write_log('delete user: error getting users info', $user_info['uid']);
+					$return['status'] = false;
+					$return['msg'] = $this->functions->lang('error getting users info');
+					return $return; 
+				}
+
 				//LDAP
 				$result_ldap = $this->ldap_functions->delete_user($user_info);
@@ -963,8 +971,11 @@
 				{
 					$return['status'] = false;
-					$return['msg'] .= $result_ldap['msg'];
+					$return['msg'] = 'user.delete(ldap): ' . $result_ldap['msg'];
+					return $return;
 				}
 				else
 				{
+					$this->db_functions->write_log("deleted users data from ldap", $user_info['uid']);
+					
 					//DB
 					$result_db = $this->db_functions->delete_user($user_info);
@@ -972,7 +983,11 @@
 					{
 						$return['status'] = false;
-						$return['msg'] .= $result_ldap['msg'];
-					}
-			
+						$return['msg'] .= 'user.delete(db): ' . $result_db['msg'];
+					}
+					else
+					{
+						$this->db_functions->write_log("deleted users data from DB", $user_info['uid']);
+					}
+					
 					//IMAP
 					$result_imap = $this->imap_functions->delete_user($user_info['uid']);
@@ -980,10 +995,19 @@
 					{
 						$return['status'] = false;
-						$return['msg'] .= $result_ldap['msg'];
-					}
-					$this->db_functions->write_log('deleted user', $user_info['uid']);
-				}
-			}
-			
+						$return['msg'] .= $result_imap['msg'];
+					}
+					else
+					{
+						$this->db_functions->write_log("deleted users data from IMAP", $user_info['uid']);
+					}
+					
+				}
+			}
+			else
+			{
+				$this->db_functions->write_log('delete user: manager does not have access', $params['uidnumber']);
+			}
+			
+			$this->db_functions->write_log('delete user: end', $user_info['uid']);
 			return $return;
 		}
@@ -998,5 +1022,5 @@
 			{
 				$return['status'] = false;
-				$return['msg'] .= lang('You do not have access to delete user') . '.';
+				$return['msg'] .= $this->functions->lang('You do not have access to delete user') . '.';
 				return $return;
 			}
@@ -1006,5 +1030,5 @@
 			{
 				$return['status'] = false;
-				$return['msg'] = lang('New login already in use') . '.';
+				$return['msg'] = $this->functions->lang('New login already in use') . '.';
 				return $return;
 			}
@@ -1050,11 +1074,11 @@
 				{
 					$return['status'] = false;
-					$return['msg'] = lang("Error rename user in LDAP") . '.';
+					$return['msg'] = $this->functions->lang("Error rename user in LDAP") . '.';
 					return $return;
 				}
 				
         		//Renomeia mailbox
-   	    		$result = $this->imap_functions->rename_mailbox($uid, $new_uid);
-				if (!$result['status'])
+   	    		$imap_rename_result = $this->imap_functions->rename_mailbox($uid, $new_uid);
+				if (!$imap_rename_result['status'])
 				{
 					// Back user uid.
@@ -1062,15 +1086,14 @@
 					
 					$return['status'] = false;
-					$return['msg'] = lang("Erro rename user in Cyrus") . '.';
+					$return['msg']  = $this->functions->lang("Error renaming user mailboxes") . ".\n";
+					$return['msg'] .= $imap_rename_result['msg'];
 					return $return;
 				}
-        			
-
-				// Seta senha default
-				$user_password = $this->ldap_functions->set_user_password($new_uid, $defaultUserPassword);
+        		
 
        			// Renomeia sieve script
        			include_once('sieve-php.lib.php');
-       			$sieve=new sieve($sieve_server, $sieve_port, $new_uid, $defaultUserPassword_plain);
+       			//function sieve($host,         $port,       $user,    $pass,        $auth="",     $auth_types)
+       			$sieve=new sieve($sieve_server, $sieve_port, $new_uid, $imap_passwd, $imap_admin, 'PLAIN');
         			
 				if ($sieve->sieve_login())
@@ -1088,16 +1111,29 @@
 						}
 					}
-
-       				$scriptname = $new_uid;
-					if($sieve->sieve_sendscript($new_uid,$script))
-					{
-						if ($sieve->sieve_setactivescript($new_uid))
-						{
-							$sieve->sieve_deletescript($myactivescript);
-						}
-					}
-					else 
-					{
-						$return['msg'] .= $result['msg'] . lang("Error renome sieve script") . '.';
+					
+					if (!empty($script))
+					{
+	       				$scriptname = $new_uid;
+						if($sieve->sieve_sendscript($new_uid,$script))
+						{
+							if ($sieve->sieve_setactivescript($new_uid))
+							{
+								if (!$sieve->sieve_deletescript($myactivescript))
+								{
+									$return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n";
+									$return['msg'] .= $result['msg'] . $this->functions->lang("Problem deleting old script") . '.';
+								}
+							}
+							else
+							{
+								$return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n";
+								$return['msg'] .= $result['msg'] . $this->functions->lang("Problem activating sieve script") . '.';
+							}
+						}
+						else 
+						{
+							$return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n";
+							$return['msg'] .= $result['msg'] . $this->functions->lang("Problem saving sieve script") . '.';
+						}
 					}
 					$sieve->sieve_logout();
@@ -1106,10 +1142,8 @@
 				{
 						$return['status'] = false;
-						$return['msg'] .= $result['msg'] . lang("Error renome sieve script") . '.';
-				}
-
-				// Back user password.
-				$this->ldap_functions->set_user_password($new_uid, $user_password);
-		
+						$return['msg'] .= $result['msg'] . $this->functions->lang("Error renaming sieve script") . ".\\n";
+						$return['msg'] .= $result['msg'] . $this->functions->lang("Can not login sieve") . '.';
+				}
+
 				$this->db_functions->write_log("renamed user", "$uid -> $new_uid");
 
