wirahadi

Untitled

May 4th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Page extends CI_Controller {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->model('My_model');
  10. $this->load->helper('url');
  11. $this->load->helper('form');
  12. }
  13.  
  14.  
  15. function index()
  16. {
  17. $this->load->view('tampilan_login');
  18.  
  19. }
  20. function proses_login(){
  21. $user=$this->input->post('usern');
  22. $pass=$this->input->post('passw');
  23.  
  24. $ceklogin= $this->my_model->login($user,$pass);
  25.  
  26. if($ceklogin){
  27. foreach($ceklogin as $row);
  28. $this->session->set_userdata('username', $row->username);
  29. $this->session->set_userdata('level',$row->level);
  30.  
  31. if($this->session->userdata('level')=="admin"){
  32. redirect('admin');//ini mengambil dari controller admin
  33. }elseif($this->session->userdata('level')=="user"){
  34. redirect('user');//ini juga dari controller user
  35. }
  36. }else{
  37. $data['pesan']="Username atau Password tidak sesuai.";
  38. $this->load->view('tampilan_login',$data);
  39. }
  40.  
  41. }
  42. function edit($id){
  43. $where=array('id_barang'=> $id);
  44. $data['bar'] = $this->my_model->ambil_where($where,'barang')->result();
  45. $this->load->view('edit',$data);
  46.  
  47. }
  48. function proses_edit(){
  49. $config['upload_path'] = './produk/';
  50. $config['allowed_types'] = 'gif|jpg|png';
  51. $config['max_size'] = '10000';
  52. $config['max_width'] = '5000';
  53. $config['max_height'] = '5000';
  54.  
  55.  
  56. $this->load->library('upload', $config);
  57. $gambar = "";
  58. if ($this->upload->do_upload('userfile'))
  59. {
  60.  
  61. $img = $this->upload->data();
  62. $gambar = $img['file_name'];
  63.  
  64.  
  65. }
  66. $id = $this->input->post('id',true);
  67. $nama = $this->input->post('nama',true);
  68.  
  69. $harga = $this->input->post('harga',true);
  70. $stok = $this->input->post('stok',true);
  71.  
  72. $data= array(
  73. 'nama_barang' => $nama,
  74. 'harga' => $harga,
  75. 'stok' => $stok,
  76. 'gambar' => $gambar
  77. );
  78.  
  79.  
  80. $where = array('id_barang'=>$id);
  81.  
  82. $this->my_model->update($where, $data,'barang');
  83. Redirect( site_url('/admin'));
  84.  
  85. }
  86.  
  87. }
Add Comment
Please, Sign In to add comment