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

class Offering_category extends CI_Controller {
	public function __construct()
    {
        parent::__construct();

        // $this->isAdminLoggedIn();
    }
    public function isAdminLoggedIn()
	{
        if($this->session->userdata('usertype') !== 'admin' && $this->session->userdata('usertype') !== 'staff')
        {
            redirect(base_url('dashboard'));
            exit;
        }
    }
	public function header_and_footer($page, $data)
    {
        $this->load->view('includes/header',$data);
		$this->load->view('includes/sidebar',$data);
        $this->load->view($page);
        $this->load->view('includes/footer');
    }
	public function index()
    {
        $data['title'] = 'Offering Category';
        $page = 'offering_category/index';
        $this->header_and_footer($page, $data);
    }
	
  
	public function addOfferingCategory()
    {
		$array = array(
			'name' => $_POST['name'],
		);
		
		if($this->model->add('offering_category',$array))
		{  
			$lead_id = $this->db->insert_id();
			$this->createLog($this->session->userdata('id'),$this->session->userdata('usertype'),$lead_id,'add','offering category');
			echo json_encode(['return'=>true,'msg'=>'Added Successfully']);
		} 
		
    }
	public function viewOfferingCategory()
    {
		$data['list'] = $this->model->getResultData('offering_category',[]);
		$this->load->view('offering_category/tb',$data);
    }
	public function editOfferingCategory()
    {
        $response=array();
		$data = $this->model->getRowData('offering_category',['id' => $_POST['id']]);
		$response = array(
			'id' => $_POST['id'],
			'name' => $data['name'],
		);
		echo json_encode($response);
    }
	public function updateOfferingCategory()
    {
			if(isset($_POST['id']))
			{
				$array = array(
					'name' => $_POST['name'],
				);
				
				if($this->model->edit('offering_category',$array,['id'=>$_POST['id']]))
				{
					$lead_id = $_POST['id'];
					$this->createLog($this->session->userdata('id'),$this->session->userdata('usertype'),$lead_id,'edit','offering category');

					echo json_encode(['return'=>true,'msg'=>'Updated Successfully']);
				}
			}
		}
    public function detail()
    {
        $id=$this->uri->segment(2);
        $data['title'] = 'Offering Category Detail';
		$data['data'] = $this->model->getRowData('offering_category',['id'=>$id]);
        $page = 'offering_category/detail';
        $this->header_and_footer($page, $data);
    }
	
   	
}
