yofikur

c/Produk

May 6th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. //Controllers Admin produk
  2. //produk
  3. public function produk(){
  4. $this->template->admin('admin/produk/data');
  5. }
  6. public function tambahproduk(){
  7. $d['kategori']= $this->Mkategori->data();
  8. $this->template->admin('admin/produk/tambah',$d);
  9. }
  10. public function editproduk(){
  11. $d['kategori']= $this->Mkategori->data();
  12. $d['produk']= $this->Mproduk->getonebykode($this->uri->segment(3));
  13. $this->template->admin('admin/produk/edit',$d);
  14. }
  15. public function fotoproduk(){
  16. $d['produk']= $this->Mproduk->getonebykode($this->uri->segment(3));
  17. $d['fotoproduk']= $this->Mfotoproduk->fotobykode($this->uri->segment(3));
  18. $this->template->admin('admin/produk/fotoproduk',$d);
  19. }
  20.  
  21. //Controllers Produk
  22. <?php
  23. defined('BASEPATH') OR exit('No direct script access allowed');
  24.  
  25. class Produk extends CI_Controller{
  26. public function __construct(){
  27. parent:: __construct();
  28. $this->load->model('Mproduk');
  29. $this->load->model('Mfotoproduk');
  30. $this->load->library('upload');
  31. $this->load->library('image_lib');
  32.  
  33. include APPPATH.'views/tool/function.php';
  34. }
  35. public function tambah(){
  36. $config['upload_path'] = './file/produk/';
  37. $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
  38. $config['encrypt_name'] = TRUE;
  39. $this->upload->initialize($config);
  40. if(!empty($_FILES['foto_produk']['name'])){
  41. if ($this->upload->do_upload('foto_produk')){
  42. $gbr = $this->upload->data();
  43. $aruk= array('200','350','500');
  44. for ($i=0; $i < count($aruk); $i++) {
  45. //Compress Image
  46. $config['image_library']='gd2';
  47. $config['source_image']='./file/produk/'.$gbr['file_name'];
  48. $config['create_thumb']= FALSE;
  49. $config['maintain_ratio']= FALSE;
  50. $config['quality']= '90%';
  51. $config['width']= $aruk[$i];
  52. $config['height']= $aruk[$i];
  53. $config['new_image']= './file/produk/'.$aruk[$i].'_'.$gbr['file_name'];
  54. $this->image_lib->initialize($config);
  55. $this->image_lib->resize();
  56. }
  57.  
  58. $gambar= 'file/produk/'.$gbr['file_name'];
  59. $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
  60. $trim= trim($string);
  61. $pre_slug=strtolower(str_replace(" ", "-", $trim));
  62. $slug= $pre_slug.'.html';
  63. $this->Mproduk->tambah(time(),$gambar,$slug);
  64. $this->session->set_flashdata('msg','simpan');
  65. redirect(base_url('admin/tambahproduk'));
  66. }
  67. else{
  68. $this->session->set_flashdata('msg','format');
  69. redirect(base_url('admin/tambahproduk'));
  70. }
  71. }
  72. }
  73. public function edit(){
  74. $config['upload_path'] = './file/produk/';
  75. $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
  76. $config['encrypt_name'] = TRUE;
  77. $this->upload->initialize($config);
  78. if(!empty($_FILES['foto_produk']['name'])){
  79. if ($this->upload->do_upload('foto_produk')){
  80. $gbr = $this->upload->data();
  81. $aruk= array('200','350','500');
  82. for ($i=0; $i < count($aruk); $i++) {
  83. //Compress Image
  84. $config['image_library']='gd2';
  85. $config['source_image']='./file/produk/'.$gbr['file_name'];
  86. $config['create_thumb']= FALSE;
  87. $config['maintain_ratio']= FALSE;
  88. $config['quality']= '90%';
  89. $config['width']= $aruk[$i];
  90. $config['height']= $aruk[$i];
  91. $config['new_image']= './file/produk/'.$aruk[$i].'_'.$gbr['file_name'];
  92. $this->image_lib->initialize($config);
  93. $this->image_lib->resize();
  94. }
  95. $gambar= 'file/produk/'.$gbr['file_name'];
  96. $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
  97. $trim= trim($string);
  98. $pre_slug=strtolower(str_replace(" ", "-", $trim));
  99. $slug= $pre_slug.'.html';
  100. $this->Mproduk->edit($gambar,$slug);
  101. //hapus
  102. $filegam= str_replace('file/produk/', "", $this->input->post('fotolama'));
  103. unlink('file/produk/'.$filegam);
  104. $aruk= array('200','350','500');
  105. for ($i=0; $i < count($aruk); $i++) {
  106. unlink('file/produk/'.$aruk[$i].'_'.$filegam);
  107. }
  108. $this->session->set_flashdata('msg','simpan');
  109. redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
  110. }
  111. else{
  112. $this->session->set_flashdata('msg','format');
  113. redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
  114. }
  115. }
  116. else{
  117. $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
  118. $trim= trim($string);
  119. $pre_slug=strtolower(str_replace(" ", "-", $trim));
  120. $slug= $pre_slug.'.html';
  121. $this->Mproduk->editnotfoto($slug);
  122. $this->session->set_flashdata('msg','simpan');
  123. redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
  124. }
  125. }
  126. public function hapus(){
  127. $produk= $this->Mproduk->getonebykode($this->uri->segment(3));
  128. $data= $produk->row_array();
  129. $aruk= array('200','350','500');
  130. //hapus
  131. $filegam= str_replace('file/produk/', "", $data['foto_produk']);
  132. unlink('file/produk/'.$filegam);
  133. for ($i=0; $i < count($aruk); $i++) {
  134. unlink('file/produk/'.$aruk[$i].'_'.$filegam);
  135. }
  136. $fotoproduk= $this->Mfotoproduk->fotobykode($data['kode_produk']);
  137. foreach($fotoproduk->result() as $fp){
  138. //hapus
  139. $filegam_fp= str_replace('file/fotoproduk/', "", $fp->foto_fotoproduk);
  140. unlink('file/fotoproduk/'.$filegam_fp);
  141. for ($i=0; $i < count($aruk); $i++) {
  142. unlink('file/fotoproduk/'.$aruk[$i].'_'.$filegam_fp);
  143. }
  144. $this->Mfotoproduk->hapus($fp->id_fotoproduk);
  145. }
  146. $this->Mproduk->hapus($data['id_produk']);
  147. $this->session->set_flashdata('msg','hapus');
  148.  
  149. echo "oke";
  150. }
  151. //data produk
  152. public function get_data_dataproduk(){
  153.  
  154. $list = $this->Mproduk->get_datatablesproduk();
  155. $data = array();
  156. $no = $_POST['start'];
  157. foreach ($list as $field) {
  158. $sisastok= $this->Mproduk->sisastok($field->id_produk);
  159.  
  160. //total
  161. $no++;
  162. $row = array();
  163. $row[]= $no;
  164. $row[]= '<a href="'.base_url('admin/fotoproduk/'.$field->kode_produk.'/access').'"><img src="'.fotoproduk(f200($field->foto_produk)).'" style="width: 60px; height: 70px;"></a>';
  165. $row[]= $field->nama_produk;
  166. $row[]= $field->nama_kategori;
  167. $row[]= rp($field->diskon_produk).'%';
  168. $row[]= rp($field->hargaasli_produk);
  169. $row[]= rp($field->harga_produk);
  170. $row[]= $field->stokawal_produk;
  171. $row[]= $sisastok;
  172. $row[]= dmy($field->tglinput_produk);
  173. $row[]= '
  174. <a href="'.base_url('admin/editproduk/'.$field->kode_produk.'/access').'" class="btn btn-warning btn-xs"><i class="fa fa-edit"></i></a>
  175. <a href="javascript:void(0)" onclick="hapus('.$field->kode_produk.')" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
  176. ';
  177. $data[] = $row;
  178. }
  179.  
  180. $output = array(
  181. "draw" => $_POST['draw'],
  182. "recordsTotal" => $this->Mproduk->count_allproduk(),
  183. "recordsFiltered" => $this->Mproduk->count_filteredproduk(),
  184. "data" => $data,
  185. );
  186. //output dalam format JSON
  187. echo json_encode($output);
  188. }
  189. }
  190.  
  191.  
  192.  
  193. // Controller Foto Produk
  194. <?php
  195. defined('BASEPATH') OR exit('No direct script access allowed');
  196.  
  197. class Fotoproduk extends CI_Controller{
  198. public function __construct(){
  199. parent:: __construct();
  200. $this->load->model('Mfotoproduk');
  201. $this->load->library('upload');
  202. $this->load->library('image_lib');
  203.  
  204. include APPPATH.'views/tool/function.php';
  205. }
  206. public function tambah(){
  207. $config['upload_path'] = './file/fotoproduk/';
  208. $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
  209. $config['encrypt_name'] = TRUE;
  210. $this->upload->initialize($config);
  211. if(!empty($_FILES['foto_fotoproduk']['name'])){
  212. if ($this->upload->do_upload('foto_fotoproduk')){
  213. $gbr = $this->upload->data();
  214. $aruk= array('200','350','500');
  215. for ($i=0; $i < count($aruk); $i++) {
  216. //Compress Image
  217. $config['image_library']='gd2';
  218. $config['source_image']='./file/fotoproduk/'.$gbr['file_name'];
  219. $config['create_thumb']= FALSE;
  220. $config['maintain_ratio']= FALSE;
  221. $config['quality']= '90%';
  222. $config['width']= $aruk[$i];
  223. $config['height']= $aruk[$i];
  224. $config['new_image']= './file/fotoproduk/'.$aruk[$i].'_'.$gbr['file_name'];
  225. $this->image_lib->initialize($config);
  226. $this->image_lib->resize();
  227. }
  228. $gambar= 'file/fotoproduk/'.$gbr['file_name'];
  229. $this->Mfotoproduk->tambah($gambar);
  230. $this->session->set_flashdata('msg','simpan');
  231. redirect(base_url('admin/fotoproduk/'.$this->input->post('kode_produk').'/access'));
  232. }
  233. else{
  234. $this->session->set_flashdata('msg','format');
  235. redirect(base_url('admin/fotoproduk/'.$this->input->post('kode_produk').'/access'));
  236. }
  237. }
  238. }
  239. public function hapus(){
  240. $fotoproduk= $this->Mfotoproduk->getone($this->uri->segment(3));
  241. $data= $fotoproduk->row_array();
  242. //hapus
  243. $filegam= str_replace('file/fotoproduk/', "", $data['foto_fotoproduk']);
  244. unlink('file/fotoproduk/'.$filegam);
  245. $aruk= array('200','350','500');
  246. for ($i=0; $i < count($aruk); $i++) {
  247. unlink('file/fotoproduk/'.$aruk[$i].'_'.$filegam);
  248. }
  249. $this->Mfotoproduk->hapus($data['id_fotoproduk']);
  250. $this->session->set_flashdata('msg','hapus');
  251.  
  252. echo "oke";
  253. }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment