<?php 
function returnStringId($id_zam){ //použité
	if (strlen($id_zam)==1) {
			return "0000".$id_zam;
	} elseif (strlen($id_zam)==2) {
			return "000".$id_zam;
	} elseif (strlen($id_zam)==3) {
			return "00".$id_zam;
	} elseif (strlen($id_zam)==4) {
			return "0".$id_zam;
	} else {
			echo $id_zam;
	}
}
function drawInventoryFalseEmployee($modeType, $mode, $id_emp, $inventory){
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					if ((amILoggedAsDriver($inventory->ID_INV, $id_emp)==TRUE) OR 
					(amILoggedAsEmployee($inventory->ID_INV, $id_emp)==TRUE) OR
					(isFreeInventory($inventory->ID_INV,$inventory->Pocet_zamestnancov)==FALSE) OR
					(haveIFreeTimeReservation($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE) OR
					(haveIFreeTimeInventory($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE)){
						echo "<img src='".base_url('pictures/red_diod.png')."' height='20%'>";	
					} else {
						echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
					}							
				echo "</td>";
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
							
				echo "<td style='font-style: italic; font-size:12px; padding-right:10px'>";
					if (amILoggedAsDriver($inventory->ID_INV, $id_emp)==TRUE){
						echo "Na túto inventúru ste už prihlásený ako vodič.";
					} elseif (amILoggedAsEmployee($inventory->ID_INV, $id_emp)==TRUE){
						echo "Na túto inventúru ste už prihlásený ako zamestnanec.";
					} elseif (isFreeInventory($inventory->ID_INV,$inventory->Pocet_zamestnancov)==FALSE){
						echo "Inventúra je už plná.";
					} elseif (haveIFreeTimeReservation($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE){
						echo "Túto dobu ste už prihlásený ako vodič na inej inventúre.";
					} elseif (haveIFreeTimeInventory($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE){
						echo "Túto dobu ste už prihlásený ako zamestnanec na inej inventúre.";	
					} else {
						echo '<div class="button-group">';
								echo '<a href="'.base_url('driver/LogOnInventoryAsEmployee/'.$mode.'/'.$inventory->ID_INV).'" class="button">Prihlásiť (zamestnanec)</a>';
								echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
						echo '</div>';	
					}
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";		
		
}

function drawInventoryFalseDriver($modeType, $mode, $id_emp, $inventory){
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					if ((amILoggedAsDriver($inventory->ID_INV, $id_emp)==TRUE) OR 
					(amILoggedAsEmployee($inventory->ID_INV, $id_emp)==TRUE) OR
					(isFreeReservation($inventory->ID_INV)==FALSE) OR
					(haveIFreeTimeReservation($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE) OR
					(haveIFreeTimeInventory($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE)){
						echo "<img src='".base_url('pictures/red_diod.png')."' height='20%'>";	
					} else {
						echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
					}							
				echo "</td>";
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
							
				echo "<td style='font-style: italic; font-size:12px; padding-right:10px'>";
					if (amILoggedAsDriver($inventory->ID_INV, $id_emp)==TRUE){
						echo "Na túto inventúru ste už prihlásený ako vodič.";
					} elseif (amILoggedAsEmployee($inventory->ID_INV, $id_emp)==TRUE){
						echo "Na túto inventúru ste už prihlásený ako zamestnanec.";
					} elseif (isFreeReservation($inventory->ID_INV)==FALSE){
						echo "Inventúra je už plná.";
					} elseif (haveIFreeTimeReservation($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE){
						echo "Túto dobu ste už prihlásený ako vodič na inej inventúre.";
					} elseif (haveIFreeTimeInventory($id_emp, $inventory->Datum_zaciatku,$inventory->Datum_konca)==FALSE){
						echo "Túto dobu ste už prihlásený ako zamestnanec na inej inventúre.";	
					} else {
						echo '<div class="button-group">';
								echo '<a href="'.base_url('driver/LogOnInventoryAsDriver/'.$mode.'/'.$inventory->ID_INV).'" class="button">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspPrihlásiť (vodič)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>';
								echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
						echo '</div>';	
					}
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";		
		
}

function drawInventoryTrueEmployee($modeType, $mode, $id_emp, $inventory){	
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
				echo "</td>";
				
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
				
				echo "<td>";
					echo '<div class="button-group">';
						echo '<a href="'.base_url('driver/LogOnInventoryAsEmployee/'.$mode.'/'.$inventory->ID_INV).'" class="button">Prihlásiť (zamestnanec)</a>';
						echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
					echo '</div>';
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";	
}

function drawInventoryTrueDriver($modeType, $mode, $id_emp, $inventory){	
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
				echo "</td>";
				
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
				
				echo "<td>";
					echo '<div class="button-group">';
						echo '<a href="'.base_url('driver/LogOnInventoryAsDriver/'.$mode.'/'.$inventory->ID_INV).'" class="button">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspPrihlásiť (vodič)&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>';
						echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
					echo '</div>';
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";	
}

function drawInventoryTrueLogOutEmployee($modeType, $mode, $id_emp, $inventory){	
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
				echo "</td>";
				
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
				
				echo "<td>";
					echo '<div class="button-group">';
						echo '<a href="'.base_url('driver/LogOutInventoryAsEmployee/'.$inventory->ID_INV).'" class="button">Odhlásiť(zamestnanec)</a>';
						echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
					echo '</div>';
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";	
}

function drawInventoryTrueLogOutDriver($modeType, $mode, $id_emp, $inventory){	
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";
					echo "<img src='".base_url('pictures/green_diod.png')."' height='20%'>";
				echo "</td>";
				
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
				
				echo "<td>";
					echo '<div class="button-group">';
						echo '<a href="'.base_url('driver/LogOutInventoryAsDriver/'.$inventory->ID_INV).'" class="button">Odhlásiť(vodič)</a>';
						echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
					echo '</div>';
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";	
}

function drawInventoryTrueArchive($modeType, $mode, $id_emp, $inventory){	
	echo "<div class='vehicle_div' align='left'>";
		echo "<table class='vehicle_table' style='margin-left:35px; padding-top:15px;margin-top:0px; margin-bottom:10px;'>";		
			echo "<tr>";
				echo "<td width='50px' style='text-align: center'>";

				echo "</td>";
				
				echo "<td width='100px' style='text-align: center; margin-left:0px'>";
					echo "<b>ID inventúry</b>";					
					echo "</br>";
					echo returnStringId($inventory->ID_INV);
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Zákazník</b>";
					echo "</br>";
					echo $inventory->Nazov_spolocnosti.", ".$inventory->Mesto;
				echo "</td>";
				
				echo "<td width='90px' style='text-align: center'>";
					echo "<b>Počet zam.</b>";
					echo "</br>";
					echo $inventory->Pocet_zamestnancov;
				echo "</td>";
				
				echo "<td width='120px' style='text-align: center'>";
					echo "<b>Vedúci inventúry</b>";
					echo "</br>";
					if ($inventory->ID_Veduci==NULL){
						echo "-neurčené-";
					} else {
						echo $inventory->Meno."&nbsp".$inventory->Priezvisko;	
					}
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas začiatku</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_zaciatku));
				echo "</td>";
				
				echo "<td width='160px' style='text-align: center'>";
					echo "<b>Dátum a čas konca</b>";
					echo "</br>";
					echo date('d.m.Y G:i',strtotime($inventory->Datum_konca));
				echo "</td>";
				
				echo "<td>";
					echo '<div class="button-group">';
						echo '<a href="'.base_url('driver/DetailOfInventory/'.$modeType.'/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';								
					echo '</div>';
				echo "</td>";			
			echo "</tr>";
		echo "</table>";
	echo "</div>";	
}

function amILoggedAsEmployee($id_inv, $id_emp){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> amILoggedAsEmployee($id_inv, $id_emp);		
}

function amILoggedAsDriver($id_inv, $id_emp){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> amILoggedAsDriver($id_inv, $id_emp);		
}

function isFreeReservation($id_inv){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> isFreeReservation($id_inv);	
}

function isFreeInventory($id_inv, $count_emp){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> isFreeInventory($id_inv, $count_emp);	
}

function haveIFreeTimeReservation($id_emp, $start, $end){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> haveIFreeTimeReservation($id_emp, $start, $end);		
}

function haveIFreeTimeInventory($id_emp, $start, $end){
	$CI =& get_instance();	
	$CI->load->model('model_driver');
	return $CI -> model_driver -> haveIFreeTimeInventory($id_emp, $start, $end);	
}

?>