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

class Feedback extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/home
	 *	- or -
	 * 		http://example.com/index.php/home/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/home/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	 
	public function index()
	{
	    
	    // loading common model
	    $this->load->model('Common_model');
	    
	    $column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Feedback';
		
        // we are loading admin dashboard
		$this->load->view('website/feedback',$data);	
	}
	
	public function add(){
	    
	    $this->load->model('Common_model');
	    date_default_timezone_set('Asia/Kolkata');
        foreach ($_POST as $key => $value) {
            if (empty($value)) {
                $this->session->set_flashdata('error',''.strtoupper("$key").' Can not be Empty.');
			    redirect(base_url('feedback'));
			    exit();
            }
            if($key != 'submit'){
                $data[$key] = $value;
            }
            
        }
        
        $data['addon'] = date('Y-m-d H:i:s');
        $data['status'] = 0;
        
        $table ='tbl_feedback';
        
        // we are updating data from tbl_p_type
        $result  = $this->Common_model->Create($data,$table);
        
        if($result == true){
            $this->session->set_flashdata('success','SUCCESS!! Your Feedback is Submited Successfully.');
		    redirect(base_url('feedback'));
		    exit();
        } else{
            $this->session->set_flashdata('error','Something went Wrong .');
		    redirect(base_url('feedback'));
		    exit();
        }
        
	}
}