source: sandbox/webservice/api/rest/admin/UpdateUserResource.php @ 7941

Revision 7941, 5.5 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Verificando se os campos possuem valor para a atualização

  • Property svn:executable set to *
Line 
1<?php
2
3require_once("CommonFunctions.php");
4
5class 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
27                                $uidNumber              = trim($this->getParam('accountUidNumber'));
28                                $loginUser              = trim($this->getParam('accountLogin'));
29                                $emailUser              = trim($this->getParam('accountEmail'));
30                                $nameUser               = $common->convertChar(trim($this->getParam('accountName')));
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'));
37                                $description    = $common->convertChar(trim($this->getParam('accountDescription')));
38                                $mailQuota              = trim($this->getParam('accountMailQuota'));
39                                $birthDate              = $common->mascaraBirthDate($this->getParam('accountBirthDate'));
40                                $st                     = $this->getParam('accountSt');
41                                $city                   = $this->getParam('accountCity');
42                                $sex                    = $this->getParam('accountSex');
43
44                                // Field Validation
45                                if( trim($uidNumber) == "" && isset($uidNumber) )
46                                        Errors::runException( "ADMIN_UIDNUMBER_EMPTY" );
47                               
48                                if( trim($loginUser) == "" && isset($loginUser) )       
49                                        Errors::runException( "ADMIN_LOGIN_EMPTY" );
50
51                                // If rgUser and rgUF
52                                if( (trim($rgUser) != "" && trim($rgUF) == "" ) || ( trim($rgUser) == "" && trim($rgUF) != "" ) )
53                                {
54                                        Errors::runException("ADMIN_RG_UF_EMPTY");
55                                }
56
57                                // If not empty
58                                if( trim($passwordUser) != "" && trim($rePasswordUser) != "" )
59                                {       
60                                        if( isset($passwordUser) && isset($rePasswordUser) )
61                                        {
62                                                // password and repassword are different ?                             
63                                                if( trim($passwordUser) != trim($rePasswordUser) )
64                                                {
65                                                        Errors::runException( "ADMIN_PASSWORD_REPASSWORD" );
66                                                }
67                                       
68                                                // validate password, 8 characteres minimum and 2 numbers
69                                                $msg = $common->validatePassword($passwordUser);
70
71                                                if( $msg['status'] == false )
72                                                {
73                                                        Errors::runException( "ADMIN_MINIMUM_CHARACTERS", $msg['msg']);
74                                                }
75                                        }
76                                }
77
78                                // CPF is invalid
79                                if( trim($cpfUser) != "" && !$common->validateCPF($cpfUser) )
80                                {
81                                        Errors::runException( "ADMIN_CPF_INVALID" );
82                                }
83
84                                // Characters not permited login
85                                $msg = $common->validateCharacters($loginUser, "accountLogin");
86
87                                if( $msg['status'] == false )
88                                {
89                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountLogin" );
90                                }
91
92                                //Characters not permited name
93                                $msg = $common->validateCharacters($nameUser);
94
95                                if( $msg['status'] == false )
96                                {
97                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountName" );
98                                }
99
100                                //Characters not permited mailQuota
101                                $msg = $common->validateCharacters($mailQuota, "accountMailQuota");
102
103                                if( $msg['status'] == false )
104                                {
105                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] . " : accountMailQuota" );
106                                }
107
108                                // Params - Validade / Update Fields
109                                $fields = array();
110                                $fields['type']                 = "edit_user";
111                                $fields['uid']                  = $loginUser;
112                                $fields['uidnumber']    = $uidNumber;
113                                $fields['mail']                 = $emailUser;
114                                $fields['cpf']                  = $common->mascaraCPF($cpfUser);
115
116                                // Validate Fields
117                                $msg = $this->validateFields( array("attributes" => serialize($fields)) );
118
119                                if( $msg['status'] == false )
120                                {
121                                        Errors::runException( "ADMIN_FIELDS_VALIDATE", $msg['msg'] );
122                                }
123
124                                //Name User
125                                $nameUser = explode(" ", $nameUser);
126                               
127                                $fields['givenname'] = $nameUser[0];
128                               
129                                if( count($nameUser) > 1 )
130                                {
131                                        unset( $nameUser[0] );
132                                }
133
134                                if( trim($passwordUser) != "" )
135                                {
136                                        $fields['password1'] = $passwordUser;
137                                        $fields['password2'] = $rePasswordUser;
138                                }
139
140                                if( trim($nameUser) != "" )
141                                        $fields['sn'] = implode(" ", $nameUser );       
142                               
143                                if( trim($phoneUser) != "" )
144                                        $fields['telephonenumber'] = $common->mascaraPhone($phoneUser);
145                               
146                                if( trim($cpfUser) != "" )
147                                        $fields['corporative_information_cpf'] = $common->mascaraCPF($cpfUser);
148                               
149                                if( trim($rgUser) != "" )
150                                        $fields['corporative_information_rg'] = $rgUser;
151                               
152                                if( trim($rgUF) != "" )
153                                        $fields['corporative_information_rguf'] = $rgUF;
154                               
155                                if( trim($description) != "" )
156                                        $fields['corporative_information_description'] = $description;
157
158                                if( trim($mailQuota) != "" )
159                                        $fields['mailquota'] = $mailQuota;
160
161                                if( trim($birthDate) != "" )
162                                        $fields['corporative_information_datanascimento'] = $birthDate;
163
164                                if( trim($st) != "" )
165                                        $fields['corporative_information_st']   = $st;
166       
167                                if( trim($city) != "" )
168                                        $fields['corporative_information_city'] = $city;
169
170                                if( trim($sex) != "" )                 
171                                        $fields['corporative_information_sexo'] = $sex;
172
173                                // Update Fields
174                                unset($fields['cpf']);
175
176                                $msg = $this->updateUser($fields);
177
178                                if( $msg['status'] == false )
179                                {
180                                        Errors::runException( "ADMIN_UPDATE_USER", $msg['msg'] );
181                                }
182
183                                $this->setResult( array( "result" => true ) );
184                        }
185                        else
186                        {
187                                Errors::runException( "ACCESS_NOT_PERMITTED" );
188                        }                       
189                }
190
191                return $this->getResponse();   
192        }       
193}
194
195?>
Note: See TracBrowser for help on using the repository browser.