Index: /trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 317)
+++ /trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 355)
@@ -266,5 +266,5 @@
 				}
 
-				$this->db_functions->write_log('criado usuario','',$dn,'','');
+				$this->db_functions->write_log("criado usuario $dn",'','','','');
 			}
 
@@ -288,4 +288,5 @@
 			print_r($new_values);
 			echo '<br>';
+			exit;
 			*/
 
@@ -310,16 +311,19 @@
 				if ($diff['context'])
 				{
-					$newrdn = 'uid=' . $new_values['uid'];
-					$newparent = $new_values['context'];
-					$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
-					if (!$result['status'])
-					{
-						$return['status'] = false;
-						$return['msg'] .= $result['msg'];
-					}
-					else
-					{
-						$dn = $newrdn . ',' . $newparent;
-						$this->db_functions->write_log('alterado contexto do usuario','',$dn,'','');
+					if (strcasecmp($old_values['context'], $new_values['context']) != 0)
+					{
+						$newrdn = 'uid=' . $new_values['uid'];
+						$newparent = $new_values['context'];
+						$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
+						if (!$result['status'])
+						{
+							$return['status'] = false;
+							$return['msg'] .= $result['msg'];
+						}
+						else
+						{
+							$dn = $newrdn . ',' . $newparent;
+							$this->db_functions->write_log('alterado contexto do usuario' . $new_values['uid'] . ' de: ' . $old_values['context'] . ' para: ' . $new_values['context'],'',$dn,'','');
+						}
 					}
 				}
@@ -331,5 +335,5 @@
 					$ldap_mod_replace['givenname'] = $new_values['givenname'];
 					$ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn'];
-					$this->db_functions->write_log("alterado givenname do usuario",'',$dn,'','');
+					$this->db_functions->write_log("alterado givenname do usuario $dn de ".$old_values['givenname']." para ".$new_values['givenname'],'','','','');
 				}
 				if ($diff['sn'])
@@ -337,5 +341,5 @@
 					$ldap_mod_replace['sn'] = $new_values['sn'];
 					$ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn'];
-					$this->db_functions->write_log("altera$ldap_mod_do sn do usuario",'',$dn,'','');
+					$this->db_functions->write_log("altera sn do usuario de ".$old_values['sn']." para ".$new_values['sn'],'','','','');
 				}
 				if ($diff['mail'])
@@ -344,5 +348,5 @@
 					$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,'','');
