gundambison

fungsi

Oct 30th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.13 KB | None | 0 0
  1.  
  2.     public function edit_user($id)
  3.     {
  4.         $this->data['title'] = $this->lang->line('edit_user_heading');
  5.        
  6.         if (!$this->ion_auth->logged_in() || (!$this->ion_auth->is_admin() && !($this->ion_auth->user()->row()->id == $id))) {
  7.             redirect('auth', 'refresh');
  8.         }
  9.        
  10.         $user          = $this->ion_auth->user($id)->row();
  11.         $groups        = $this->ion_auth->groups()->result_array();
  12.         $currentGroups = $this->ion_auth->get_users_groups($id)->result();
  13.        
  14.         // validate form input
  15.         $this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
  16.         $this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
  17.         $this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
  18.         $this->form_validation->set_rules('company', $this->lang->line('edit_user_validation_company_label'), 'trim|required');
  19.        
  20.         if (isset($_POST) && !empty($_POST)) {
  21.            
  22.             // do we have a valid request?
  23.             /*
  24.             if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
  25.             {
  26.             show_error($this->lang->line('error_csrf'));
  27.             }
  28.             */
  29.            
  30.             // update the password if it was posted
  31.             if ($this->input->post('password')) {
  32.                 $this->form_validation->set_rules('password', $this->lang->line('edit_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
  33.                 $this->form_validation->set_rules('password_confirm', $this->lang->line('edit_user_validation_password_confirm_label'), 'required');
  34.             }
  35.             // RULE apa yang ngak jalan??? ini jd pertanyaan... tapi di message kayaknya ada form yang ga ke isi deh
  36.             if ($this->form_validation->run() === TRUE) {
  37.                 $data = array(
  38.                     'first_name' => $this->input->post('first_name'),
  39.                     'last_name' => $this->input->post('last_name'),
  40.                     'company' => $this->input->post('company'),
  41.                     'phone' => $this->input->post('phone')
  42.                 );
  43.                
  44.                 // update the password if it was posted
  45.                 if ($this->input->post('password')) {
  46.                     $data['password'] = $this->input->post('password');
  47.                 }
  48.                
  49.                 // Only allow updating groups if user is admin
  50.                 if ($this->ion_auth->is_admin()) {
  51.                     // Update the groups user belongs to
  52.                     $groupData = $this->input->post('groups');
  53.                    
  54.                     if (isset($groupData) && !empty($groupData)) {
  55.                        
  56.                         $this->ion_auth->remove_from_group('', $id);
  57.                        
  58.                         foreach ($groupData as $grp) {
  59.                             $this->ion_auth->add_to_group($grp, $id);
  60.                         }
  61.                        
  62.                     }
  63.                 }
  64.                
  65.                 // check to see if we are updating the user
  66.                 if ($this->ion_auth->update($user->id, $data)) {
  67.                     // redirect them back to the admin page if admin, or to the base url if non admin
  68.                     $this->session->set_flashdata('message', $this->ion_auth->messages());
  69.                    
  70.                     $data = array(
  71.                         'status' => TRUE,
  72.                         'pesan' => 'ERROR:' . validation_errors()
  73.                     );
  74.                     die(json_encode($data));
  75.                    
  76.                     $this->redirectUser();
  77.                    
  78.                 } else {
  79.                     // redirect them back to the admin page if admin, or to the base url if non admin
  80.                     $this->session->set_flashdata('message', $this->ion_auth->errors());
  81.                     die('ok2');
  82.                     $this->redirectUser();
  83.                    
  84.                 }
  85.                
  86.             } else {
  87.                 //show_error('masih ada yg error:'.validation_errors());
  88.                 $data = array(
  89.                     'status' => FALSE,
  90.                     'pesan' => 'ERROR:' . validation_errors()
  91.                 );
  92.                 die(json_encode($data));
  93.             }
  94.         }
  95.        
  96.         // set the flash data error message if there is one
  97.         $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
  98.        
  99.         // pass the user to the view
  100.         $this->data['user']          = $user;
  101.         $this->data['groups']        = $groups;
  102.         $this->data['currentGroups'] = $currentGroups;
  103.        
  104.         echo json_encode($this->data);
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment