<script>
	function destroyDialog(){
		var confBackGr = document.getElementById("confirmBackgr");	
		var dialog = document.getElementById("confirmBox");
		confBackGr.style.display = "none";
		dialog.style.display = "none";
	}
	
	function showConfirmBoxDeleteInv(id_inv){	
			
		var confBackGr = document.getElementById("confirmBackgr");						
		var dialog = document.getElementById("confirmBox");
		document.getElementById("confirmBoxHead").innerHTML = "Zrušenie inventúry";		
		document.getElementById("confirmBoxBody").innerHTML = "Určite chcete zrušiť inventúru pre zákazníka: <br><b>"+document.getElementById("zak"+id_inv).innerHTML+"-"+document.getElementById("mesto"+id_inv).innerHTML+" ("+document.getElementById("invStart"+id_inv).innerHTML+")";
		document.getElementById("confirmButtons").innerHTML = "<a onclick='destroyDialog()' class='button'>Nie</a><a href='http://martinbendik.studenthosting.sk/manager/cancelInventory/1/"+id_inv+"' class='button'>Áno</a>";
		confBackGr.style.display = "block";
		dialog.style.display = "block";	
		
		var width = window.innerWidth;
		var height = window.innerHeight; 
		dialog.style.left = ((width/2)-(500/2)+80)+"px";
		dialog.style.top = "200px";
	}
	
	document.onload = function(){
		destroyDialog();
	}
</script>
<?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="confirmBackgr">';
		echo '</div>';
			echo '<div id="confirmBox">';
				echo '<div id="confirmBoxHead"></div>';
				echo '<div id="confirmBoxBody"></div>';
				echo '<div id="confirmBoxFoot">';
					echo '<div class="button-group" id="confirmButtons">';
						echo '<a href="" class="button">Nie</a>';
						echo '<a href="" class="button">Áno</a>';
					echo '</div>';
				echo '</div>';
			echo '</div>';	
		echo '<div id="default_container">';
		echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';
			echo '<a href="'. base_url('manager/redirectChooseCustomerNewInventory') . '" class="button">Vytvoriť novú inventúru</a>';
		echo '</div>';
		echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';						
			if($mode==1){
				echo '<a href="'. base_url() . 'manager/showInventories/1" class="button active">Aktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/2" class="button">Neaktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/3" class="button">Ukončené inventúry</a>';	
			} elseif ($mode==2){
				echo '<a href="'. base_url() . 'manager/showInventories/1" class="button">Aktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/2" class="button active">Neaktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/3" class="button">Ukončené inventúry</a>';	
			} else {
				echo '<a href="'. base_url() . 'manager/showInventories/1" class="button">Aktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/2" class="button">Neaktívne inventúry</a>';
				echo '<a href="'. base_url() . 'manager/showInventories/3" class="button active">Ukončené inventúry</a>';		
			} 
											
		echo '</div>';
		if($mode==3){
			echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';
		 			echo form_open(base_url() . 'manager/searchArchiveInventories/3','onkeypress="return event.keyCode != 13;"');	  			   			
						echo form_submit('submit_search', 'Hľadať', 'class="button"');
						echo form_input('inventory_search','','class="search_area" ');			
		 			echo form_close();
	    		echo '</div>';	
		}
		
		echo "<div class='vehicle_div' style='align:center; margin-top:15px; margin-bottom:5px'>";
			echo "</div>";
		if(count($m_inventories)==0){
			switch($mode){
				case 1:
					echo "<h3 style='margin-bottom:30px;padding-bottom:30px'>Nevypísali ste žiadnu aktívnu inventúru.</h3>"; 
				break;
				case 2:
					echo "<h3 style='margin-bottom:30px;padding-bottom:30px'>Všetky inventúry sú kompletne vytvorené.</h3>"; 
				break;
				case 3:
					echo "<h3 style='margin-bottom:30px;padding-bottom:30px'>Ľutujeme zvolenému kritériu neodpovedá žiadna inventúra.</h3>"; 
				break;
			}
		} else {
		echo "<table width='100%'>";
			echo "<thead style='text-align:left'>";
				echo "<th>";
				echo "</td>";
				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 "Typ";
				echo "</th>";
				echo "<th>";
					echo "Dátum a čas začiatku";
				echo "</th>";
				echo "<th>";
					echo "Vedúci inventúry";
				echo "</th>";
			echo "</thead>";
			echo "<tbody class='zoznamTable'>";	
			echo "<tr class='nothing'>";
				echo "<td colspan='8' class='nothing'>";
				echo "<div class='vehicle_div' style='align:center; margin-top:5px; margin-bottom:5px'></div>";
				echo "</td>";
			echo "</tr>";			
		foreach ($m_inventories as $inventory) {				
				echo "<tr>";
					echo "<td width='50px'>";
					echo "</td>";				
					echo "<td width='100px'>";
						if (strlen($inventory->ID_INV)==1) {
								echo "0000";
								echo $inventory->ID_INV;
							} elseif (strlen($inventory->ID_INV)==2) {
								echo "000";
								echo $inventory->ID_INV;
							} elseif (strlen($inventory->ID_INV)==3) {
								echo "00";
								echo $inventory->ID_INV;
							} elseif (strlen($inventory->ID_INV)==4) {
								echo "0";
								echo $inventory->ID_INV;
							} else {
								echo $inventory->ID_INV;
							}
					echo "</td>";
					echo "<td width='150px' id='zak".$inventory->ID_INV."'>";
						echo $inventory->Nazov_spolocnosti;
					echo "</td>";
					echo "<td  width='160px' id='mesto".$inventory->ID_INV."'>";
						echo $inventory->Mesto;
					echo "</td>";
					echo "<td  width='100px'>";
						if($inventory->ID_TYP_R<4){
							echo "Predajňa";
						}else{
							echo "Sklad"; 	
						}
					echo "</td>";					
					echo "<td  width='180px' id='invStart".$inventory->ID_INV."'>";
						echo date ("d.m.Y G:i",strtotime($inventory->Datum_zaciatku));
					echo "</td>";
					echo "<td  width='160px'>";
						if(($inventory->Meno==NULL) OR ($inventory->Priezvisko==NULL)){
							echo "neurčené";
						} else {
							echo $inventory->Meno . ' ' .$inventory->Priezvisko;	
						}
						
					echo "</td>";
					echo "<td>";
					echo '<div class="button-group" style="margin-top:3px">';
						if ($mode == 1){ 
							echo '<a onclick="showConfirmBoxDeleteInv('.$inventory->ID_INV.')"class="button danger">Zrušiť</a>';
							//echo '<a href="'.base_url('manager/cancelInventory/'.$mode.'/'.$inventory->ID_INV).'" class="button danger">Zrušiť</a>';
							echo '<a href="" class="button">Upraviť</a>';					
							echo '<a href="'. base_url('manager/redirectInventoryDetail/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';	
						} elseif ($mode == 2){
							echo '<a href="'.base_url('manager/cancelInventory/'.$mode.'/'.$inventory->ID_INV).'" class="button danger">Zrušiť</a>';
							echo '<a href="" class="button">Upraviť</a>';
							echo '<a href="'. base_url('manager/redirectInventoryDetail/'.$mode.'/1/'.$inventory->ID_INV).'" class="button">Detail</a>';
						} else {
							echo '<a href="'. base_url('manager/redirectInventoryDetail/'.$mode.'/1/'.$inventory->ID_INV).'" class="button" style="margin-right:138px">Detail</a>';			
						}										 
					echo '</div>';
					echo "</td>";
										
				echo "</tr>";						
		}	
		echo "</table>";
		echo "<div class='vehicle_div' style='align:center; margin-top:5px; margin-bottom:10px'></div>";
		echo $this->pagination->create_links();	
		}
			} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


