Index: sandbox/webservice/api/rest/admin/DeleteUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/DeleteUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/DeleteUserResource.php	(revision 7810)
@@ -0,0 +1,56 @@
+<?php
+
+class DeleteUserResource extends AdminAdapter
+{
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if( $this->isLoggedIn() )
+		{
+			// Permission
+			$permission = array();
+			$permission['action'] = 'delete_users';
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				$uidUser 		= $this->getParam('account_uid_del');
+				$uidNumberUser	= $this->getParam('account_uidnumber_del');
+
+				//Field Validation
+				if(trim($uidUser) == "" && isset($uidUser))
+					Errors::runException( "ADMIN_UID_EMPTY" );
+
+				if(trim($uidNumberUser) == "" && isset($uidNumberUser))	
+					Errors::runException( "ADMIN_UIDNUMBER_EMPTY" );
+
+				// Delete User
+				$params = array();
+				$params['uid'] = $uidUser;
+				$params['uidnumber'] = $uidNumberUser;
+
+				$msg = $this->deleteUser( $params );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_DELETE_USER", $msg['msg'] );
+				}
+
+				$this->setResult( array( "result" => true ) );
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}			
+		}
+		
+		return $this->getResponse();
+	}
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/UpdateUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/UpdateUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/UpdateUserResource.php	(revision 7810)
@@ -0,0 +1,148 @@
+<?php
+
+require_once("CommonFunctions.php");
+
+class UpdateUserResource extends AdminAdapter
+{
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if( $this->isLoggedIn() )
+		{
+ 			// Permission
+			$permission = array();
+			$permission['action'] = 'edit_users';
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				//Class CommonFunctions
+				$common	= new CommonFunctions();
+
+				$uidNumber		= trim($this->getParam('account_uidnumber_up'));
+				$loginUser 		= trim($this->getParam('account_login_up'));
+				$emailUser		= trim($this->getParam('account_email_up'));
+				$nameUser		= trim($this->getParam('account_name_up'));
+				$passwordUser	= trim($this->getParam('account_password_up'));
+				$rePasswordUser	= trim($this->getParam('account_re_password_up'));
+				$phoneUser		= trim($this->getParam('account_phone_up'));
+				$cpfUser		= trim($this->getParam('account_cpf_up'));
+				$rgUser			= trim($this->getParam('account_rg_up'));
+				$rgUF			= trim($this->getParam('account_rg_uf_up'));
+				$description 	= trim($this->getParam('account_description_up'));
+
+				// Field Validation
+				if( trim($uidNumber) == "" && isset($uidNumber) )
+					Errors::runException( "ADMIN_UIDNUMBER_EMPTY" );
+				
+				if( trim($loginUser) == "" && isset($loginUser) )	
+					Errors::runException( "ADMIN_LOGIN_EMPTY" );
+
+				// If rgUser and rgUF
+				if( (trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ) )
+				{
+					Errors::runException("ADMIN_RG_UF_EMPTY");
+				}
+
+				// If not empty
+				if( trim($passwordUser) != "" && trim($rePasswordUser) != "" )
+				{	
+					if( isset($passwordUser) && isset($rePasswordUser) )
+					{
+						// password and repassword are different ? 				
+						if( trim($passwordUser) != trim($rePasswordUser) )
+						{
+							Errors::runException( "ADMIN_PASSWORD_REPASSWORD" );
+						}
+					
+						// validate password, 8 characteres minimum and 2 numbers
+						$msg = $common->validatePassword($passwordUser);
+
+						if( $msg['status'] == false )
+						{
+							Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']);
+						}
+					}
+				}
+
+				// CPF is invalid
+				if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) )
+				{
+					Errors::runException( "ADMIN_CPF_INVALID" );
+				}
+
+				// Characters not permited login
+				$msg = $common->validateCharacters($loginUser);
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+
+				// Params - Validade / Update Fields
+				$fields = array();
+				$fields['type'] 		= "edit_user";
+				$fields['uid']			= $loginUser;
+				$fields['uidnumber'] 	= $uidNumber;
+				$fields['mail']			= $emailUser;
+				$fields['cpf']			= $common->mascaraCPF($cpfUser);
+
+				// Validate Fields
+				$msg = $this->validateFields( array("attributes" => serialize($fields)) );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+
+				//Name User
+				$nameUser = explode(" ", $nameUser);
+				
+				$fields['givenname'] = $nameUser[0]; 
+				
+				if( count($nameUser) > 1 )
+				{
+					unset( $nameUser[0] );
+				}
+
+				if( trim($passwordUser) != "" )
+				{
+					$fields['password1'] = $passwordUser;
+					$fields['password2'] = $rePasswordUser;
+				}
+
+				$fields['sn'] 				= implode(" ", $nameUser );	
+				$fields['telephonenumber']				= $common->mascaraPhone($phoneUser);
+				$fields['corporative_information_cpf']	= $common->mascaraCPF($cpfUser);
+				$fields['corporative_information_rg'] 	= $rgUser;
+				$fields['corporative_information_rguf']	= $rgUF;
+				$fields['corporative_information_description'] = $description;
+
+				// Update Fields
+				unset($fields['cpf']);
+
+				$msg = $this->updateUser($fields);
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_UPDATE_USER", $msg['msg'] );
+				}
+
+				$this->setResult( array( "result" => true ) );
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}			
+		}
+
+		return $this->getResponse();	
+ 	}	
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/CreateUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/CreateUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/CreateUserResource.php	(revision 7810)
@@ -0,0 +1,146 @@
+<?php
+
+require_once("CommonFunctions.php");
+
+class CreateUserResource extends AdminAdapter
+{
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+ 		if( $this->isLoggedIn() )
+		{
+			// Permission
+			$permission = array();
+			$permission['action'] = 'add_users';
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				//Class CommonFunctions
+				$common	= new CommonFunctions();
+
+				$loginUser 		= trim($this->getParam('account_login'));
+				$emailUser		= trim($this->getParam('account_email'));
+				$nameUser		= trim($this->getParam('account_name'));
+				$profileUser	= trim($this->getParam('account_profile'));
+				$passwordUser	= trim($this->getParam('account_password'));
+				$rePasswordUser	= trim($this->getParam('account_re_password'));
+				$phoneUser		= trim($this->getParam('account_phone'));
+				$cpfUser		= trim($this->getParam('account_cpf'));
+				$rgUser			= trim($this->getParam('account_rg'));
+				$rgUF			= trim($this->getParam('account_rg_uf'));
+				$description 	= trim($this->getParam('account_description'));
+
+				// Field Validation
+				if( trim($loginUser) == "" && isset($loginUser) )	
+					Errors::runException( "ADMIN_LOGIN_EMPTY" );
+
+				if( trim($nameUser) == "" && isset($nameUser) )
+					Errors::runException( "ADMIN_NAME_EMPTY" );
+
+				if( trim($profileUser) == "" && isset($profileUser) )
+					Errors::runException( "ADMIN_PROFILE_USER_EMPTY" );
+				
+				if( trim($emailUser) == "" && isset($emailUser) )
+					Errors::runException( "ADMIN_EMAIL_EMPTY" );
+
+				if( trim($passwordUser) == "" && isset($passwordUser) )
+					Errors::runException( "ADMIN_PASSWORD_EMPTY" );
+
+				if( trim($rePasswordUser) == "" && isset($rePasswordUser) )
+					Errors::runException( "ADMIN_RE_PASSWORD_EMPTY" );
+			
+				//If rgUser and rgUF
+				if((trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ))
+				{
+					Errors::runException("ADMIN_RG_UF_EMPTY");
+				}
+
+				// password and repassword are different ? 				
+				if( trim($passwordUser) != trim($rePasswordUser) )
+				{
+					Errors::runException( "ADMIN_PASSWORD_REPASSWORD" );
+				}
+				
+				// validate password, 8 characteres minimum and 2 numbers
+				$msg = $common->validatePassword($passwordUser);
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']);
+				}
+
+				// CPF is invalid
+				if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) )
+				{
+					Errors::runException( "ADMIN_CPF_INVALID" );
+				}
+
+				// Characters not permited login
+				$msg = $common->validateCharacters($loginUser);
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+
+				// Params
+				$fields = array();
+				$fields['profileUser'] 	= $profileUser;
+				$fields['type'] 		= "create_user";
+				$fields['uid']			= $loginUser;
+				$fields['mail']			= $emailUser;
+
+				//Name User
+				$nameUser = explode(" ", $nameUser);
+				$fields['givenname'] = $nameUser[0]; 
+				if( count($nameUser) > 1 )
+				{
+					unset( $nameUser[0] );
+				}
+				$fields['sn'] = implode(" ", $nameUser );	
+				$fields['password1'] = $passwordUser;
+				$fields['password2'] = $rePasswordUser;
+				$fields['telephonenumber'] = $common->mascaraPhone($phoneUser);
+				$fields['cpf'] = $common->mascaraCPF($cpfUser);
+				$fields['corporative_information_cpf']	= $common->mascaraCPF($cpfUser);
+				$fields['corporative_information_rg'] 	= $rgUser;
+				$fields['corporative_information_rguf']	= $rgUF;
+				$fields['corporative_information_description'] = $description;
+
+				// Validate Fields
+				$msg = $this->validateFields( array("attributes" => serialize($fields)) );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+
+				// Create User
+				unset($fields['cpf']);
+
+				$msg = $this->createUser( $fields );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_CREATE_USER", $msg['msg'] );
+				}
+
+				$this->setResult( array( "result" => true ) );
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}
+		}
+		
+		return $this->getResponse();
+	}
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/EditUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/EditUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/EditUserResource.php	(revision 7810)
@@ -0,0 +1,60 @@
+<?php
+
+class EditUserResource extends AdminAdapter
+{
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if( $this->isLoggedIn() )
+		{
+			// Permission
+			$permission = array();
+			$permission['action'] = 'edit_users';
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				$uidUser = $this->getParam('account_uidnumber_edit');
+
+				// Validate fields
+				if( trim($uidUser) == "" && isset($uidUser) )
+					Errors::runException( "ADMIN_UIDNUMBER_EMPTY" );
+
+				// Get User
+				$fields = $this->editUser($uidUser);
+
+				if( $fields != false )
+				{	
+					// Return fields
+					$return = array();
+					$return['account_uidnumber']	= $fields['uidnumber'];
+					$return['account_login']		= $fields['uid'];
+					$return['account_email']		= $fields['mail'];
+					$return['account_name']			= $fields['givenname']." ".$fields['sn'];
+					$return['account_phone']		= $fields['telephonenumber'];	
+					$return['account_cpf']			= $fields['corporative_information_cpf'];
+					$return['account_rg']			= $fields['corporative_information_rg'];
+					$return['account_rg_uf']		= $fields['corporative_information_rguf'];
+					$return['account_description']	= $fields['corporative_information_description'];
+					
+					$this->setResult( array( "result" => $return ));
+				}
+				else
+					Errors::runException( "ADMIN_USER_NOT_FOUND" );
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}			
+		}
+		
+		return $this->getResponse();
+	}
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/SearchUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/SearchUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/SearchUserResource.php	(revision 7810)
@@ -0,0 +1,50 @@
+<?php
+
+class SearchUserResource extends AdminAdapter
+{
+
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+ 		if( $this->isLoggedIn() )
+ 		{
+			//Permission
+			$permission = array();
+			$permission['action'] = 'list_users';
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				$searchUser = $this->getParam('account_search_user');
+
+				if( trim($searchUser) == "" && isset($searchUser) )	
+					Errors::runException( "ADMIN_SEARCH_USER_EMPTY" );
+
+				$list = $this->listUsers( $searchUser );
+
+				if( count($list) > 0 )
+				{
+					$this->setResult( array( "result" => $list ) );
+				}
+				else
+				{
+					Errors::runException( "ADMIN_USERS_NOT_FOUND" );		
+				}
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}			
+
+ 		}
+
+		return $this->getResponse();
+	}
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/RenameUserResource.php
===================================================================
--- sandbox/webservice/api/rest/admin/RenameUserResource.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/RenameUserResource.php	(revision 7810)
@@ -0,0 +1,81 @@
+<?php
+
+class RenameUserResource extends AdminAdapter
+{
+	public function post($request)
+	{
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if( $this->isLoggedIn() )
+		{
+			$common	= new CommonFunctions();
+
+			// Permission
+			$permission = array();
+			$permission['action'] = 'rename_users';			
+			$permission['apps'] = $this->getUserApps();
+
+			//Load Conf Admin
+			$this->loadConfAdmin();
+
+			if( $this->validatePermission($permission) ) 	
+			{	
+				$uidUser 	= $this->getParam('account_uid_rename');
+				$uidNewUser = $this->getParam('account_uid_new_rename');
+											   
+				// Field Validation
+				if( trim($uidUser) == "" && isset($uidUser) )	
+					Errors::runException( "ADMIN_UID_EMPTY" );
+
+				if( trim($uidNewUser) == "" && isset($uidNewUser) )	
+					Errors::runException( "ADMIN_NEW_UID_EMPTY" );
+
+				// Params
+				$fieldsValidate = array();
+				$fieldsValidate['type'] = "rename_user";
+				$fieldsValidate['uid']	= $uidNewUser;
+
+				// Validate Fields
+				$msg = $this->validateFields( array("attributes" => serialize($fields)) );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+
+				// Characters not permited
+				$msg = $common->validateCharacters($uidNewUser);
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
+				}
+				
+				// Rename User
+				$fieldsRename = array();
+				$fieldsRename['uid'] = $uidUser;
+				$fieldsRename['new_uid'] = $uidNewUser;	
+
+				$msg = $this->renameUser( $fieldsRename );
+
+				if( $msg['status'] == false )
+				{
+					Errors::runException( "ADMIN_CREATE_USER", $msg['msg'] );
+				}
+
+
+				$this->setResult( array( "result" => true ) );
+			}
+			else
+			{
+				Errors::runException( "ACCESS_NOT_PERMITTED" );
+			}			
+		}
+		
+		return $this->getResponse();
+	}
+
+}
+
+?>
Index: sandbox/webservice/api/rest/admin/CommonFunctions.php
===================================================================
--- sandbox/webservice/api/rest/admin/CommonFunctions.php	(revision 7810)
+++ sandbox/webservice/api/rest/admin/CommonFunctions.php	(revision 7810)
@@ -0,0 +1,112 @@
+<?php
+
+class CommonFunctions
+{
+	public function mascaraCPF($param)
+	{
+		$cpf = trim(preg_replace("/[^0-9]/", "", $param));
+
+		return preg_replace('/(\d{3})(\d{3})(\d{3})/','$1.$2.$3-',$cpf);
+	}
+
+	public function mascaraPhone($param)
+	{
+		$phone = trim(preg_replace("/[^0-9]/", "", $param));
+
+		return preg_replace('/(\d{2})(\d{4})(\d{4})/','($1)$2-$3',$phone);
+	}
+
+	public function validatePassword($param)
+	{
+		$sizePassword = strlen(trim($param));
+		
+		$numbers = strlen(preg_replace("/[^0-9]/", "", trim($param)));
+
+		$return['status'] = true;
+
+		if( (int)$sizePassword < 8 )
+		{
+			$return["status"] = false;
+			$return["msg"] = "you need a minimum of 8 characters for the password";
+		}
+		else
+		{
+			if( (int)$numbers < 2 )
+			{
+				$return["status"] = false;
+				$return["msg"] = "must have 2 numbers in the password";
+			}
+		}	
+
+		return $return;
+	}
+
+	public function validateCharacters( $params )	
+	{
+		$search = trim(preg_replace("/[^a-z_0-9_A-Z_-_.]/", "", $params));
+
+		$return['status'] = true;
+
+		if( strtolower($search) != strtolower(trim($params)) )
+		{
+			$return['status'] = false;
+			$return['msg'] = "Field contains characters not allowed";
+		}
+
+		return $return;
+	}
+
+	public function validateCPF( $cpf )
+	{
+		$seqInvalid = array('11111111111','22222222222','33333333333',
+							'44444444444','55555555555','66666666666',
+							'77777777777','88888888888','99999999999',
+							'00000000000', '12345678909');
+		
+		$cpf = trim(preg_replace("/[^0-9]/", "", $cpf));
+
+		if( strlen($cpf) != 11 )
+			return False;
+
+		if( in_array( $cpf, $seqInvalid ) )
+		{
+			return False;
+		}
+
+		$a = 0;
+		
+		for( $i = 0 ; $i < 9 ; $i++ )
+		{
+			$a += ($cpf[$i]*(10 - $i));
+		}
+
+		$b = ($a % 11);
+		
+		$a = ( ($b > 1) ? (11 - $b) : 0);
+		
+		if( $a != $cpf[9] )
+		{
+			return False;
+		}
+		
+		$a = 0;
+
+		for ( $i=0; $i < 10; $i++ )
+		{
+			$a += ($cpf[$i]*(11 - $i));
+		}
+
+		$b = ($a % 11);
+
+		$a = (($b > 1) ? (11 - $b) : 0);
+		
+		if( $a != $cpf[10] )
+		{
+			return False;
+		}
+
+		return True;
+	}
+}
+
+?>
