SHARE
TWEET

Untitled

taktikhek Jun 17th, 2019 37 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. *
  4. */
  5. class User extends CI_Controller
  6. {
  7.    
  8.     public function __construct() {
  9.         parent::__construct();
  10.         if(!isset($this->session->login['id_user'])) {
  11.             $this->session->sess_destroy();
  12.             redirect('admin/login');
  13.         }
  14.         $this->load->model('User_model');
  15.     }
  16.  
  17.     public function index(){
  18.         $data['hasil'] = $this->User_model->get_all();
  19.         //main
  20.         $data['title'] = "User";
  21.         $data['contens'] = "admin/user/view";
  22.         $this->load->view("admin/layout/template",$data);
  23.     }
  24.  
  25.     public function add(){
  26.         if($_SERVER['REQUEST_METHOD']=="POST"){
  27.             $this->form_validation->set_rules('nama', 'Nama', 'trim|required|xss_clean');
  28.             $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  29.             $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
  30.             if($this->form_validation->run() == FALSE){
  31.                 $data['err'] = validation_errors();
  32.                 $tmp['contents'] = $this->load->view("admin/user/add",$data, TRUE);
  33.             }else{
  34.                 $nama = ucwords($this->input->post('nama'));
  35.                 $username = $this->input->post('username');
  36.                 $password = MD5($this->input->post('password'));
  37.  
  38.                 $input = array(
  39.                     'nama' => "$nama",
  40.                     'username' => "$username",
  41.                     'password' => "$password"
  42.                     );
  43.                 $aksi = $this->User_model->add($input);
  44.  
  45.                 if ($aksi) {
  46.                     $data['successMsg'] = "Data Berhasil di Inputkan!";
  47.                 }else{
  48.                     $data['errorMsg'] = "Gagal Input!";
  49.                 }
  50.             }
  51.         }
  52.         //main
  53.         $data['title'] = "Add User";
  54.         $data['contens'] = "admin/user/add";
  55.         $this->load->view("admin/layout/template",$data);
  56.     }
  57.  
  58.     public function edit($id){
  59.         if($_SERVER['REQUEST_METHOD']=="POST"){
  60.             $this->form_validation->set_rules('nama', 'Nama', 'trim|required|xss_clean');
  61.             $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  62.             $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
  63.             if($this->form_validation->run() == FALSE){
  64.                 $data['err'] = validation_errors();
  65.                 $tmp['contents'] = $this->load->view("admin/user/edit",$data, TRUE);
  66.             }else{
  67.                 $nama = ucwords($this->input->post('nama'));
  68.                 $username = $this->input->post('username');
  69.                 $password = MD5($this->input->post('password'));
  70.  
  71.                 $input = array(
  72.                     'nama' => "$nama",
  73.                     'username' => "$username",
  74.                     'password' => "$password"
  75.                     );
  76.                 $aksi = $this->User_model->update($id,$input);
  77.  
  78.                 if ($aksi) {
  79.                     $data['successMsg'] = "Data Berhasil di Inputkan!";
  80.                 }else{
  81.                     $data['errorMsg'] = "Gagal Input!";
  82.                 }
  83.             }
  84.         }
  85.         $data['old_value'] = $this->User_model->get_by_id($id);
  86.         //main
  87.         $data['title'] = "Add User";
  88.         $data['contens'] = "admin/user/edit";
  89.         $this->load->view("admin/layout/template",$data);
  90.     }
  91.  
  92.     public function delete($id){
  93.         $aksi = $this->User_model->delete($id);
  94.         redirect('admin/user','refresh');
  95.     }
  96. }
  97. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top