+					$this->db_functions->write_log("alterado mail do usuario $dn de " . $old_values['mail'] . " para " . $new_values['mail'],'','','','');
 				}
 				/*
@@ -363,5 +367,5 @@
 				{
 					$ldap_mod_replace['phpgwlastpasswdchange'] = '0';
-					$this->db_functions->write_log("Expirado senha do usuário",'',$dn,'','');
+					$this->db_functions->write_log("Expirado senha do usuário $dn",'','','','');
 				}
 			}
@@ -395,5 +399,5 @@
 					}
 					
-					$this->db_functions->write_log("alterado password do usuario",'',$dn,'','');
+					$this->db_functions->write_log("alterado password do usuario $dn",'','','','');
 				}
 			}
@@ -405,5 +409,5 @@
 				{
 					$ldap_mod_replace['telephonenumber'] = $new_values['telephonenumber'];
-					$this->db_functions->write_log("alterado telephonenumber do usuario",'',$dn,'','');
+					$this->db_functions->write_log("alterado telephonenumber do usuario $dn de ".$old_values['telephonenumber']." para ".$new_values['telephonenumber'],'','','','');
 				}
 			}
@@ -426,5 +430,5 @@
 							$ldap_atribute = str_replace("corporative_information_", "", $atribute);
 							$ldap_mod_replace[$ldap_atribute] = $new_values[$atribute];
-							$this->db_functions->write_log("alterado $ldap_atribute do usuario",'',$dn,'','');
+							$this->db_functions->write_log("alterado $ldap_atribute do usuario $dn de ".$old_values[$atribute]." para ".$new_values[$atribute],'','','','');
 						}
 						//ADD ATTRS OF CORPORATIVE
@@ -432,5 +436,5 @@
 						{
 							$ldap_add[$ldap_atribute] = $new_values[$atribute];
-							$this->db_functions->write_log("adicionado $ldap_atribute ao usuario",'',$dn,'','');
+							$this->db_functions->write_log("adicionado $ldap_atribute ao usuario $dn de ".$old_values[$atribute]." para ".$new_values[$atribute],'','','','');
 						}
 						//REMOVE ATTRS OF CORPORATIVE
@@ -438,5 +442,5 @@
 						{
 							$ldap_remove[$ldap_atribute] = array();
-							$this->db_functions->write_log("removido $ldap_atribute do usuario",'',$dn,'','');	
+							$this->db_functions->write_log("removido $ldap_atribute do usuario $dn de ".$old_values[$atribute]." para ".$new_values[$atribute],'','','','');	
 						}
 					}
@@ -448,20 +452,33 @@
 			     ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) )
 			{
+				
+				if ($diff['gidnumber'])
+				{
+					$ldap_mod_replace['gidnumber'] = $new_values['gidnumber'];
+					$this->db_functions->write_log("alterado gidnumber do usuario $dn. De:".$old_values['gidnumber']." Para:".$new_values['gidnumber'],'','','','');
+				}
+				
 				if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on'))
 				{
+					if ($diff['gidnumber'])
+					{
+						$ldap_mod_replace['sambaPrimaryGroupSID']	= $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['gidnumber'])+1001);
+						$this->db_functions->write_log("alterado sambaPrimaryGroupSID do usuario $dn.",'','','','');
+					}
+					
 					if ($diff['sambaacctflags'])
 					{
 						$ldap_mod_replace['sambaacctflags'] = $new_values['sambaacctflags'];
-						$this->db_functions->write_log("alterado sambaacctflags do usuario",'',$dn,'','');
+						$this->db_functions->write_log("alterado sambaacctflags do usuario $dn",'','','','');
 					}
 					if ($diff['sambalogonscript'])
 					{
 						$ldap_mod_replace['sambalogonscript'] = $new_values['sambalogonscript'];
-						$this->db_functions->write_log("alterado sambalogonscript do usuario",'',$dn,'','');
+						$this->db_functions->write_log("alterado sambalogonscript do usuario $dn",'','','','');
 					}
 					if ($diff['sambahomedirectory'])
 					{
 						$ldap_mod_replace['homedirectory'] = $new_values['sambahomedirectory'];
-						$this->db_functions->write_log("alterado homedirectory do usuario",'',$dn,'','');
+						$this->db_functions->write_log("alterado homedirectory do usuario $dn",'','','','');
 					}
 					if ($diff['sambadomain'])
@@ -469,5 +486,5 @@
 						$ldap_mod_replace['sambaSID']				= $diff['sambadomain'] . '-' . ((2 * $old_values['uidnumber'])+1000);
 						$ldap_mod_replace['sambaPrimaryGroupSID']	= $diff['sambadomain'] . '-' . ((2 * $old_values['gidnumber'])+1001);
-						$this->db_functions->write_log("alterado dominio samba do usuario $dn para " . $params['sambadomain'],'',$dn,'','');
+						$this->db_functions->write_log("alterado dominio samba do usuario $dn para " . $params['sambadomain'],'','','','');
 					}
 				}
@@ -485,5 +502,5 @@
 				{
 					$this->ldap_functions->ldap_remove_photo($dn);
-					$this->db_functions->write_log("removido jpegphoto do usuario",'',$dn,'','');
+					$this->db_functions->write_log("removido jpegphoto do usuario $dn",'','','','');
 				}
 				elseif ($_FILES['photo']['name'] != '')
@@ -500,10 +517,10 @@
 						{
 							$photo_exist = true;
-							$this->db_functions->write_log("substituido jpegphoto do usuario",'',$dn,'','');
+							$this->db_functions->write_log("substituido jpegphoto do usuario $dn",'','','','');
 						}
 						else
 						{
 							$photo_exist = false;
-							$this->db_functions->write_log("adicionado jpegphoto ao usuario",'',$dn,'','');
+							$this->db_functions->write_log("adicionado jpegphoto ao usuario $dn",'','','','');
 						}				
 						$this->ldap_functions->ldap_save_photo($dn, $_FILES['photo']['tmp_name'], $new_values['photo_exist'], $photo_exist);
@@ -520,10 +537,10 @@
 				{
 					$ldap_add['telephonenumber'] = $new_values['telephonenumber'];
-					$this->db_functions->write_log("adicionado telephonenumber ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("adicionado telephonenumber ao usuario $dn",'','','','');
 				}
 				if (($old_values['telephonenumber'] != '') && ($new_values['telephonenumber'] == ''))
 				{
 					$ldap_remove['telephonenumber'] = array();
-					$this->db_functions->write_log("removido telephonenumber do usuario",'',$dn,'','');
+					$this->db_functions->write_log("removido telephonenumber do usuario $dn",'','','','');
 				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -532,10 +549,10 @@
 				{
 					$ldap_add['phpgwlastpasswdchange'] = '0';
-					$this->db_functions->write_log("Expirado senha do usuário",'',$dn,'','');
+					$this->db_functions->write_log("Expirado senha do usuário $dn",'','','','');
 				}
 				if (($old_values['passwd_expired'] == '0') && ($new_values['passwd_expired'] == ''))
 				{
 					$ldap_remove['phpgwlastpasswdchange'] = array();
-					$this->db_functions->write_log("Removido expiração da senha do usuário",'',$dn,'','');
+					$this->db_functions->write_log("Removido expiração da senha do usuário $dn",'','','','');
 				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -544,10 +561,10 @@
 				{
 					$this->db_functions->add_pref_changepassword($new_values['uidnumber']);
-					$this->db_functions->write_log("adicionado changepassword ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("adicionado changepassword ao usuario $dn",'','','','');
 				}
 				if (($old_values['changepassword'] != '') && ($new_values['changepassword'] == ''))
 				{
 					$this->db_functions->remove_pref_changepassword($new_values['uidnumber']);
-					$this->db_functions->write_log("removido changepassword do usuario",'',$dn,'','');
+					$this->db_functions->write_log("removido changepassword do usuario $dn",'','','','');
 				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -556,10 +573,10 @@
 				{
 					$ldap_add['phpgwaccountstatus'] = 'A';
-					$this->db_functions->write_log("ativado conta do usuario",'',$dn,'','');
+					$this->db_functions->write_log("ativado conta do usuario $dn",'','','','');
 				}
 				if (($old_values['phpgwaccountstatus'] != '') && ($new_values['phpgwaccountstatus'] == ''))
 				{
 					$ldap_remove['phpgwaccountstatus'] = array();
-					$this->db_functions->write_log("desativado conta do usuario",'',$dn,'','');
+					$this->db_functions->write_log("desativado conta do usuario $dn",'','','','');
 				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -568,10 +585,10 @@
 				{
 					$ldap_add['phpgwaccountvisible'] = '-1';
-					$this->db_functions->write_log("adicionado phpgwaccountvisible ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("adicionado phpgwaccountvisible ao usuario $dn",'','','','');
 				}
 				if (($old_values['phpgwaccountvisible'] != '') && ($new_values['phpgwaccountvisible'] == ''))
 				{
 					$ldap_remove['phpgwaccountvisible'] = array();
-					$this->db_functions->write_log("removido phpgwaccountvisible ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("removido phpgwaccountvisible ao usuario $dn",'','','','');
 				}
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -580,10 +597,10 @@
 				{
 					$ldap_add['accountstatus'] = 'active';
-					$this->db_functions->write_log("ativado conta de email do usuario",'',$dn,'','');
+					$this->db_functions->write_log("ativado conta de email do usuario $dn",'','','','');
 				}
 				if (($old_values['accountstatus'] != '') && ($new_values['accountstatus'] == ''))
 				{
 					$ldap_remove['accountstatus'] = array();
-					$this->db_functions->write_log("desativado conta de email do usuario",'',$dn,'','');
+					$this->db_functions->write_log("desativado conta de email do usuario $dn",'','','','');
 				}
 				/*
@@ -675,10 +692,10 @@
 				{
 					$ldap_add['deliverymode'] = 'forwardOnly';
-					$this->db_functions->write_log("adicionado forwardOnly ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("adicionado forwardOnly ao usuario $dn",'','','','');
 				}
 				if (($old_values['deliverymode'] != '') && ($new_values['deliverymode'] == ''))
 				{
 					$ldap_remove['deliverymode'] = array();
-					$this->db_functions->write_log("removido forwardOnly ao usuario",'',$dn,'','');
+					$this->db_functions->write_log("removido forwardOnly ao usuario $dn",'','','','');
 				}
 			}
@@ -692,5 +709,5 @@
 				{
 					$this->imap_functions->change_user_quota($new_values['uid'], $new_values['mailquota']);
-					$this->db_functions->write_log("alterado cota do usuario",'',$dn,'','');
+					$this->db_functions->write_log("alterado cota do usuario $dn",'','','','');
 				}
 			}
@@ -715,5 +732,5 @@
 					$ldap_remove['sambaPwdLastSet']			= array();
 					$ldap_remove['sambaPwdMustChange']		= array();
-					$this->db_functions->write_log("removido atributos samba do usuario.",'',$dn,'','');
+					$this->db_functions->write_log("removido atributos samba do usuario $dn.",'','','','');
 				}
 				//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -742,5 +759,5 @@
 						$ldap_add['sambaPwdLastSet']		= strtotime("now");
 						$ldap_add['sambaPwdMustChange']	= '2147483647';
-						$this->db_functions->write_log("adicionado atributos samba do usuario.",'',$dn,'','');
+						$this->db_functions->write_log("adicionado atributos samba ao usuario $dn.",'','','','');
 					}
 				}
@@ -765,5 +782,5 @@
 						$this->db_functions->add_user2group($gidnumber, $new_values['uidnumber']);
 						$this->ldap_functions->add_user2group($gidnumber, $new_values['uid']);
-						$this->db_functions->write_log("adicionado usuario ao grupo $gidnumber.",'',$dn,'','');
+						$this->db_functions->write_log("adicionado usuario $dn ao grupo $gidnumber.",'','','','');
 					}
 				}
@@ -779,10 +796,11 @@
 								$this->db_functions->remove_user2group($gidnumber, $new_values['uidnumber']);
 								$this->ldap_functions->remove_user2group($gidnumber, $new_values['uid']);
-								$this->db_functions->write_log("removido usuario do grupo $gidnumber.",'',$dn,'','');
+								$this->db_functions->write_log("removido usuario $dn do grupo $gidnumber.",'','','','');
 							}
 						}
 					}
 				}
-
+				/* GIDNUMBER agora é um atributo samba e pode ser alterado por gerentes com este perfil
+				/*
 				if ($diff['gidnumber'])
 				{
@@ -794,4 +812,5 @@
 					$this->db_functions->write_log("alterado gidnumber do usuario.",'',$dn,'','');
 				}
+				*/
 			}
 			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -854,5 +873,5 @@
 					{
 						$this->ldap_functions->add_user2maillist($uid, $new_values['mail']);
-						$this->db_functions->write_log("adicionado usuario a maillist $uid.",'',$dn,'','');
+						$this->db_functions->write_log("adicionado usuario $dn a maillist $uid.",'','','','');
 					}
 				}
