Advertisement
Roofi

controller/page_update

May 5th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Page extends CI_Controller {
  5.  
  6.  
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->model('My_model');
  11. $this->load->helper('url');
  12. $this->load->helper('form');
  13. $this->load->database();
  14. }
  15.  
  16.  
  17. function index()
  18. {
  19. $this->load->view('tampilan_login');
  20.  
  21. }
  22. function proses_login(){
  23. $user=$this->input->post('usern');
  24. $pass=$this->input->post('passw');
  25.  
  26. $ceklogin= $this->my_model->login($user,$pass);
  27.  
  28. if($ceklogin){
  29. foreach($ceklogin as $row);
  30. $this->session->set_userdata('username', $row->username);
  31. $this->session->set_userdata('level',$row->level);
  32.  
  33. if($this->session->userdata('level')=="admin"){
  34. redirect('/admin');//ini mengambil dari controller admin
  35. }elseif($this->session->userdata('level')=="user"){
  36. redirect('user');//ini juga dari controller user
  37. }
  38. }else{
  39. $data['pesan']="Username atau Password tidak sesuai.";
  40. $this->load->view('tampilan_login',$data);
  41. }
  42.  
  43. }
  44. function edit($id){
  45. $where=array('id_barang'=> $id);
  46. $data['bar'] = $this->my_model->ambil_where($where,'barang')->result();
  47. $this->load->view('edit',$data);
  48.  
  49. }
  50. function stok($id){
  51. $where=array('id_barang'=> $id);
  52. $data['bara'] = $this->my_model->ambil_where($where,'barang')->result();
  53. $this->load->view('edit_user',$data);
  54.  
  55. }
  56. function proses_edit(){
  57.  
  58. $id = $this->uri->segment(3);
  59.  
  60. $config['upload_path'] = 'produk/'; // foler upload
  61. $config['allowed_types'] = 'gif|jpg|png'; // jenis file
  62. $config['max_size'] = '10000';
  63. $config['max_width'] = '5000';
  64. $config['max_height'] = '5000';
  65.  
  66. $this->load->library('upload', $config);
  67. $this->upload->initialize($config);
  68. $id = $this->input->post('id');
  69. $gambar_lama = $this->input->post('ganti_gambar');
  70.  
  71. $nama = $this->input->post('nama');
  72. $harga = $this->input->post('harga');
  73. $stok = $this->input->post('stok');
  74.  
  75. $gambar_lama = $this->input->post('ganti_gambar');
  76. if ($_FILES['userfile']['name'])
  77. {
  78.  
  79.  
  80. $field_name = "userfile";
  81. if (!$this->upload->do_upload($filename)) //sesuai dengan name pada form
  82. {
  83. $error = array('error' => $this->upload->display_errors());
  84.  
  85. $this->load->view('terserah');
  86.  
  87. }
  88. else
  89. {
  90. //tampung data dari form
  91.  
  92.  
  93. $file = $this->upload->data();
  94. $gambar = $file['file_name'];
  95. $data = array(
  96. 'nama_barang' => $nama,
  97. 'harga' => $harga,
  98. 'stok' => $stok,
  99. 'gambar' => $gambar
  100.  
  101. );
  102. unlink($path.$gambar_lama);
  103. $where = array('id_barang'=>$id);
  104. $this->my_model->update($where, $data,'barang');
  105. Redirect( site_url('/admin'));
  106.  
  107. }
  108. }
  109.  
  110. }
  111.  
  112. function hapus($id){
  113. $where = array('id_barang' => $id);
  114. $this->my_model->hapus($where,'barang');
  115.  
  116. Redirect( site_url('/admin'));
  117.  
  118.  
  119. }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement