<?php 

class Katagori extends CI_Controller{

	function __construct(){
		parent::__construct();
	 	$this->load->model('m_kontak');/* sesuaikan dengan nama file pada model */
		$this->load->model('m_login'); 
		$this->load->model('m_admin'); 
		$this->load->model('m_kantor');
		$this->load->model('m_katagori'); 
		$this->load->library('session');
		$this->load->library('upload');
		 
		$this->load->helper(array('form', 'url','tanggal'));
		if($this->session->userdata('status') != "loginbro"  and empty($this->session->userdata('email')) ){
			$this->session->set_flashdata('msg','<div class="alert alert-danger alert-dismissible">
						<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
						<strong> Admin Bukan Admin </strong>Ulangi Kembali
						</div> ');

			redirect(base_url("")); 
			
		}
	 
	 
	}

	 
	function index(){		
		$data['title1'] = 'Data Katagori Barang'; 	
		$data['title2'] = 'Ubah Data'; 	
		$data['title3'] = 'Tambah Data';
		$data['title4'] = 'katagori';
		$data['kontak'] = $this->m_kontak->kontak();
		$data['kantor'] = $this->m_kantor->kantor();
		$data['admin'] = $this->m_admin->data_admin(); 
		$data['admin_login'] = $this->m_admin->data_admin_login();  
		$data['katagori'] = $this->m_katagori->katagori(); 
		 
	
		$this->load->view('master/header',$data); 
		$this->load->view('master/katagori/v_katagori');
		$this->load->view('master/footer',$data); 
	}
	 
	public function code_hapus(){
		$id = $this->input->post('id');  
		 
	    $this->db->delete('tb_katagori', array('id_katagori' => $id)); 
	  	$this->session->set_flashdata('msg','success-hapus');
	    redirect('katagori');
		
	}
	 
	public function code_tambah()
	{	 
		$data=array(
			'id_katagori'=>  null,
			'nama_katagori'=> $this->input->post('nama_katagori'),
			'status'=> $this->input->post('status'),
			'url_katagori'=> url_title($this->input->post('nama_katagori')),
		);

		$this->db->insert('tb_katagori',$data);
		$this->session->set_flashdata('msg','success');
		redirect('katagori');
		

 
        
        
    }  
     
	public function code_ubah() {
      
        
    	$data=array(
    	 	'status'=> $this->input->post('status'),
    		'nama_katagori'=> $this->input->post('nama_katagori'),
    		'url_katagori'=> url_title($this->input->post('nama_katagori')),
    		
    		
    	);

    	$this->db->where('id_katagori',$this->input->post('id'));
        $this->db->update('tb_katagori',$data);
        $this->session->set_flashdata('msg','success-edit');
    	redirect('katagori');
	 
	} 
	 
}