<h1>Menu:</h1>
<table class="table_90procent"><tr><td>
<?php
	function menu_rek($menu_items, $site, $padding, $languages, $id=null){
		$padding+=20;
		$wasprinted = array();
		$i = 0;	
		foreach($menu_items as $menu_item){
			$allowprint = 1;
			foreach($wasprinted as $wasprint){
				if($wasprint==$menu_item['idmenu_items']){
					$allowprint = 0;
					break;
				}
			}
			if($menu_item['idparent']==$id && $allowprint){
				$used_languages = array();
				$menu_items_languages = array();
				$notused_languages = $languages;
				$wasprinted[$i] = $menu_item['idmenu_items'];
				$i++;
				echo '<tr class="data_row"><td style="padding-left:'.$padding.'px;"><b>|<br/>|<br/>|<br/>|<br/>|</b></td><td>';
					foreach($menu_items as $submenu_item){
						if($submenu_item['idmenu_items']==$menu_item['idmenu_items']){
							echo $submenu_item['fullname'].': <b>'.$submenu_item['elementname'].'</b><br/>';
							$menu_items_languages[$submenu_item['idmenu_item_languages']]=$submenu_item['fullname'];
							$used_languages[$submenu_item['idlanguages']] = $submenu_item['fullname'];
							if(isset($notused_languages[$submenu_item['idlanguages']])){
								unset($notused_languages[$submenu_item['idlanguages']]);
							}
						}
					} 
				echo '</td><td>';	
					echo $menu_item['type'];
				echo '</td><td>';
				echo form_open('admin/change_menu_item_priority/'.$menu_item['idmenu_items']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$menu_item['showorder'])).form_submit('submit', ucfirst($site['ustaw'])).form_close();	
				echo '</td><td>';
				
				echo form_open('admin/add_menu_item_language/'.$menu_item['idmenu_items']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($site['dodaj_wersje_jezykowa'])).form_close();
				echo form_open('admin/edit_menu_item_language').form_dropdown('idmenu_item_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($site['edytuj_wersje_jezykowa'])).form_close();
				echo '</td><td>';
					echo form_open('admin/add_menu_item/'.$menu_item['idmenus'].'/'.$menu_item['idmenu_items']).form_submit('submit', ucfirst($site['dodaj_podmenu'])).form_close();	
				echo '</td><td>';	
						echo '<input type="button" value="'.ucfirst($site['usun']).'" onClick="if(window.confirm(\''.ucfirst($site['czy_napewno_usunac']).'\')){window.location=\'/admin/delete_menu_item/'.$menu_item['idmenu_items'].'\';}">';
				echo '</td></tr><tr class="space_row"><td></td><td></td><td></td><td></td><td></td><td></td></tr>';	
				menu_rek($menu_items, $site, $padding, $languages, $menu_item['idmenu_items']);	
			}
		}	
	}
	foreach($menus as $img){		
		
		echo '<table class="table_100procent"><tr>';
			echo '<td>Menu: <b>['.$img['idmenus'].']'.$img['name'].'</b></td><td>'.form_open('admin/add_menu_item/'.$img['idmenus']).form_submit('submit', ucfirst($this->site['dodaj_pozycje'])).form_close().'</td><td><input type="button" value="'.ucfirst($this->site['usun']).'" onClick="if(window.confirm(\''.ucfirst($this->site['czy_napewno_usunac']).'\')){window.location=\'/admin/delete_menu/'.$img['idmenus'].'\';}"></td></tr></table>';
			$have_versions = 0;
			foreach($menu_items as $subimg){	
				if($subimg['idmenus']==$img['idmenus']){
					$have_versions = 1;
				}
			}
			if($have_versions){
				echo '<table class="news_data_table"><tr class="admin_table_header">';
				echo '<td></td><td>';
				echo ucfirst($this->site['wyswietlana_nazwa']).'</td><td>';
				echo ucfirst($this->site['kategoria']).'</td><td>';
				echo ucfirst($this->site['kolejnosc']).'</td><td></td></tr>';
				$wasprinted = array();
				$i = 0;
				foreach($menu_items as $subimg){	
					$allowprint = 1;
					foreach($wasprinted as $wasprint){
						if($wasprint==$subimg['idmenu_items']){
							$allowprint = 0;
							break;
						}
					}
					if($allowprint && $subimg['idparent']==null && $subimg['idmenus']==$img['idmenus']){
						$used_languages = array();
						$menu_items_languages = array();
						$notused_languages = $languages;
						$wasprinted[$i] = $subimg['idmenu_items'];
						$i++;
						echo '<tr class="data_row"><td><b>|<br/>|<br/>|<br/>|<br/>|<br/>|</b></td><td>';
							foreach($menu_items as $subsubimg){
								if($subsubimg['idmenu_items']==$subimg['idmenu_items']){
									echo $subsubimg['fullname'].': <b>'.$subsubimg['elementname'].'</b><br/>';
									$menu_items_languages[$subsubimg['idmenu_item_languages']]=$subsubimg['fullname'];
									$used_languages[$subsubimg['idlanguages']] = $subsubimg['fullname'];
									if(isset($notused_languages[$subsubimg['idlanguages']])){
										unset($notused_languages[$subsubimg['idlanguages']]);
									}
								}
							} 
						echo '</td><td>';	
							echo $subimg['type'];
						echo '</td><td>';
						echo form_open('admin/change_menu_item_priority/'.$subimg['idmenu_items']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$subimg['showorder'])).form_submit('submit', ucfirst($this->site['ustaw'])).form_close();	
						echo '</td><td>';
							echo form_open('admin/add_menu_item_language/'.$subimg['idmenu_items']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($this->site['dodaj_wersje_jezykowa'])).form_close();
							echo form_open('admin/edit_menu_item_language').form_dropdown('idmenu_item_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['edytuj_wersje_jezykowa'])).form_close();	
							echo form_open('admin/delete_menu_item_language').form_dropdown('idmenu_item_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($site['usun'])).form_close();
						echo '</td><td>';
							echo form_open('admin/add_menu_item/'.$subimg['idmenus'].'/'.$subimg['idmenu_items']).form_submit('submit', ucfirst($site['dodaj_podmenu'])).form_close();	
						echo '</td></tr><tr class="space_row"><td></td><td></td><td></td><td></td><td></td><td></td></tr>';	
						menu_rek($menu_items, $site, 0, $languages, $subimg['idmenu_items']);				
					}
				}
				echo '<tr><td><br/><br/></td></tr></table>';
			}
	}
?>
</td></tr></table>