<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Jeniskopi extends CI_Controller {


	public function __construct()
    {
        parent::__construct();
        $this->load->model('Jenis_model');
        $this->load->model('User_model');
		is_logged_in();
    }
    public function index()
	{

		$data['jenis_kopi']=$this->Jenis_model->get_all_data();
		$id_user=$this->session->userdata('id_user');
        $data['user']=$this->User_model->get_user($id_user);
	
		$data['nama'] = "Data Jenis Kopi";
		
        $this->load->view('Templates/header.php',$data);
        $this->load->view('Templates/navbar.php',$data);
        $this->load->view('Templates/leftmenu.php',$data);
        $this->load->view('jenis/index.php',$data);
        $this->load->view('Templates/footer.php',$data);
    }

    public function tambah_jenis()
	{
        
		$id_user=$this->session->userdata('id_user');
        $data['user']=$this->User_model->get_user($id_user);
        $data['nama'] = "Tambah Data Jenis Kopi";
        $this->form_validation->set_rules('nama', 'nama', 'required');
		if ($this->form_validation->run() == false) {
        $this->load->view('Templates/header.php',$data);
        $this->load->view('Templates/navbar.php',$data);
        $this->load->view('Templates/leftmenu.php',$data);
        $this->load->view('jenis/tambah_jenis.php',$data);
        $this->load->view('Templates/footer.php',$data);
        }else{
         
		$nama=$this->input->post('nama', true);
        $deskripsi=$this->input->post('deskripsi', true);
		$this->Jenis_model->add($nama,$deskripsi);
		$this->session->set_flashdata('flash', 'Ditambahkan');
		$this->session->set_flashdata('data', 'Data Jenis kopi');

		redirect('jeniskopi');
        }
    }

    public function edit_jenis($id)
	{
        $data['jenis_kopi']=$this->Jenis_model->get_data_byid($id);
		$id_user=$this->session->userdata('id_user');
        $data['user']=$this->User_model->get_user($id_user);
        $data['nama'] = "Edit Data Jenis Kopi";
        $this->form_validation->set_rules('nama', 'nama', 'required');
		if ($this->form_validation->run() == false) {
        $this->load->view('Templates/header.php',$data);
        $this->load->view('Templates/navbar.php',$data);
        $this->load->view('Templates/leftmenu.php',$data);
        $this->load->view('jenis/edit_jenis.php',$data);
        $this->load->view('Templates/footer.php',$data);
        }else{
         
		$nama=$this->input->post('nama', true);
        $deskripsi=$this->input->post('deskripsi', true);
		$this->Jenis_model->edit($id,$nama,$deskripsi);
		$this->session->set_flashdata('flash', 'Diupdate');
		$this->session->set_flashdata('data', 'Data Jenis kopi');

		redirect('jeniskopi');
        }
    }

    public function hapus_jenis($id)
	{
	
		$this->Jenis_model->hapus($id);
		$this->session->set_flashdata('flash', 'dihapus');
        $this->session->set_flashdata('data', 'Data Kopi');
	
		redirect('jeniskopi');
    }
}