<?php



if (!defined('BASEPATH'))

    exit('No direct script access allowed');



class UserModel extends CI_Model {



    function __construct() {

        // Call the Model constructor

        parent::__construct();

        $this->load->database();

        $this->load->library('session');

    }



    public function getcategories() {

	if(!isset($_SESSION["login_type"]) && !isset($_SESSION["user_id"]))

	{

		echo  header('location:'.base_url().'index.php/Login/logout');	

	}

	else

	{

			$login_type = $this->session->userdata('login_type');

			if ($login_type == 'super_admin') {

				$session_login_id = $_SESSION['login_id'];

				$sql = 'select * from tbl_category';

			}

			/*else {

				$session_login_id = $_SESSION['rest_id'];

			  

				$sql = 'select * from tbl_category job,tbl_restaurant_registration rest where job.rest_id=rest.rest_id and rest.rest_job_post="Yes" and job.rest_id='.$session_login_id;

			}*/

			$query = $this->db->query($sql);

			$result = $query->result();

			return $result;

		}

    }



 



    public function insert_User($fname, $lname, $dob, $password,$cat_button,$user_id) {

			$session_login_id = $_SESSION['user_id'];

         if ($this->input->post('add_user')) 

		 {

		 

			  $sql = 'INSERT INTO user_master (category_name,category_desc, category_small_img, category_photo) values ("'.$category_name.'","'.$category_desc.'","'.$category_small_img.'", "'.$fileName.'")';

        }

		else

		{

		 $sql = 'update user_master set category_name="'.$category_name.'", category_desc="'.$category_desc.'", category_small_img="'.$category_small_img.'", category_photo="'.$fileName.'" where tbl_category_id='.$category_id;

      

		}

		$result = $this->db->query($sql);

        redirect(base_url() . 'index.php/category');

    }



    



    public function edit_category($id) {

       $query = $this->db->query("SELECT * FROM tbl_category WHERE tbl_category_id = $id");

        return $query->result_array();

    }



    public function view_category($id) {

        $query = $this->db->query("SELECT * FROM tbl_category  WHERE tbl_category_id = $id");

        return $query->result_array();

    }

	public function delete_category($id) {

			$query = "delete from  tbl_category where tbl_category_id = $id";

		    $result = $this->db->query($query);

		}

}



?>				