SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
3 | ||
4 | class Admin extends CI_Controller{ | |
5 | function __construct(){ | |
6 | parent::__construct(); | |
7 | $this->load->helper('url'); | |
8 | $this->load->model('m_admin'); | |
9 | if($this->session->userdata('status') != "login"){ | |
10 | redirect('login'); | |
11 | } | |
12 | } | |
13 | function index(){ | |
14 | $data['vendor']=$this->m_admin->vendor(); | |
15 | $this->load->view('admin/header',$data); | |
16 | $this->load->view('admin/home',$data); | |
17 | $this->load->view('admin/footer',$data); | |
18 | } | |
19 | function vendor(){ | |
20 | $this->load->library('pagination'); | |
21 | $this->load->library('table'); | |
22 | $config['base_url'] = '/admin/vendor/'; | |
23 | $config['total_rows'] = $this->db->get('vendor')->num_rows(); | |
24 | $config['per_page'] = 10; | |
25 | ||
26 | $this->pagination->initialize($config); | |
27 | //---- curiga yg ini | |
28 | $data['records'] = $this->db->get('vendor', $config['per_page'], $this->uri->segment(3)); | |
29 | echo "page =".$config['per_page']."<br>segmen=". $this->uri->segment(3)); | |
30 | echo "<pre>".print_r($_REQUEST,1)."</pre>"; | |
31 | $data['vendor']=$this->m_admin->vendor(); | |
32 | $this->load->view('admin/header'); | |
33 | $this->load->view('admin/vendor/V_vendorList',$data); | |
34 | $this->load->view('admin/footer'); | |
35 | } | |
36 | ||
37 | function tambah_vendor(){ | |
38 | $this->load->library('form_validation'); | |
39 | $this->form_validation->set_rules('category','category','required'); | |
40 | $this->form_validation->set_rules('name','name','required'); | |
41 | $this->form_validation->set_rules('address','address','required'); | |
42 | if($this->form_validation->run() != true ){ | |
43 | $data['vendorCategory'] = $this->m_admin->vendorCategory(); | |
44 | $this->load->view('admin/header'); | |
45 | $this->load->view('admin/vendor/v_vendorAdd',$data); | |
46 | $this->load->view('admin/footer'); | |
47 | }else{ | |
48 | $category = $this->input->post('category'); | |
49 | $name = $this->input->post('name'); | |
50 | $address = $this->input->post('address'); | |
51 | $config['upload_path'] = './gambar_posting/'; | |
52 | $config['allowed_types'] = 'gif|jpg|png'; | |
53 | $this->load->library('upload', $config); | |
54 | $this->upload->do_upload('icon'); | |
55 | $data = array('upload_data' => $this->upload->data()); | |
56 | $d = array( | |
57 | 'category' => $category, | |
58 | 'name' => $name, | |
59 | 'address' => $address, | |
60 | 'icon' => $data['upload_data']['file_name'] | |
61 | ); | |
62 | $this->m_admin->tambah_vendor($d); | |
63 | redirect('admin/vendor/oke','refresh'); | |
64 | } | |
65 | } | |
66 | ||
67 | function edit_vendor($id){ | |
68 | $this->load->library('form_validation'); | |
69 | $data['vendor'] = $this->m_admin->edit_vendor($id); | |
70 | $data['vendorCategory'] = $this->m_admin->vendorCategory(); | |
71 | $this->load->view('admin/header'); | |
72 | $this->load->view('admin/vendor/V_vendorEdit',$data); | |
73 | $this->load->view('admin/footer'); | |
74 | } | |
75 | ||
76 | function update_vendor(){ | |
77 | $this->load->library('form_validation'); | |
78 | $id = $this->input->post('id'); | |
79 | $this->form_validation->set_rules('category','category','required'); | |
80 | $this->form_validation->set_rules('name','name','required'); | |
81 | $this->form_validation->set_rules('address','address','required'); | |
82 | if($this->form_validation->run() != true ){ | |
83 | $data['vendor'] = $this->m_admin->edit_vendor($id); | |
84 | $data['vendorCategory'] = $this->m_admin->vendorCategory(); | |
85 | $this->load->view('admin/header'); | |
86 | $this->load->view('admin/vendor/V_vendorEdit',$data); | |
87 | $this->load->view('admin/footer'); | |
88 | }else{ | |
89 | $category = $this->input->post('category'); | |
90 | $name = $this->input->post('name'); | |
91 | $address = $this->input->post('address'); | |
92 | if($_FILES['icon']['name'] == ""){ | |
93 | $d = array( | |
94 | 'category' => $category, | |
95 | 'name' => $name, | |
96 | 'address' => $address | |
97 | ); | |
98 | $this->m_admin->update_vendor($d,$id); | |
99 | redirect('admin/vendor/diupdate','refresh'); | |
100 | }else{ | |
101 | $config['upload_path'] = './gambar_posting/'; | |
102 | $config['allowed_types'] = 'gif|jpg|png'; | |
103 | $this->load->library('upload', $config); | |
104 | $this->upload->do_upload('icon'); | |
105 | $data = array('upload_data' => $this->upload->data()); | |
106 | $d = array( | |
107 | 'category' => $category, | |
108 | 'name' => $name, | |
109 | 'address' => $address, | |
110 | 'icon' => $data['upload_data']['file_name'] | |
111 | ); | |
112 | $this->m_admin->update_vendor($d,$id); | |
113 | redirect('admin/vendor/diupdate','refresh'); | |
114 | } | |
115 | } | |
116 | } | |
117 | ||
118 | function hapus_vendor($id){ | |
119 | $this->m_admin->hapus_vendor($id); | |
120 | redirect('admin/vendor/dihapus'); | |
121 | } | |
122 | } |