Advertisement
darmariduan

controllers/Resi.php

Aug 1st, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.42 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Resi extends CI_Controller {
  5.  
  6.     function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->load->library(array('template', 'form_validation'));
  10.       $this->load->model('resis');
  11.     }
  12.  
  13.    public function index()
  14.    {
  15.         $this->cek_login();
  16.  
  17.         $this->template->admin('admin/menage_resi');
  18.    }
  19.  
  20.     public function ajax_list()
  21.    {
  22.       $list = $this->resis->get_datatables();
  23.       $data = array();
  24.       $no = $_POST['start'];
  25.       foreach ($list as $i) {
  26.  
  27.          $no++;
  28.          $row = array();
  29.          $row[] = $no;
  30.          $row[] = $i->nama;
  31.          $row[] = $i->no_resi;
  32.        
  33.          $row[] = $i->pengiriman;
  34.          $row[] = '<a href="'.site_url('resi/detail/'.$i->id_resi).'" class="btn btn-success btn-xs"><i class="fa fa-search-plus"></i></a>
  35.                 <a href="'.site_url('resi/update_resi/'.$i->id_resi).'" class="btn btn-warning btn-xs"><i class="fa fa-edit"></i></a>';
  36.  
  37.          $data[] = $row;
  38.       }
  39.  
  40.       $output = array(
  41.                 "draw" => $_POST['draw'],
  42.                 "recordsTotal" => $this->resis->count_all(),
  43.                 "recordsFiltered" => $this->resis->count_filtered(),
  44.                 "data" => $data
  45.                 );
  46.       //output to json format
  47.     echo json_encode($output);
  48.    }
  49.  
  50.  
  51.    public function add_resi()
  52.    {
  53.         $this->cek_login();
  54.  
  55.       if ($this->input->post('submit', TRUE) == 'Submit') {
  56.          //validasi
  57.          $this->form_validation->set_rules('nama', 'Nama', 'required|min_length[2]');
  58.          $this->form_validation->set_rules('no_resi', 'No Resi', 'required|numeric');
  59.        
  60.          $this->form_validation->set_rules('pengiriman', 'Pengiriman', 'required|min_length[2]');
  61.  
  62.          if ($this->form_validation->run() == TRUE)
  63.          {
  64.                  $resis = array (
  65.                     'nama' => $this->input->post('nama', TRUE),
  66.                     'no_resi' => $this->input->post('no_resi', TRUE),
  67.                     'pengiriman' => $this->input->post('pengiriman', TRUE)
  68.                  );
  69.  
  70.                     $id_resi = $this->resis->insert_last('t_resis', $resis);
  71.                     //akses function kategori
  72.  
  73.                     //upload Foto Lainnya
  74.                    
  75.                        
  76.  
  77.                                  
  78.  
  79.                     redirect('resi');
  80.  
  81.                 } else {
  82.                     $this->session->set_flashdata('alert', 'Isi Data Resi');
  83.                 }
  84.          }
  85.      
  86.  
  87.         $data['nama']       = $this->input->post('nama', TRUE);
  88.       $data['no_resi']  = $this->input->post('no_resi', TRUE);
  89.  
  90.       $data['pengiriman']       = $this->input->post('pengiriman', TRUE);
  91.    
  92.       $data['header'] = "Add New Resi";
  93.  
  94.       $this->template->admin('admin/resi_form', $data);
  95.    }
  96.  
  97.     public function detail()
  98.     {
  99.         $this->cek_login();
  100.         $id_resi = $this->uri->segment(3);
  101.         $resi = $this->resis->get_where('t_resis', array('id_resi' => $id_resi));
  102.  
  103.         foreach ($resi->result() as $key) {
  104.             $data['id_resi'] = $key->id_resi;
  105.             $data['nama'] = $key->nama;
  106.             $data['no_resi'] = $key->no_resi;
  107.  
  108.        
  109.             $data['pengiriman'] = $key->pengiriman;
  110.         }
  111.  
  112.         //ambil data img berdasarkan id_resi
  113.        
  114.         $this->template->admin('admin/detail_resi', $data);
  115.     }
  116.  
  117.     public function update_resi()
  118.    {
  119.         $this->cek_login();
  120.         $id_resi = $this->uri->segment(3);
  121.  
  122.       if ($this->input->post('submit', TRUE) == 'Submit') {
  123.          //validasi
  124.          $this->form_validation->set_rules('nama', 'Nama', 'required|min_length[4]');
  125.  
  126.          $this->form_validation->set_rules('no_resi', 'No Resi', 'required|numeric');
  127.  
  128.          $this->form_validation->set_rules('pengiriman', 'Pengiriman', 'required|min_length[2]');
  129.  
  130.          if ($this->form_validation->run() == TRUE)
  131.          {
  132.                 $resis = array (
  133.                     'nama' => $this->input->post('nama', TRUE),
  134.                     'no_resi' => $this->input->post('no_resi', TRUE),
  135.  
  136.                     'pengiriman' => $this->input->post('pengiriman', TRUE)
  137.                 );
  138.  
  139.                
  140.                
  141.                     $this->resis->update('t_resis', $resis, array('id_resi' => $id_resi));
  142.            
  143.  
  144.                
  145.  
  146.                 redirect('resi');
  147.          }
  148.       }
  149.  
  150.         $resi = $this->resis->get_where('t_resis', array('id_resi' => $id_resi));
  151.  
  152.        
  153.  
  154.  
  155.         foreach($resi->result() as $key) {
  156.           $data['nama'] = $key->nama;
  157.  
  158.           $data['no_resi'] = $key->no_resi;
  159.      
  160.           $data['pengiriman'] = $key->pengiriman;
  161.            
  162.  
  163.         }
  164.  
  165.  
  166.       $data['header'] = "Update Data Resi";
  167.  
  168.       $this->template->admin('admin/resi_form', $data);
  169.    }
  170.  
  171.    
  172.     function cek_login()
  173.     {
  174.         if (!$this->session->userdata('admin'))
  175.         {
  176.             redirect('login');
  177.         }
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement