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

class Driver extends CI_Controller {		
	
	
	public function showAllInventories($modeType, $mode){		
		$this->load->model('model_driver');
		$data['modeType'] = $modeType;
		$data['mode'] = $mode;
		
		switch($modeType){
			case 1: 

				switch($mode){
					case 1:
						$data['inventories']=$this->model_driver->getBasicInfo();
					break;
					case 2:
						$data['inventories']=$this->model_driver->getBasicInfo();
					break;
					case 3:
						$data['inventories']=$this->model_driver->getMyDrives($this->session->userdata['id_zamestnanca']);
					break;
					case 4:
						$data['inventories']=$this->model_driver->getMyDrivesArchive($this->session->userdata['id_zamestnanca']);
					break;
				}
			break;
			case 2:
				switch($mode){
					case 1:
						$data['inventories']=$this->model_driver->getBasicInfo();
					break;
					case 2:
						$data['inventories']=$this->model_driver->getBasicInfo();
					break;
					case 3:
						$data['inventories']=$this->model_driver->getMyInventories($this->session->userdata['id_zamestnanca']);
					break;
					case 4:
						$data['inventories']=$this->model_driver->getMyInventoriesArchive($this->session->userdata['id_zamestnanca']);
					break;
				} 
			break;
		}
		
		$this->load->view('include/header');
		$this->load->view('driver/driver_inventories', $data);
		$this->load->view('include/footer');	
	}	 
	
		public function showVehicles($mode){
		$this->load->model('model_vehicles');		
		$data['mode']=$mode;		
		switch ($mode){
			case 1:
				$data['vehicles']=$this->model_vehicles->getAllVehicles2();
			break;
			case 2:
				$data['vehicles']=$this->model_vehicles->getAllActiveVehicles();
			break;
			case 3:
				$data['vehicles']=$this->model_vehicles->getAllUnactiveVehicles();
			break;
		}		
		$this->load->view('include/header');
		$this->load->view('driver/driver_vehicles', $data);
		$this->load->view('include/footer');	
	}
	
	public function LogOnInventoryAsEmployee($mode,$id_inv) { 
		$this->load->model('model_inventory');
		$this->model_inventory->LogOnInventory2($id_inv, $this->session->userdata['id_zamestnanca']);
		$Reservations = $this->model_inventory->getInvetoryReservations($id_inv);
		$Status=FALSE;
			
		foreach ($Reservations as $Reservation) {
			$Count = $this->model_inventory->getCountOfEmployeesOnInv($Reservation->ID_REZ);
			$Seats = $this->model_inventory->getNumberOfSeats($Reservation->ID_REZ);
			if ((($Count->Pocet)<($Seats->Pocet_miest-1)) AND ($Status==FALSE)) {
				$this->model_inventory->LogOnReservation($Reservation->ID_REZ,$this->session->userdata['id_zamestnanca']);
				$Status=TRUE;				
				redirect(base_url('driver/showAllInventories/2/'.$mode));
			}
		}
	}
	
	public function LogOnInventoryAsDriver($mode,$id_inv) { 
		$this->load->model('model_driver');
		$reservationID = $this->model_driver->getFreeReservation($id_inv);
		$this->model_driver->LogOnInventoryAsDriver($reservationID, $this->session->userdata['id_zamestnanca']);
		redirect(base_url('driver/showAllInventories/1/'.$mode));	
	}
	
	public function LogOutInventoryAsEmployee($id_inv) { 
		$this->load->model('model_inventory');
		$this->model_inventory->LogOutInventory($id_inv, $this->session->userdata['id_zamestnanca'],$this->model_inventory->getReservationInfo($id_inv, $this->session->userdata['id_zamestnanca']));
		redirect(base_url().'driver/showAllInventories/2/3');
	}
	
	public function LogOutInventoryAsDriver($id_inv) { 
		$this->load->model('model_driver');
		$this->model_driver->LogOutInventoryAsDriver($id_inv, $this->session->userdata['id_zamestnanca']);
		redirect(base_url('driver/showAllInventories/1/3'));
	}	
	
	public function DetailOfInventory($modeType, $mode, $modeDet, $id_inv) {
		$this->load->model('model_lead_employee');
			$data['modeType']=$modeType; 
			$data['mode']=$mode;
			$data['modeDet']=$modeDet;
			$data['id_inv']=$id_inv; 
			switch($modeDet){
				case 1:
					$data['inventoryInfo'] = $this->model_lead_employee->getGeneralInventoryInfo($id_inv);
					 
					$this->load->library('googlemaps');
					$config = array();
					$config['center'] = $data['inventoryInfo']->GPS;
					$config['map_height'] = 374;
					$config['map_width'] = 600;
					
					$marker = array();
					$marker['position'] = $data['inventoryInfo']->GPS;
		
					$this->googlemaps->add_marker($marker);
					$this->googlemaps->initialize($config);
					$data['map'] = $this->googlemaps->create_map();
					$this->load->view('include/header2', $data);
					
				break; 
				case 2:
					$data['inventoryInfo'] = $this->model_lead_employee->getOnlyInventoryReservations($id_inv);
					$this->load->view('include/header');
				break;
			}			
		$this->load->view('driver/driver_inventory_detail', $data);
		$this->load->view('include/footer');
	}
	
	public function redirectVehicleDetail($mode,$id_voz){
		$this->load->model('model_vehicles');
		$data["mode"]=$mode;
		$data['vehicle'] = $this->model_vehicles->getVehicleInfo($id_voz);
		
		$this->load->view('include/header');
		$this->load->view('driver/driver_vehicle_detail', $data);
		$this->load->view('include/footer');
	}
	
	
}		
		
	
	
	
		
		
	
		
		



	


