Advertisement
Sumayasri

Admin_Controller

Feb 6th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.15 KB | None | 0 0
  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.  
  28.         $data['records'] = $this->db->get('vendor', $config['per_page'], $this->uri->segment(3));
  29.         $data['vendor']=$this->m_admin->vendor();
  30.         $this->load->view('admin/header');
  31.         $this->load->view('admin/vendor/V_vendorList',$data);
  32.         $this->load->view('admin/footer');
  33.     }
  34.  
  35.     function tambah_vendor(){
  36.         $this->load->library('form_validation');
  37.         $this->form_validation->set_rules('category','category','required');
  38.         $this->form_validation->set_rules('name','name','required');
  39.         $this->form_validation->set_rules('address','address','required');
  40.         if($this->form_validation->run() != true ){
  41.             $data['vendorCategory'] = $this->m_admin->vendorCategory();
  42.             $this->load->view('admin/header');
  43.             $this->load->view('admin/vendor/v_vendorAdd',$data);
  44.             $this->load->view('admin/footer');
  45.         }else{
  46.             $category = $this->input->post('category');
  47.             $name = $this->input->post('name');
  48.             $address = $this->input->post('address');
  49.             $config['upload_path'] = './gambar_posting/';
  50.             $config['allowed_types'] = 'gif|jpg|png';          
  51.             $this->load->library('upload', $config);
  52.             $this->upload->do_upload('icon');
  53.             $data = array('upload_data' => $this->upload->data());
  54.             $d = array(
  55.                 'category' => $category,
  56.                 'name' => $name,
  57.                 'address' => $address,
  58.                 'icon' => $data['upload_data']['file_name']
  59.                 );
  60.             $this->m_admin->tambah_vendor($d);
  61.             redirect('admin/vendor/oke','refresh');
  62.         }      
  63.     }
  64.    
  65.     function edit_vendor($id){
  66.         $this->load->library('form_validation');
  67.         $data['vendor'] = $this->m_admin->edit_vendor($id);
  68.         $data['vendorCategory'] = $this->m_admin->vendorCategory();
  69.         $this->load->view('admin/header');
  70.         $this->load->view('admin/vendor/V_vendorEdit',$data);
  71.         $this->load->view('admin/footer');
  72.     }
  73.  
  74.     function update_vendor(){
  75.         $this->load->library('form_validation');
  76.         $id = $this->input->post('id');
  77.         $this->form_validation->set_rules('category','category','required');
  78.         $this->form_validation->set_rules('name','name','required');
  79.         $this->form_validation->set_rules('address','address','required');
  80.         if($this->form_validation->run() != true ){
  81.             $data['vendor'] = $this->m_admin->edit_vendor($id);
  82.             $data['vendorCategory'] = $this->m_admin->vendorCategory();
  83.             $this->load->view('admin/header');
  84.             $this->load->view('admin/vendor/V_vendorEdit',$data);
  85.             $this->load->view('admin/footer');
  86.         }else{         
  87.             $category = $this->input->post('category');
  88.             $name = $this->input->post('name');
  89.             $address = $this->input->post('address');
  90.             if($_FILES['icon']['name'] == ""){             
  91.                 $d = array(
  92.                     'category' => $category,
  93.                     'name' => $name,
  94.                     'address' => $address                  
  95.                     );
  96.                 $this->m_admin->update_vendor($d,$id);
  97.                 redirect('admin/vendor/diupdate','refresh');
  98.             }else{             
  99.                 $config['upload_path'] = './gambar_posting/';
  100.                 $config['allowed_types'] = 'gif|jpg|png';          
  101.                 $this->load->library('upload', $config);
  102.                 $this->upload->do_upload('icon');
  103.                 $data = array('upload_data' => $this->upload->data());
  104.                 $d = array(
  105.                     'category' => $category,
  106.                     'name' => $name,
  107.                     'address' => $address,                                     
  108.                     'icon' => $data['upload_data']['file_name']
  109.                     );
  110.                 $this->m_admin->update_vendor($d,$id);
  111.                 redirect('admin/vendor/diupdate','refresh');
  112.             }          
  113.         }      
  114.     }
  115.  
  116.     function hapus_vendor($id){
  117.         $this->m_admin->hapus_vendor($id);
  118.         redirect('admin/vendor/dihapus');
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement