<?php
	if ($this->session->userdata('permisson')==1) {		
		$CI =& get_instance();
		$CI->load->library('libraryprofile');		
		$CI->libraryprofile->showMenuBarManager($this->session->userdata('meno'),$this->session->userdata('priezvisko')); 	
			
  					
		echo '<div id="default_container">';
			echo "<h3>Editácia vozidla: </h3>";
			echo form_open(base_url('manager/vehicleEditSave/'. $Vehicle->ID_VOZ),'onkeypress="return event.keyCode != 13;"');
			echo "<table class='profile_table'>";
			echo "<tr>";
					echo "<td>";
						echo "<b>Identifikačné číslo vozidla: </b>";
					echo "</td>";
					echo "<td>";
						if (strlen($Vehicle->ID_VOZ)==1) {
							echo "0000";
							echo $Vehicle->ID_VOZ;
						} elseif (strlen($Vehicle->ID_VOZ)==2) {
							echo "000";
							echo $Vehicle->ID_VOZ;
						} elseif (strlen($Vehicle->ID_VOZ)==3) {
							echo "00";
							echo $Vehicle->ID_VOZ;
						} elseif (strlen($Vehicle->ID_VOZ)==4) {
							echo "0";
							echo $Vehicle->ID_VOZ;
						} else {
							echo $Vehicle->ID_VOZ;
						}
					echo "</td>";
					echo "<td>";
						echo "<b>Názov vozidla: </b>";
					echo "</td>";
					echo "<td>";										
						echo form_input("editVehicleName", $Vehicle->Nazov, 'class="login_textarea"');
					echo "</td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td>";
						echo "<b>ŠPZ vozidla: </b>";
					echo "</td>";
					echo "<td>";										
						echo form_input("editVehicleSPZ", $Vehicle->SPZ, 'class="login_textarea"');
					echo "</td>";
					echo "<td>";
						echo "<b>Počet miest vozidla: </b>";
					echo "</td>";
					echo "<td>";										
						echo form_input("editVehicleNumberSeats", $Vehicle->Pocet_miest, 'class="login_textarea"');
					echo "</td>";
				echo "</tr>";
			
				
			if (count($Inventories)==0){
				echo "<tr>";
					echo "<td>";
						echo "<b>Aktivita vozidla: </b>";
					echo "</td>";
					echo "<td>";										
						echo '<div class="button-group" style="margin-top:10px">';
							if ($Vehicle->Status_vozidla==1){
								echo '<a href="'. base_url() . 'manager/setActivity/' . $Vehicle->ID_VOZ . '/1" class="button active"  >Aktívne</a>';	
								echo '<a href="'. base_url() . 'manager/setActivity/' . $Vehicle->ID_VOZ . '/0" class="button"  >Neaktívne</a>';	
							} else{
								echo '<a href="'. base_url() . 'manager/setActivity/' . $Vehicle->ID_VOZ . '/1" class="button"  >Aktívne</a>';	
								echo '<a href="'. base_url() . 'manager/setActivity/' . $Vehicle->ID_VOZ . '/0" class="button active"  >Neaktívne</a>';
							} 
						echo '</div>';							
					echo "</td>";					
				echo "</tr>";
			echo "</table>";
				echo "<div class='vehicle_div' style='align:center; margin-top:15px;margin-bottom:10px'></div>";	
			echo '<div class="button-group" style="margin-left:50px;margin-top:10px">';
				echo '<a class="button" href="javascript:window.history.go(-1);">Späť</a>';
				echo form_submit('input_form_submit' , 'Uložiť' ,'class="button"' );
			echo '</div>';	

			
				
			} else {
				
				echo "</table>";
				echo '<div class="button-group" style="margin-left:50px;margin-top:10px">';
				echo '<a class="button" href="javascript:window.history.go(-1); ">Späť</a>';
				echo form_submit('input_form_submit' , 'Uložiť' ,'class="button"' );
			echo form_close();
			echo '</div>';
			
				echo "<h3>Nie je možné zmeniť aktivitu vozidla, pretože vozidlo je prihlásené na inventúrach: </h3>";
				echo "<table class='m_inventory' style='margin-top:20px'>";
			echo "<thead>";
				echo "<th>";
					echo "ID inventúry";
				echo "</th>";
				echo "<th>";
					echo "Zákazník";
				echo "</th>";
				echo "<th>";
					echo "Mesto";
				echo "</th>";
				echo "<th>";
					echo "Dátum a čas začiatku";
				echo "</th>";
				echo "<th style='width:250px'>";
					echo "Nahradiť za vozidlo";
				echo "</th>";
			echo "</thead>";
			echo "<tbody>";
			
			foreach ($Inventories as $inventory) {				
				echo "<tr>";				
					echo "<td>";
						echo $inventory->ID_INV;
					echo "</td>";
					echo "<td>";
						echo $inventory->Nazov_spolocnosti;
					echo "</td>";
					echo "<td>";
						echo $inventory->Mesto;
					echo "</td>";					
					echo "<td>";
						echo date ("d.m.Y G:i",strtotime($inventory->Datum_zaciatku));
					echo "</td>";
					echo "<td>";
					
						echo form_open(base_url('manager/changeVehicles/' . $inventory->ID_INV . '/' .  $Vehicle->ID_VOZ),'onkeypress="return event.keyCode != 13;"');
						$this->load->helper('vehicles_helper');
						$allFreeVehicles = getFreeVehicles($inventory->Datum_zaciatku, $inventory->Datum_konca);
						if ((Count($allFreeVehicles)==0) OR ($allFreeVehicles==null) OR ($allFreeVehicles==' ')){
							$options = array();	
						} else {
							$options = array();
							foreach ($allFreeVehicles as $FreeVehicle){
								if ($FreeVehicle->Pocet_miest>=$Vehicle->Pocet_miest){
									$options[$FreeVehicle->ID_VOZ]=$FreeVehicle->Pocet_miest. " miestné | ID vozidla ". $FreeVehicle->ID_VOZ;	
								}							
							}	
						}
															
						if ($options==array()){
							echo "-nie je k dispozícii vozidlo-";
						} else {
							echo form_dropdown('changeInventoryVehicle', $options,'' , 'class="login_textarea" style="width:180px"');							
						}																
						
					echo "</td>";
					echo "<td>";					
						echo '<div class="button-group">';
							echo form_submit('input_form_submit' , 'Nahradiť vozidlo' ,'class="button"' );
							echo form_close();
							echo '<a href="" class="button"  >Detail inventúry</a>';						
						echo '</div>';
					echo "</td>";					
				echo "</tr>";	
									
		}	
		echo "</table>";
	}
		echo "</div>";		
		echo $this->pagination->create_links();
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