@@ -868,5 +887,5 @@
 					{
 						$this->ldap_functions->remove_user2maillist($uid, $new_values['mail']);
-						$this->db_functions->write_log("removido usuario da maillist $uid.",'',$dn,'','');
+						$this->db_functions->write_log("removido usuario $dn da maillist $uid.",'','','','');
 					}
 				}
@@ -947,5 +966,5 @@
 			}
 			
-			$this->db_functions->write_log('Setado senha default','',$uid,'','');
+			$this->db_functions->write_log("Setado senha default para $uid",'','','','');
 			
 			return $return;
@@ -968,5 +987,5 @@
 			}
 			
-			$this->db_functions->write_log('Retornado senha default','',$uid,'','');
+			$this->db_functions->write_log("Retornado senha default de $uid",'','','','');
 			
 			return $return;
@@ -1007,5 +1026,5 @@
 						$return['msg'] .= $result_ldap['msg'];
 					}
-					$this->db_functions->write_log('deletado usuario','',$user_info['uid'],'','');
+					$this->db_functions->write_log('deletado usuario ' . $user_info['uid'],'','','','');
 				}
 			}
@@ -1122,5 +1141,5 @@
 					$this->ldap_functions->set_user_password($new_uid, $user_password);
 			
-					$this->db_functions->write_log('renomeado usuario',$new_uid,$uid,'','');
+					$this->db_functions->write_log("renomeado login do usuario $uid para $new_uid.",'','','','');
 
 					$return['exec_return'] = "";
