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

class Dashboard extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->library('layouts');

		checkDashboard();
		
		$this->session->set_userdata('menu', "dashboard");
	}

	public function index() {
		
		redirect('dashboard/homedashboard/0');
		
	}
	
	public function homedashboard(){
	
		$this->lang->load('dashboard', $this->session->userdata('language'));
		
		$this->load->model('dashboard_model');
		
		$positionID = $this->uri->segment(3);
		
		$data['totalComp'] = $this->dashboard_model->getTotComp();
		$data['totalVoter'] = $this->dashboard_model->getTotVoter();
		$data['totalVote'] = $this->dashboard_model->getTotVote();
		$data['totalnonvoted'] = $this->dashboard_model->getTotNonVote();
		$data['totalBlock'] = $this->dashboard_model->getTotBlock();
		$data['totalPosition'] = $this->dashboard_model->getTotPosition();
		
		$data['positionList'] = $this->dashboard_model->getdesignation();
		
		$data['firstVoter'] = $this->dashboard_model->getfirstvoter();
		$data['lastVoter'] = $this->dashboard_model->getlastvoter();
		$data['fastestVoter'] = $this->dashboard_model->getfastestvoter();
		$data['slowestVoter'] = $this->dashboard_model->getslowestvoter();
		
		if($positionID == 0){
			$getvote = ($data['positionList'])?$this->dashboard_model->getvote_bydesignation($data['positionList'][0]->positionID):null;
		
			$data['checkelected'] = ($getvote)?sizeof($getvote):0;
			
			$data['positionID'] = ($data['positionList'])?$data['positionList'][0]->positionID:null;
		}
		else{
			$getvote = $this->dashboard_model->getvote_bydesignation(2);
		
			$data['checkelected'] = ($getvote)?sizeof($getvote):0;
			
			$data['positionID'] = $positionID;
		}

		$this->layouts->view('dashboard', array(), $data);	
	
	}

	public function getvotebydesignation(){
		
		$this->load->model('dashboard_model');
		
		$positionList = $this->dashboard_model->getdesignation();
		
		$positionID = $this->input->post('positionID');
		
		$getvote = $this->dashboard_model->getvote_bydesignation($positionID);
		
		$checkelected = sizeof($getvote);
		
		if($getvote){
			echo json_encode(array('status' => 'success', 'message' => $getvote, 'checkelected' => $checkelected));
		}
		
	}
	
	public function refreshtotalvote(){
	
		$this->load->model('dashboard_model');
		
		$totalvote = $this->dashboard_model->getTotVote();
	
		if($totalvote){
			echo json_encode(array('status' => 'success', 'message' => $totalvote));
		}
	
	}
	
	
	
}

?>
