<?php

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

/**
 * staff Class
 *
 * @package     edusol
 * @subpackage  country
 * @author      Atif Razzaq
 * @link        http://atifrazzaq.arteck.xyz
 */

class kit extends CI_Controller {

    private $userInfo = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->model("user_model");
        $this->load->model("kit_model");
        $this->user_model->check_login("admin");
        $this->userInfo = $this->user_model->userInfo("first_name,last_name");
    }

     public function index()
    {
        $this->user_model->check_permissions("kit/index");
        $data['edit_delete']=$this->user_model->checkEditDelete('kit/index');
        $data['is_super'] = $this->user_model->is_super();
        $data['menu'] = $this->load_model->menu();
        $query = @$this->db->query("SELECT * FROM `kit` WHERE  is_delete='0'");
        $data['base_url'] = base_url();
        $data['userInfo'] = $this->userInfo;
        $data['kit'] = $query->result_array();
                //calling view pages
        $this->load->view('header',$data);
        $this->load->view('sidebar',$data);
        $this->load->view('kit/kit',$data);
    }

    public function save()
    {
        if($this->input->post())
            {
            
                $data = $this->input->post();
                
$db_insert = $this->kit_model->save($data);
                redirect("kit/index","refresh"); 
            }
        else
            {
                redirect("kit/index","refresh"); 

            }
        
    }

    public function edit($id)
    {
        if($this->uri->segment(3))
            {
                $data['menu'] = $this->load_model->menu();
                $id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
                $data['kit']=$this->kit_model->edit($id);
                $data['userInfo'] = $this->userInfo;
                $data['base_url'] = base_url();
                    //calling view pages
                $this->load->view('header',$data);
                $this->load->view('sidebar',$data);
                $this->load->view('kit/kit_edit',$data);

            }
         else
         {
                redirect("kit/index","refresh"); 

         }   
             

      
    }

    public function update()
    {
        if($this->input->post())
        {
            $data = $this->input->post();
            $db_update = $this->kit_model->update($data);
            redirect("kit/index","refresh");
    
        }
        else
        {
            redirect("kit/index","refresh");
        }
        

   }
   public function delete($id)
   {
        if($this->uri->segment(3))
        {
           $id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
            $this->kit_model->delete($id);
            redirect('kit/index','refresh');
     
        }
        else
        {
            redirect('kit/index','refresh');
            
        }
          }

}
