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

class Icd_login_ctrl extends user_icd_index {
 
	
	public function __construct(){
		parent::__construct(); 
		$data = array();
		$this->load->model('admin_model');
	}
	
	/*----------------- load dashboard -----------------*/
	public function index(){	
		// var_dump($this->user['panel_type']);return;	
		$data['active_cls'] 	= 'dash';	
		$data['sdata'] 			= array();
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
		if($this->user['panel_type']=='4'){
			$data['subview'] 	= 'icd/dashboard/mceo_dashboard';
		}else if($this->user['panel_type']=='5'){
			$data['subview'] 	= 'icd/dashboard/pteo_dashboard';
		}else if($this->user['panel_type']=='6'){ //old username : Port Payment Officer 
			$data['subview'] 	= 'icd/dashboard/fo_dashboard';			
			// redirect('icd/ppo_ctrl/finance_entry_approve_list');
		}else if($this->user['panel_type']=='7'){ //old username : Finance Entry Addition Officer 
			// redirect('icd/feao_ctrl/finance_addition_list');
			$data['subview'] 	= 'icd/dashboard/fc_dashboard';			
		}
		else if($this->user['panel_type']=='8'){
			redirect('icd/tno_ctrl/truck_nomination_list');
		}
		else if($this->user['panel_type']=='9'){
			$data['subview'] 	= 'icd/dashboard/geo_dashboard';
		}else if($this->user['panel_type']=='10'){
			$data['subview'] 	= 'icd/dashboard/igeo_dashboard';
		}else if($this->user['panel_type']=='11'){
			$data['subview'] 	= 'icd/dashboard/iao_dashboard';
		}else if($this->user['panel_type']=='12'){
			$data['subview'] 	= 'icd/dashboard/iomo_dashboard';
		}
		else if($this->user['panel_type']=='13'){ //old username : Container Verificationn Officer 
			$data['subview'] 	= 'icd/dashboard/cvo_dashboard';
			
			// redirect('icd/cvo_ctrl/container_verification_list');
		}
		else if($this->user['panel_type']=='20'){
			redirect('icd/icd_rep_ctrl/icd_rep_search/icd');
		}
		
		// else if($this->user['panel_type']=='16'){
		// 	redirect('icd/crao_ctrl/container_release_approve_list');
		// }
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load login page -----------------*/
	public function login(){
		// var_dump('ddd');return;
		$data['url_list'] 	= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
			// echo $this->db->last_query();return;
		
		$this->load->view('icd/common/icd_login',$data);
	}
	
	/*----------------- login submition -----------------*/
	
	public function submit(){
		$return = array('status'=>false);
		if(isset($_POST["u_name"])){
			$user_name 				= $this->input->post("u_name");
			$password 				= $this->input->post("pwd");
			$ul_type 				= $this->input->post("ul_type");
			$l_data 				= $this->admin_model->signin($user_name,$password);
			// echo $this->db->last_query();
			// 	var_dump($l_data); 
			// echo	$l_data['i_user_id'];
			$l_data_re 				= $this->admin_model->check_role($l_data['i_user_id'],$ul_type);

			// return;
			 
			if($l_data_re==false){
					$this->session->set_flashdata('tos_error', 'Sorry your selected user type is restricted');
					redirect("icd/icd_login_ctrl/login");
			}
			else{
				$l_data['panel_type']  	= $ul_type;
				if($l_data['i_type']!="0"){
					if($l_data!=false){ 
						$this->session->set_userdata('login_state',$l_data );
						redirect('icd/icd_login_ctrl/index');
					}
					else redirect("icd");
				}else{
					$this->session->set_flashdata('tos_error', 'Sorry your selected user type is restricted');
					redirect("icd/icd_login_ctrl/login");
				}
			}

			
			
		}
		else redirect("icd");
	}
	
	/*----------------- load dashboard -----------------*/
	public function token_type_list($csl_id){	
		// var_dump($this->user['panel_type']);return;	
		$data['active_cls'] 	= 'dash';	
		$data['sdata'] 			= array();
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
		if($csl_id=='1'){
			$data['subview'] 	= 'icd/dashboard/local_dashboard';
		}else if($csl_id=='2'){
			$data['subview'] 	= 'icd/dashboard/transit_dashboard';
		}
		
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load local dashboard -----------------*/
	public function local_list($local_type){	
		// var_dump($this->user['panel_type']);return;	
		$data['active_cls'] 	= 'dash';	
		$data['sdata'] 			= array();
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
		if($local_type=='1'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/local/lcm_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/local/lcm_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/local/lcm_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/local/lcm_iomo_dashboard';
			}	
		}
		else if($local_type=='2'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/local/llem_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/local/llem_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/local/llem_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/local/llem_iomo_dashboard';
			}	
		}
		else if($local_type=='3'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/local/lec_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/local/lec_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/local/lec_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/local/lec_iomo_dashboard';
			}	
		}
			
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load transit dashboard -----------------*/
	public function transit_list($transit_type){	
		// var_dump($this->user['panel_type']);return;	
		$data['active_cls'] 	= 'dash';	
		$data['sdata'] 			= array();
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
		if($transit_type=='1'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/transit/tm_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/transit/tm_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/transit/tm_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/transit/tm_iomo_dashboard';
			}	
		}else if($transit_type=='2'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/transit/tec_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/transit/tec_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/transit/tec_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/transit/tec_iomo_dashboard';
			}	
		}else if($transit_type=='3'){
			if($this->user['panel_type']=='9'){
				$data['subview'] 	= 'icd/dashboard/transit/tcm_geo_dashboard';
			}else if($this->user['panel_type']=='10'){
				$data['subview'] 	= 'icd/dashboard/transit/tcm_igeo_dashboard';
			}else if($this->user['panel_type']=='11'){
				$data['subview'] 	= 'icd/dashboard/transit/tcm_iao_dashboard';
			}else if($this->user['panel_type']=='12'){
				$data['subview'] 	= 'icd/dashboard/transit/tcm_iomo_dashboard';
			}	
		}
			
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	public function token_search(){	
		// var_dump($this->user['panel_type']);return;	
		$data['active_cls'] 	= 'search_clss';	
		$data['sdata'] 			= array();
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');
		$data['subview'] 		= 'icd/search/token_search';			
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}


	

	
	public function logout(){		
		$redirect_url = 'icd/icd_login_ctrl/login';		
		$this->session->sess_destroy();
		redirect(''.$redirect_url.'');
	}
	
	
	
	
}
