<?php 

function getFreeVehicles($zaciatok, $koniec){
	$CI =& get_instance();	
	$CI->load->model('model_vehicles');
	$engagedVehicles = $CI -> model_vehicles -> getAllEngagedVehicles($zaciatok, $koniec);
	$allVehicles = $CI -> model_vehicles -> getAllActiveVehicles();
	$arrayAllVehicles = array();
	$arrayEngagedVehicles = array();
	$freeVehicles = array();
	
	 
	if (empty($engagedVehicles)) {
		return $CI -> model_vehicles ->getIdTypeNumberVehicles(); 
	} else{
		foreach($allVehicles as $allVehicle){
			array_push($arrayAllVehicles,$allVehicle->ID_VOZ);	
		}
		foreach($engagedVehicles as $engagedVehicle){
			array_push($arrayEngagedVehicles,$engagedVehicle->ID_VOZ);	
		}
			$results = array_diff($arrayAllVehicles,$arrayEngagedVehicles);
		
		foreach($results as $result) {		
			$freeVehicles[]=$CI -> model_vehicles -> getIdAndTypeVehicle($result);		
		}
		if (empty($freeVehicles)){
			return FALSE;
		} else {
			return $freeVehicles;	
		}	
	}
	
	foreach($allVehicles as $allVehicle){
		array_push($arrayAllVehicles,$allVehicle->ID_VOZ);	
	}
	foreach($engagedVehicles as $engagedVehicle){
		array_push($arrayEngagedVehicles,$engagedVehicle->ID_VOZ);	
	}
	$results = array_diff($arrayAllVehicles,$arrayEngagedVehicles);
	
	foreach($results as $result) {		
		$freeVehicles[]=$CI -> model_vehicles -> getIdAndTypeVehicle($result);		
	}
	if (empty($freeVehicles)){
		return FALSE;
	} else {
		return $freeVehicles;	
	}
	
		
}



function getTypesOfVehicles(){
	$CI =& get_instance();	
	$CI->load->model('model_vehicles');
	return $CI -> model_vehicles -> getTypesOfVehicles();
}

function getCountOfVehicle($pocetMiest, $zaciatok, $koniec){
	$CI =& get_instance();	
	$CI->load->model('model_vehicles');
	$pocet = 0;
	$engagedVehicles = $CI -> model_vehicles -> getAllEngagedVehicles($zaciatok, $koniec);
	if ($engagedVehicles==0){
		$pocet = $CI -> model_vehicles -> getCountOfVehicles($pocetMiest);
		return $pocet->PocetMiest;			
	} else {
		return $data;
	}
	return $pocet;
}

function getStatusVehicle($id_voz){
	$CI =& get_instance();	
	$CI->load->model('model_vehicles');
	$status = $CI -> model_vehicles -> getStatusVehicle($id_voz);	
	if (($status->Status_vozidla)==0){
		return FALSE;
	} else {
		return TRUE;
	}
}


?>