Index: /trunk/expressoAdmin1_2/inc/class.maillist.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.maillist.inc.php	(revision 283)
+++ /trunk/expressoAdmin1_2/inc/class.maillist.inc.php	(revision 355)
@@ -144,17 +144,20 @@
 			if ($diff['context'] || $diff['uid'])
 			{
-				$newrdn = 'uid=' . $new_values['uid'];
-				$newparent = $new_values['context'];
-				$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
-				if (!$result['status'])
-				{
-					$return['status'] = false;
-					$return['msg'] .= $result['msg'];
-				}
-				else
-				{
-					$dn = $newrdn . ',' . $newparent;
-					$old_dn = $old_values['uid'];
-					$this->db_functions->write_log("Renomeado login da lista de $old_dn para $dn",'',$dn,$old_values['uid'],'');
+				if ( (strcasecmp($old_values['uid'], $new_values['uid']) != 0) || (strcasecmp($old_values['context'], $new_values['context']) != 0) )
+				{
+					$newrdn = 'uid=' . $new_values['uid'];
+					$newparent = $new_values['context'];
+					$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
+					if (!$result['status'])
+					{
+						$return['status'] = false;
+						$return['msg'] .= $result['msg'];
+					}
+					else
+					{
+						$dn = $newrdn . ',' . $newparent;
+						$old_dn = $old_values['uid'];
+						$this->db_functions->write_log("Renomeado login da lista de $old_dn para $dn",'',$dn,$old_values['uid'],'');
+					}
 				}
 			}
Index: /trunk/expressoAdmin1_2/inc/class.group.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 317)
+++ /trunk/expressoAdmin1_2/inc/class.group.inc.php	(revision 355)
@@ -168,16 +168,19 @@
 			if ($diff['context'] || $diff['cn'])
 			{
-				$newrdn = 'cn=' . $new_values['cn'];
-				$newparent = $new_values['context'];
-				$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
-				if (!$result['status'])
-				{
-					$return['status'] = false;
-					$return['msg'] .= $result['msg'];
-				}
-				else
-				{
-					$dn = $newrdn . ',' . $newparent;
-					$this->db_functions->write_log('Renomeado grupo de usuários de '.$old_values['cn']." para $dn.",'',$dn,$old_values['cn'],'');
+				if ( (strcasecmp($old_values['cn'], $new_values['cn']) != 0) || (strcasecmp($old_values['context'], $new_values['context']) != 0) )
+				{
+					$newrdn = 'cn=' . $new_values['cn'];
+					$newparent = $new_values['context'];
+					$result =  $this->ldap_functions->change_user_context($dn, $newrdn, $newparent);
+					if (!$result['status'])
+					{
+						$return['status'] = false;
+						$return['msg'] .= $result['msg'];
+					}
+					else
+					{
+						$dn = $newrdn . ',' . $newparent;
+						$this->db_functions->write_log('Renomeado grupo de usuários de '.$old_values['cn']." para $dn.",'',$dn,$old_values['cn'],'');
+					}
 				}
 			}
Index: /trunk/expressoAdmin1_2/inc/class.uilogs.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.uilogs.inc.php	(revision 309)
+++ /trunk/expressoAdmin1_2/inc/class.uilogs.inc.php	(revision 355)
@@ -92,5 +92,5 @@
 				}
 				
- 				$query .= " ORDER by manager ASC, date DESC"; 
+ 				$query .= " ORDER by date DESC"; 
  				
 				$GLOBALS['phpgw']->db->query($query);
@@ -136,9 +136,16 @@
 					//_debug_array($log);
 					$this->nextmatchs->template_alternate_row_color($p);
-
+					
+					//Date treatment
+					$a_date = split(" ", $log['date']);
+					$a_day = split("-", $a_date[0]);
+					$a_day_tmp = array_reverse($a_day);
+					$a_day = join($a_day_tmp, "/");
+					$a_hour = split("\.", $a_date[1]);
+					
 					$var = array(
 						'row_manager_lid'	=> $log['manager'],
 						'row_action'		=> $log['action'],
-						'row_date' 			=> $log['date'],
+						'row_date' 			=> $a_day . '  ' . $a_hour[0],
 						//'row_view'  => (!$account['account_lastname']?'&nbsp':$account['account_lastname'])
 					);
Index: /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 317)
+++ /trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 355)
@@ -7,4 +7,7 @@
 function ldapRebind($ldap_connection, $ldap_url)
 {
+	// Enquanto estivermos utilizando referral na arvore ldap, teremos que continuar a utilizar o usuário sistemas:expresso.
+	// Depois, quando não existir mais referral, não existirá a necessidade de ldapRebind.
+	//ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
 	if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') )
 	{
@@ -20,9 +23,21 @@
 	var $manager_contexts;
 	
-	function ldap_functions(){
+	function ldap_functions(){		
 		$GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
 		$this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin'];
 		$common = new common();
-		$this->ldap = $common->ldapConnect();
+		
+		if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
+			 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
+			 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
+		{
+			$this->ldap = $common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
+											   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
+											   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
+		}
+		else
+		{
+			$this->ldap = $common->ldapConnect();
+		}
 		
 		$this->functions = new functions;
@@ -31,8 +46,35 @@
 	}
 	
-	/* ldap connection following referals and using Contac Center config*/
+	/* expressoAdmin: email lists : deve utilizar o ldap Host Master com o usuario e senha do CC*/
+	/* ldap connection following referrals and using Master config, from setup */
 	function ldapMasterConnect()
 	{
-		if ( (is_array($_SESSION['phpgw_info']['expresso']['cc_ldap_server'])) && ($ldap_connection = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host'])) )
+		/*
+		$common = new common();
+		if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
+			 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
+			 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
+		{
+			$ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_master_host']);
+			ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3);
+			ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, true);
+			ldap_set_rebind_proc($ldap_connection, ldapRebind);
+			ldap_bind($ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
+		}
+		else
+		{
+			$ldap_connection = $common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_host'],
+											   $GLOBALS['phpgw_info']['server']['ldap_root_dn'],
+											   $GLOBALS['phpgw_info']['server']['ldap_root_pw'], true);
+		}
+		
+		// If success, return follow_referral connection. Else, return normal connection.
+		if ($ldap_connection)
+			return $ldap_connection;
+		else
+			return $this->ldap;
+		*/
+		
+		if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && ($ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_master_host'])) )
 		{
 			ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3);
@@ -101,4 +143,5 @@
 		$mail = $params['mail'];
 		$mailalternateaddress = $params['mailalternateaddress'];
+		$cpf = $params['cpf'];
 				
 		if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid])
@@ -265,4 +308,61 @@
 		}
 
+		//Begin: Check CPF
+		if (!empty($cpf))
+		{
+			if (!$this->functions->checkCPF($cpf))
+			{
+				$result['status'] = false;
+				$result['msg'] = $this->functions->lang('Field CPF is invalid') . '.';
+				return $result;
+			}
+			else
+			{
+				$local_ldap_connection = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
+				if ($ldap_connection)
+				{
+					ldap_set_option($local_ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3);
+					ldap_set_option($local_ldap_connection, LDAP_OPT_REFERRALS, false);
+					ldap_bind($local_ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_root_dn'], $GLOBALS['phpgw_info']['server']['ldap_root_pw']);
+				}
+				else
+				{
+					$result['status'] = false;
+					$result['msg'] = 'Falha na conexao com o ldap.';
+					return $result;
+				}
+				
+				$filter = "(&(phpgwAccountType=u)(cpf=$cpf))";
+				$justthese = array("cn","uid");
+				$search = ldap_search($local_ldap_connection, $context, $filter, $justthese);
+				$entries = ldap_get_entries($local_ldap_connection,$search);
+				
+				if ( ($entries['count'] == 1) && (strcasecmp($uid, $entries[0]['uid'][0]) == 0) )
+				{}
+				else
+				{
+					if ($entries['count'] > 0)
+					{
+						$result['question'] = $this->functions->lang('Field CPF used by') . ":\n";
+						for ($i=0; $i<$entries['count']; $i++)
+						{
+							if (strcasecmp($uid, $entries[$i]['uid'][0]) != 0)
+								$result['question'] .= "- " . $entries[$i]['cn'][0] . "\n";
+						}
+						$result['question'] .= $this->functions->lang("Do you want to continue anyway") . "?";
+						return $result;
+					}
+				}
+				ldap_close($local_ldap_connection);
+			}
+		}
+		else if ($this->current_config['expressoAdmin_cpf_obligation'])
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('Field CPF must be completed') . '.';
+			return $result;
+		}
+		//End: Check CPF
+
 		return $result;
 	}
@@ -1357,8 +1457,10 @@
 		
 		$return['status'] = true;
-		
+		$return['msg'] = "";
+				
 		// GROUPS
 		$attrs = array();
-		$attrs['memberUid'] = $user_info['uid'];
+		$attrs['memberuid'] = $user_info['uid'];
+		
 		if (count($user_info['groups_info']))
 		{
@@ -1371,9 +1473,9 @@
 	    		$entry = ldap_get_entries($this->ldap, $search);
 				$dn = $entry[0]['dn'];
-			
+
 				if (!@ldap_mod_del($this->ldap, $dn, $attrs))
 				{
 					$return['status'] = false;
-					$return['msg'] .= 'Erro em ldap_funcitons->delete_user, grupos: ' . ldap_error($this->ldap);
+					$return['msg'] .= "Erro em ldap_functions->delete_user from group ($dn): " . ldap_error($this->ldap);
 				}
 			}
Index: /trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- /trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 317)
+++ /trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 355)
@@ -747,4 +747,53 @@
 				return $key . '*';
 		}
