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

class hotel extends MY_Controller{
	function __construct(){
        parent::__construct();
        $this->load->model('hotel_model', '', TRUE);
        // if($this->data['userid']==''){
        //     redirect($this->data['base_url'] . 'home');   
        //     exit;
        // }
    }
    function index(){
        if($this->input->post()){            
            $data = $this->input->post('data');
            $data['status']='1';
            $data['is_delete']='0';
            $data['create_datetime']=date('Y-m-d h:i:s');
            $data['created_ip']=$_SERVER['REMOTE_ADDR'];
            $hoteldata = $this->hotel_model->addhotel($data);
            $this->session->set_flashdata('message',"hotel Added Successfully.");
            redirect($this->data['base_url'] . 'hotel/');
        } 
        $this->data['hotel'] = $this->hotel_model->allhotel_details();
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']='New hotel';
        $this->data['tpl_name']= "hotel.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    } 
    
    function update(){
        if($this->input->post()){            
            $data = $this->input->post('data');
            $data['status']='1';
            $data['is_delete']='0';
            $data['created_ip']=$_SERVER['REMOTE_ADDR'];
            $hoteldata = $this->hotel_model->edithotel($data);
            $this->session->set_flashdata('message',"hotel Update Successfully.");
            redirect($this->data['base_url'] . 'hotel/');            
        } 
        $hotelid = $this->uri->segment(3);
        $this->data['hotel_details'] = $this->hotel_model->single_hotel_details($hotelid);
        $this->data['hotel'] = $this->hotel_model->allhotel_details();
        $this->data['message'] = $this->session->flashdata('message');
        $this->data['breadcrumb']='Edit hotel';
        $this->data['tpl_name']= "hotel.tpl";
        $this->smarty->assign('data', $this->data);
        $this->smarty->view('template.tpl');  
    }
    function delete(){
        $hotelid = $this->uri->segment(3);
        if($hotelid!=''){            
            $data['is_delete'] = '1';
            $data['id'] = $hotelid;
            $edithotel = $this->hotel_model->edithotel($data);
            $this->session->set_flashdata('message',"hotel delete Successfully.");
            redirect($this->data['base_url'] . 'hotel/');
        }else{
             redirect($this->data['base_url'] . 'hotel/');
        }
    }   
}
