<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hindu_festival extends REF_Controller
{
	public  function __construct()
	{
		parent::__construct();// load library
		$this->load->library('upload');
		$this->load->model('hindu_festival_model','',TRUE);
		$this->uri_key_index = 0;
	}
		
	public function index()	
	{	
		$data 				= array();
        $data['results']	= $this->hindu_festival_model->hindu_festival_lists();

        if (!empty($this->session->flashdata('success'))) 
           $data['success'] = $this->session->flashdata('success');
        else 
            $data['error'] = $this->session->flashdata('error');
        

        $actions 			= $this->actions();

        $data['add_btn']    = 'Create New Hindu Festival';

        $data['view_link']  = $actions['view'] . '/';

        $data['add_link']   = $actions['add'];

        $data['edit_link']  = $actions['edit'] . '/';

        $data['delete_link']= $actions['delete'] . '/';

        $service_menu_id = get_master_controller_id($actions['controller']);

        $data['service_menu_id'] = array('service_menu_id' => $service_menu_id, 'menu_type' => '1');

        $this->render($data, 'hindu_festival/list');
	}
		
	public function add() 
	{
		$data 					= array();
        $actions 				= $this->actions();
        $data['form_action']	= $actions['insert'];

        $this->render($data, 'hindu_festival/add');
	}
		
	public function insert() 
	{ 
		$date = date('Y-m-d',strtotime($this->input->post('date')));
		$data = array(
				'name' => $this->input->post('name'),
				'name_t' => $this->input->post('name_t'),
				'date' => $date,
				'day' => $this->input->post('day'),
				'day_t' => $this->input->post('day_t'),
				'status' => $this->input->post('status'),		
				'created_on' => date('Y-m-d H:i:s'),
				'created_by' => $this->user_data['user_id']
		);
	
		$insert_id = $this->hindu_festival_model->insert($data);
		
		if ($insert_id)		
			$this->session->set_flashdata('success', 'Festivals details added successfully');		
		else		
			$this->session->set_flashdata('error', 'Festivals details not added!');
		
		
		redirect('hindu_festival', 'refresh');
	}
	
	
	public function edit($festival_id) 
	{
		if (empty($festival_id)) {
            show_400_error();
        }

        $data 								= array();
        $data['general_festivals_details'] 	= $this->hindu_festival_model->get_hindu_festival_details_by_id($festival_id);
        $actions 							= $this->actions();
        $data['form_action'] 				= $actions['update'] . '/' . $festival_id;

        $this->render($data, 'hindu_festival/edit');
	}

	public function update($id) 
	{
		$date = date('Y-m-d',strtotime($this->input->post('date')));
		$data = array(
				'name' => $this->input->post('name'),
				'name_t' => $this->input->post('name_t'),
				'date' => $date,
				'day' => $this->input->post('day'),
				'day_t' => $this->input->post('day_t'),
				'status' => $this->input->post('status'),		
				'updated_on' => date('Y-m-d H:i:s'),
				'updated_by' => $this->user_data['user_id']
		);
		
		$update_id = $this->hindu_festival_model->update($id, $data);
		
		if ($update_id > 0)		
			$this->session->set_flashdata('success', 'Festivals details updated successfully');			
		else		
			$this->session->set_flashdata('error', 'Festivals details not updated!');
		
		
		redirect('hindu_festival', 'refresh');
	}
	
	public function delete($id) 
	{ 
		if (empty($id)) {
            show_400_error();
        }

        $update = array ( 
            'status' 		=> 2,
            'updated_by' 	=> $this->user_data['user_id'],
            'updated_on'	=> date('Y-m-d H:i:s')
        );
		
        if ($this->hindu_festival_model->update($id, $update) > 0) {
            $this->session->set_flashdata('success', 'Festivals details deleted successfully');
        } else 
            $this->session->set_flashdata('error', 'Festivals details not deleted!');
		
		redirect('hindu_festival', 'refresh');
	}
	
	public function view($id)
   	{
		if (empty($id)) {
            show_400_error();
        }

        $data 								= array();
        $data['general_festivals_details'] 	= $this->hindu_festival_model->get_hindu_festival_details_by_id($id);

        $this->render($data, 'hindu_festival/view');
	}	
}
?>