+		
+		
+		function checkCPF($cpf)
+		{
+			$nulos = array("12345678909","11111111111","22222222222","33333333333",
+        		       "44444444444","55555555555","66666666666","77777777777",
+            		   "88888888888","99999999999","00000000000");
+
+			/* Retira todos os caracteres que nao sejam 0-9 */
+			$cpf = ereg_replace("[^0-9]", "", $cpf);
+
+			/*Retorna falso se houver letras no cpf */
+			if (!(ereg("[0-9]",$cpf)))
+    			return false;
+
+			/* Retorna falso se o cpf for nulo */
+			if( in_array($cpf, $nulos) )
+    			return false;
+
+			/*Calcula o penúltimo dígito verificador*/
+			$acum=0;
+			for($i=0; $i<9; $i++)
+			{
+  				$acum+= $cpf[$i]*(10-$i);
+			}
+
+			$x=$acum % 11;
+			$acum = ($x>1) ? (11 - $x) : 0;
+			/* Retorna falso se o digito calculado eh diferente do passado na string */
+			if ($acum != $cpf[9]){
+  				return false;
+			}
+			/*Calcula o último dígito verificador*/
+			$acum=0;
+			for ($i=0; $i<10; $i++)
+			{
+  				$acum+= $cpf[$i]*(11-$i);
+			}
+
+			$x=$acum % 11;
+			$acum = ($x > 1) ? (11-$x) : 0;
+			/* Retorna falso se o digito calculado eh diferente do passado na string */
+			if ( $acum != $cpf[10])
+			{
+  				return false;
+			}
+			/* Retorna verdadeiro se o cpf eh valido */
+			return true;
+		}
 	}
 	
