<?php 
// if ( ! defined('BASEPATH')) exit('No direct script access allowed');
defined('BASEPATH') OR exit('No direct script access allowed');
class Dashboard extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('My_model');
		$this->load->model('Dashboard_model');
		$this->load->library('admin_layout');
		$this->load->helper('jsondata_helper');	
	}

	function index() {
		if(!$username=$this->session->userdata('logged_in')) redirect(base_url().'login');
		$user_id = $this->session->userdata('user_id');
			
		$header_data = array(
		  'username'  		=> $username,
		  'user_id'    		=> $user_id
		);
		
		$this->admin_layout->set_title("Dashboard");
		$this->admin_layout->set_description("");
		$this->admin_layout->set_data($header_data);
		// $data = '';

		// $get_claims = $this->My_model->get_rows('claims',array('admin_id'=>$user_id));
		$get_claims = $this->Dashboard_model->getclaims($user_id);
		
		// echo $this->db->last_query();
		// $claims= array();
		// foreach($get_claims as $row){
		// 	$row_array['claim_id'] = $row->claim_id;
		// 	$row_array['name'] = $row->name;
		// 	array_push($claims,$row_array);
		// }

		// $data['claims'] = json_encode($get_claims);
		// $data['header'] = json_fields($get_claims); 
		// $data['rows'] = json_encode($get_claims);

		// $options = array(     
		// 	'hideFirstCol'    => 'Y',
		// 	'displayCounter'  => 0, //0= No;1=ASC; -1=DESC
		//   ); 
	  
		// $data['options'] = json_encode($options);  


		$data['claims'] = $get_claims;
		$data['err_claim'] = 'No Claims available'; 


		
		$content = "admin/view_dashboard";
		$this->admin_layout->view($content,'',$data,true);
	
	}


	public function get_docus(){
	
		$refno = $this->input->post('refno',TRUE);	
		
		// echo "refno:".$refno;
		
		// $res = $this->My_model->get_rows('claim_docus',array('refno'=>$refno));
		$res = $this->Dashboard_model->getdocus($refno);
		//echo $this->db->last_query();
		$result = json_encode($res);

		// if(!$res) {
		//   echo json_encode(array("SQL" => $this->db->last_query()));
		// }
	
		// else 
		echo $result;
	
	
	}


}
