[7810] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require_once("CommonFunctions.php"); |
---|
| 4 | |
---|
| 5 | class UpdateUserResource extends AdminAdapter |
---|
| 6 | { |
---|
| 7 | public function post($request) |
---|
| 8 | { |
---|
| 9 | // to Receive POST Params (use $this->params) |
---|
| 10 | parent::post($request); |
---|
| 11 | |
---|
| 12 | if( $this->isLoggedIn() ) |
---|
| 13 | { |
---|
| 14 | // Permission |
---|
| 15 | $permission = array(); |
---|
| 16 | $permission['action'] = 'edit_users'; |
---|
| 17 | $permission['apps'] = $this->getUserApps(); |
---|
| 18 | |
---|
| 19 | //Load Conf Admin |
---|
| 20 | $this->loadConfAdmin(); |
---|
| 21 | |
---|
| 22 | if( $this->validatePermission($permission) ) |
---|
| 23 | { |
---|
| 24 | //Class CommonFunctions |
---|
| 25 | $common = new CommonFunctions(); |
---|
| 26 | |
---|
[7813] | 27 | $uidNumber = trim($this->getParam('accountUidNumber')); |
---|
| 28 | $loginUser = trim($this->getParam('accountLogin')); |
---|
| 29 | $emailUser = trim($this->getParam('accountEmail')); |
---|
[7880] | 30 | $nameUser = $common->convertChar(trim($this->getParam('accountName'))); |
---|
[7813] | 31 | $passwordUser = trim($this->getParam('accountPassword')); |
---|
| 32 | $rePasswordUser = trim($this->getParam('accountRePassword')); |
---|
| 33 | $phoneUser = trim($this->getParam('accountPhone')); |
---|
| 34 | $cpfUser = trim($this->getParam('accountCpf')); |
---|
| 35 | $rgUser = trim($this->getParam('accountRg')); |
---|
| 36 | $rgUF = trim($this->getParam('accountRgUf')); |
---|
[7880] | 37 | $description = $common->convertChar(trim($this->getParam('accountDescription'))); |
---|
[7882] | 38 | $mailQuota = trim($this->getParam('accountMailQuota')); |
---|
[7810] | 39 | |
---|
| 40 | // Field Validation |
---|
| 41 | if( trim($uidNumber) == "" && isset($uidNumber) ) |
---|
| 42 | Errors::runException( "ADMIN_UIDNUMBER_EMPTY" ); |
---|
| 43 | |
---|
| 44 | if( trim($loginUser) == "" && isset($loginUser) ) |
---|
| 45 | Errors::runException( "ADMIN_LOGIN_EMPTY" ); |
---|
| 46 | |
---|
| 47 | // If rgUser and rgUF |
---|
| 48 | if( (trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ) ) |
---|
| 49 | { |
---|
| 50 | Errors::runException("ADMIN_RG_UF_EMPTY"); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | // If not empty |
---|
| 54 | if( trim($passwordUser) != "" && trim($rePasswordUser) != "" ) |
---|
| 55 | { |
---|
| 56 | if( isset($passwordUser) && isset($rePasswordUser) ) |
---|
| 57 | { |
---|
| 58 | // password and repassword are different ? |
---|
| 59 | if( trim($passwordUser) != trim($rePasswordUser) ) |
---|
| 60 | { |
---|
| 61 | Errors::runException( "ADMIN_PASSWORD_REPASSWORD" ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | // validate password, 8 characteres minimum and 2 numbers |
---|
| 65 | $msg = $common->validatePassword($passwordUser); |
---|
| 66 | |
---|
| 67 | if( $msg['status'] == false ) |
---|
| 68 | { |
---|
| 69 | Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // CPF is invalid |
---|
| 75 | if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) ) |
---|
| 76 | { |
---|
| 77 | Errors::runException( "ADMIN_CPF_INVALID" ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | // Characters not permited login |
---|
[7882] | 81 | $msg = $common->validateCharacters($loginUser, "accountLogin"); |
---|
[7810] | 82 | |
---|
| 83 | if( $msg['status'] == false ) |
---|
| 84 | { |
---|
[7882] | 85 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountLogin" ); |
---|
[7810] | 86 | } |
---|
| 87 | |
---|
[7882] | 88 | //Characters not permited name |
---|
| 89 | $msg = $common->validateCharacters($nameUser); |
---|
| 90 | |
---|
| 91 | if( $msg['status'] == false ) |
---|
| 92 | { |
---|
| 93 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountName" ); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //Characters not permited mailQuota |
---|
| 97 | $msg = $common->validateCharacters($mailQuota, "accountMailQuota"); |
---|
| 98 | |
---|
| 99 | if( $msg['status'] == false ) |
---|
| 100 | { |
---|
| 101 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountMailQuota" ); |
---|
| 102 | } |
---|
| 103 | |
---|
[7810] | 104 | // Params - Validade / Update Fields |
---|
| 105 | $fields = array(); |
---|
| 106 | $fields['type'] = "edit_user"; |
---|
| 107 | $fields['uid'] = $loginUser; |
---|
| 108 | $fields['uidnumber'] = $uidNumber; |
---|
| 109 | $fields['mail'] = $emailUser; |
---|
| 110 | $fields['cpf'] = $common->mascaraCPF($cpfUser); |
---|
| 111 | |
---|
| 112 | // Validate Fields |
---|
| 113 | $msg = $this->validateFields( array("attributes" => serialize($fields)) ); |
---|
| 114 | |
---|
| 115 | if( $msg['status'] == false ) |
---|
| 116 | { |
---|
| 117 | Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] ); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | //Name User |
---|
| 121 | $nameUser = explode(" ", $nameUser); |
---|
| 122 | |
---|
| 123 | $fields['givenname'] = $nameUser[0]; |
---|
| 124 | |
---|
| 125 | if( count($nameUser) > 1 ) |
---|
| 126 | { |
---|
| 127 | unset( $nameUser[0] ); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | if( trim($passwordUser) != "" ) |
---|
| 131 | { |
---|
| 132 | $fields['password1'] = $passwordUser; |
---|
| 133 | $fields['password2'] = $rePasswordUser; |
---|
| 134 | } |
---|
| 135 | |
---|
[7882] | 136 | $fields['sn'] = implode(" ", $nameUser ); |
---|
| 137 | $fields['telephonenumber'] = $common->mascaraPhone($phoneUser); |
---|
| 138 | $fields['corporative_information_cpf'] = $common->mascaraCPF($cpfUser); |
---|
| 139 | $fields['corporative_information_rg'] = $rgUser; |
---|
| 140 | $fields['corporative_information_rguf'] = $rgUF; |
---|
[7810] | 141 | $fields['corporative_information_description'] = $description; |
---|
[7882] | 142 | $fields['mailquota'] = $mailQuota; |
---|
[7810] | 143 | |
---|
| 144 | // Update Fields |
---|
| 145 | unset($fields['cpf']); |
---|
| 146 | |
---|
| 147 | $msg = $this->updateUser($fields); |
---|
| 148 | |
---|
| 149 | if( $msg['status'] == false ) |
---|
| 150 | { |
---|
| 151 | Errors::runException( "ADMIN_UPDATE_USER", $msg['msg'] ); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | $this->setResult( array( "result" => true ) ); |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | Errors::runException( "ACCESS_NOT_PERMITTED" ); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | return $this->getResponse(); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | ?> |
---|