Index: /trunk/expressoAdmin1_2/js/jscode/users.js
===================================================================
--- /trunk/expressoAdmin1_2/js/jscode/users.js	(revision 309)
+++ /trunk/expressoAdmin1_2/js/jscode/users.js	(revision 355)
@@ -56,4 +56,6 @@
 	}
 
+	/* Validation cpf is in php now.
+	/*
 	if (document.forms[0].corporative_information_cpf.value != "")
 	{
@@ -73,5 +75,5 @@
 			return;
 		}
-	}
+	}*/
 	
 	//MAIL
@@ -150,9 +152,11 @@
 	}
 
-	// Uid & Mail exist?
+	// Uid, Mail and CPF exist?
 	var attrs_array = new Array();
 	attrs_array['type'] = type;
 	attrs_array['uid'] = document.forms[0].uid.value;
 	attrs_array['mail'] = document.forms[0].mail.value;
+	attrs_array['cpf'] = document.forms[0].corporative_information_cpf.value;
+	
 	if (document.forms[0].mailalternateaddress.value != '')
 		attrs_array['mailalternateaddress'] = document.forms[0].mailalternateaddress.value;
@@ -165,4 +169,9 @@
 		else
 		{
+			if ( (data.question) && (!confirm(data.question)) )
+			{
+				return false;
+			}
+
 			if (type == 'create_user')
 			{
Index: /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 317)
+++ /trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 355)
@@ -250,5 +250,5 @@
 			<td colspan="4" align="left">
 				{lang_primary_group}:
-				<select id="ea_combo_primary_user_group" name="gidnumber" {disabled}>{ea_combo_primary_user_group_options}</select>
+				<select id="ea_combo_primary_user_group" name="gidnumber" {disabled_samba}>{ea_combo_primary_user_group_options}</select>
 			</td>
 		</tr>
Index: /trunk/expressoAdmin1_2/templates/default/config.tpl
===================================================================
--- /trunk/expressoAdmin1_2/templates/default/config.tpl	(revision 283)
+++ /trunk/expressoAdmin1_2/templates/default/config.tpl	(revision 355)
@@ -125,4 +125,13 @@
 		</td>
 	</tr>
+	<tr class="row_off">
+		<td>{lang_Does_CPF_field_must_be_completed}?</td>
+		<td>
+			<select name="newsettings[expressoAdmin_cpf_obligation]">
+				<option value="0" {selected_expressoAdmin_cpf_obligation_0}>{lang_no}</option>
+				<option value="1" {selected_expressoAdmin_cpf_obligation_1}>{lang_yes}</option>
+			</select>			
+		</td>
+	</tr>
 
 	<tr class="th">
