Ejemplo n.º 1
0
 public function edit()
 {
     $is_admin = $this->session->userdata('is_admin');
     $user = new VBX_User();
     $params = array();
     foreach ($user->fields as $field) {
         $val = $this->input->post($field);
         /* Disallow people from changing certain settings */
         if (in_array($field, $user->admin_fields)) {
             if ($val && $is_admin) {
                 $params[$field] = $val;
             }
         } else {
             if ($val) {
                 $params[$field] = $val;
             }
         }
         // The value for some fields should also be saved to the session
         if ($field === 'email') {
             $this->session->set_userdata('email', trim($val));
         }
     }
     if ($user->update($this->user_id, $params)) {
         $this->session->set_flashdata('message_edit', 'User data changed');
         redirect('account');
     } else {
         $this->data['error_edit'] = '';
         $this->index();
     }
 }
Ejemplo n.º 2
0
 public function edit()
 {
     if (!$this->session->userdata('loggedin')) {
         redirect('auth/login');
     }
     $is_admin = $this->session->userdata('is_admin');
     $user = new VBX_User();
     $params = array();
     foreach ($user->fields as $field) {
         $val = $this->input->post($field);
         /* Disallow people from changing certain settings */
         if (in_array($field, $user->admin_fields)) {
             if (($val || $val === '0') && $is_admin) {
                 $params[$field] = $val;
             }
         } else {
             if ($val || $val === '0') {
                 $params[$field] = $val;
             }
         }
         // The value for some fields should also be saved to the session
         if ($field === 'email') {
             $this->session->set_userdata('email', trim($val));
         }
     }
     $success = $user->update($this->user_id, $params);
     if ($this->response_type == 'json') {
         $data = isset($this->data) ? $this->data : array();
         $data['json']['error'] = !$success;
         $data['json']['message'] = !$success ? 'an error occurred while updating the user' : 'user status updated';
         $this->respond('', null, $data);
     } else {
         if ($success) {
             $this->session->set_flashdata('message_edit', 'User data changed');
             redirect('account');
         } else {
             $this->data['error_edit'] = '';
             $this->index();
         }
     }
 }