View difference between Paste ID: UidfLtti and wGVhbs8U
SHOW: | | - or go back to the newest paste.
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
        
58
        if (! $this->upload->do_upload('userfile'))
59
        {
60
            echo 'gagal upload';
61
            
62
            
63
        }else{
64
        $id = $this->input->post('id',true);
65
        $nama = $this->input->post('nama',true);
66
        $img = $this->upload->data();
67
        $gambar = $img['file_name'];
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
    
88
}