Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Controllers Admin produk
- //produk
- public function produk(){
- $this->template->admin('admin/produk/data');
- }
- public function tambahproduk(){
- $d['kategori']= $this->Mkategori->data();
- $this->template->admin('admin/produk/tambah',$d);
- }
- public function editproduk(){
- $d['kategori']= $this->Mkategori->data();
- $d['produk']= $this->Mproduk->getonebykode($this->uri->segment(3));
- $this->template->admin('admin/produk/edit',$d);
- }
- public function fotoproduk(){
- $d['produk']= $this->Mproduk->getonebykode($this->uri->segment(3));
- $d['fotoproduk']= $this->Mfotoproduk->fotobykode($this->uri->segment(3));
- $this->template->admin('admin/produk/fotoproduk',$d);
- }
- //Controllers Produk
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Produk extends CI_Controller{
- public function __construct(){
- parent:: __construct();
- $this->load->model('Mproduk');
- $this->load->model('Mfotoproduk');
- $this->load->library('upload');
- $this->load->library('image_lib');
- include APPPATH.'views/tool/function.php';
- }
- public function tambah(){
- $config['upload_path'] = './file/produk/';
- $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
- $config['encrypt_name'] = TRUE;
- $this->upload->initialize($config);
- if(!empty($_FILES['foto_produk']['name'])){
- if ($this->upload->do_upload('foto_produk')){
- $gbr = $this->upload->data();
- $aruk= array('200','350','500');
- for ($i=0; $i < count($aruk); $i++) {
- //Compress Image
- $config['image_library']='gd2';
- $config['source_image']='./file/produk/'.$gbr['file_name'];
- $config['create_thumb']= FALSE;
- $config['maintain_ratio']= FALSE;
- $config['quality']= '90%';
- $config['width']= $aruk[$i];
- $config['height']= $aruk[$i];
- $config['new_image']= './file/produk/'.$aruk[$i].'_'.$gbr['file_name'];
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- }
- $gambar= 'file/produk/'.$gbr['file_name'];
- $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
- $trim= trim($string);
- $pre_slug=strtolower(str_replace(" ", "-", $trim));
- $slug= $pre_slug.'.html';
- $this->Mproduk->tambah(time(),$gambar,$slug);
- $this->session->set_flashdata('msg','simpan');
- redirect(base_url('admin/tambahproduk'));
- }
- else{
- $this->session->set_flashdata('msg','format');
- redirect(base_url('admin/tambahproduk'));
- }
- }
- }
- public function edit(){
- $config['upload_path'] = './file/produk/';
- $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
- $config['encrypt_name'] = TRUE;
- $this->upload->initialize($config);
- if(!empty($_FILES['foto_produk']['name'])){
- if ($this->upload->do_upload('foto_produk')){
- $gbr = $this->upload->data();
- $aruk= array('200','350','500');
- for ($i=0; $i < count($aruk); $i++) {
- //Compress Image
- $config['image_library']='gd2';
- $config['source_image']='./file/produk/'.$gbr['file_name'];
- $config['create_thumb']= FALSE;
- $config['maintain_ratio']= FALSE;
- $config['quality']= '90%';
- $config['width']= $aruk[$i];
- $config['height']= $aruk[$i];
- $config['new_image']= './file/produk/'.$aruk[$i].'_'.$gbr['file_name'];
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- }
- $gambar= 'file/produk/'.$gbr['file_name'];
- $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
- $trim= trim($string);
- $pre_slug=strtolower(str_replace(" ", "-", $trim));
- $slug= $pre_slug.'.html';
- $this->Mproduk->edit($gambar,$slug);
- //hapus
- $filegam= str_replace('file/produk/', "", $this->input->post('fotolama'));
- unlink('file/produk/'.$filegam);
- $aruk= array('200','350','500');
- for ($i=0; $i < count($aruk); $i++) {
- unlink('file/produk/'.$aruk[$i].'_'.$filegam);
- }
- $this->session->set_flashdata('msg','simpan');
- redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
- }
- else{
- $this->session->set_flashdata('msg','format');
- redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
- }
- }
- else{
- $string= preg_replace('/[^a-zA-Z0-9 \&%|{.}=,?!*()"-_+$@;<>\']/', '', $this->input->post('nama_produk'));
- $trim= trim($string);
- $pre_slug=strtolower(str_replace(" ", "-", $trim));
- $slug= $pre_slug.'.html';
- $this->Mproduk->editnotfoto($slug);
- $this->session->set_flashdata('msg','simpan');
- redirect(base_url('admin/editproduk/'.$this->input->post('kode_produk').'/access'));
- }
- }
- public function hapus(){
- $produk= $this->Mproduk->getonebykode($this->uri->segment(3));
- $data= $produk->row_array();
- $aruk= array('200','350','500');
- //hapus
- $filegam= str_replace('file/produk/', "", $data['foto_produk']);
- unlink('file/produk/'.$filegam);
- for ($i=0; $i < count($aruk); $i++) {
- unlink('file/produk/'.$aruk[$i].'_'.$filegam);
- }
- $fotoproduk= $this->Mfotoproduk->fotobykode($data['kode_produk']);
- foreach($fotoproduk->result() as $fp){
- //hapus
- $filegam_fp= str_replace('file/fotoproduk/', "", $fp->foto_fotoproduk);
- unlink('file/fotoproduk/'.$filegam_fp);
- for ($i=0; $i < count($aruk); $i++) {
- unlink('file/fotoproduk/'.$aruk[$i].'_'.$filegam_fp);
- }
- $this->Mfotoproduk->hapus($fp->id_fotoproduk);
- }
- $this->Mproduk->hapus($data['id_produk']);
- $this->session->set_flashdata('msg','hapus');
- echo "oke";
- }
- //data produk
- public function get_data_dataproduk(){
- $list = $this->Mproduk->get_datatablesproduk();
- $data = array();
- $no = $_POST['start'];
- foreach ($list as $field) {
- $sisastok= $this->Mproduk->sisastok($field->id_produk);
- //total
- $no++;
- $row = array();
- $row[]= $no;
- $row[]= '<a href="'.base_url('admin/fotoproduk/'.$field->kode_produk.'/access').'"><img src="'.fotoproduk(f200($field->foto_produk)).'" style="width: 60px; height: 70px;"></a>';
- $row[]= $field->nama_produk;
- $row[]= $field->nama_kategori;
- $row[]= rp($field->diskon_produk).'%';
- $row[]= rp($field->hargaasli_produk);
- $row[]= rp($field->harga_produk);
- $row[]= $field->stokawal_produk;
- $row[]= $sisastok;
- $row[]= dmy($field->tglinput_produk);
- $row[]= '
- <a href="'.base_url('admin/editproduk/'.$field->kode_produk.'/access').'" class="btn btn-warning btn-xs"><i class="fa fa-edit"></i></a>
- <a href="javascript:void(0)" onclick="hapus('.$field->kode_produk.')" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
- ';
- $data[] = $row;
- }
- $output = array(
- "draw" => $_POST['draw'],
- "recordsTotal" => $this->Mproduk->count_allproduk(),
- "recordsFiltered" => $this->Mproduk->count_filteredproduk(),
- "data" => $data,
- );
- //output dalam format JSON
- echo json_encode($output);
- }
- }
- // Controller Foto Produk
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Fotoproduk extends CI_Controller{
- public function __construct(){
- parent:: __construct();
- $this->load->model('Mfotoproduk');
- $this->load->library('upload');
- $this->load->library('image_lib');
- include APPPATH.'views/tool/function.php';
- }
- public function tambah(){
- $config['upload_path'] = './file/fotoproduk/';
- $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
- $config['encrypt_name'] = TRUE;
- $this->upload->initialize($config);
- if(!empty($_FILES['foto_fotoproduk']['name'])){
- if ($this->upload->do_upload('foto_fotoproduk')){
- $gbr = $this->upload->data();
- $aruk= array('200','350','500');
- for ($i=0; $i < count($aruk); $i++) {
- //Compress Image
- $config['image_library']='gd2';
- $config['source_image']='./file/fotoproduk/'.$gbr['file_name'];
- $config['create_thumb']= FALSE;
- $config['maintain_ratio']= FALSE;
- $config['quality']= '90%';
- $config['width']= $aruk[$i];
- $config['height']= $aruk[$i];
- $config['new_image']= './file/fotoproduk/'.$aruk[$i].'_'.$gbr['file_name'];
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- }
- $gambar= 'file/fotoproduk/'.$gbr['file_name'];
- $this->Mfotoproduk->tambah($gambar);
- $this->session->set_flashdata('msg','simpan');
- redirect(base_url('admin/fotoproduk/'.$this->input->post('kode_produk').'/access'));
- }
- else{
- $this->session->set_flashdata('msg','format');
- redirect(base_url('admin/fotoproduk/'.$this->input->post('kode_produk').'/access'));
- }
- }
- }
- public function hapus(){
- $fotoproduk= $this->Mfotoproduk->getone($this->uri->segment(3));
- $data= $fotoproduk->row_array();
- //hapus
- $filegam= str_replace('file/fotoproduk/', "", $data['foto_fotoproduk']);
- unlink('file/fotoproduk/'.$filegam);
- $aruk= array('200','350','500');
- for ($i=0; $i < count($aruk); $i++) {
- unlink('file/fotoproduk/'.$aruk[$i].'_'.$filegam);
- }
- $this->Mfotoproduk->hapus($data['id_fotoproduk']);
- $this->session->set_flashdata('msg','hapus');
- echo "oke";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment