<h1><?= ucfirst($this->site['artykuly']);?></h1>
<table class="table_90procent"><tr><td>
<?php
	function menu_rek($article_languages, $site, $padding, $languages, $id=null){
		$padding+=40;
		$wasprinted = array();
		$i = 0;	
		foreach($article_languages as $article_language){
			$allowprint = 1;
			foreach($wasprinted as $wasprint){
				if($wasprint==$article_language['idarticles']){
					$allowprint = 0;
					break;
				}
			}
			if($article_language['idparent']==$id && $allowprint){
				$used_languages = array();
				$menu_items_languages = array();
				$notused_languages = $languages;
				$wasprinted[$i] = $article_language['idarticles'];
				$i++;
				echo '<tr class="data_row"><td style="padding-left:'.$padding.'px;"><b>|<br/>|<br/>|<br/>|<br/>|<br/>|</b></td><td>';
					foreach($article_languages as $submenu_item){
						if($submenu_item['idarticles']==$article_language['idarticles']){
							echo $submenu_item['fullname'].': <b>'.$submenu_item['title'].'</b><br/>';
							$menu_items_languages[$submenu_item['idarticle_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 form_open('admin/change_article_priority/'.$article_language['idarticles']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$article_language['showorder'])).form_submit('submit', ucfirst($site['ustaw'].' '.$site['kolejnosc'])).form_close();
				echo '</td><td>';
					echo form_open('/admin/add_article_language/'.$article_language['idarticles']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($site['dodaj_wersje_jezykowa'])).form_close();
					echo form_open('/admin/edit_article_language').form_dropdown('idarticle_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($site['edytuj_wersje_jezykowa'])).form_close();
					echo form_open('admin/delete_article_language/'.$article_language['idarticles']).form_dropdown('idarticle_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($site['usun'])).form_close();
				echo '</td><td>';
					echo form_open('/admin/add_article/'.$article_language['idarticles']).form_submit('submit', ucfirst($site['dodaj_podartykul'])).form_close();
				echo '</td></tr><tr class="space_row"><td></td><td></td><td></td><td></td><td></td></tr>';	
				menu_rek($article_languages, $site, $padding, $languages, $article_language['idarticles']);	
			}
		}	
	}	
	
	echo '<table class="data_table"><tr class="admin_table_header">';
	echo '<td></td><td>';
	echo ucfirst($this->site['wyswietlana_nazwa']).'</td><td>';
	echo ucfirst($this->site['kolejnosc']).'</td><td></td></tr>';
	$wasprinted = array();
	$i = 0;
	foreach($article_languages as $subimg){	
		$allowprint = 1;
		foreach($wasprinted as $wasprint){
			if($wasprint==$subimg['idarticles']){
				$allowprint = 0;
				break;
			}
		}
		if($allowprint && $subimg['idparent']==null){
			$used_languages = array();
			$menu_items_languages = array();
			$notused_languages = $languages;
			$wasprinted[$i] = $subimg['idarticles'];
			$i++;
			echo '<tr class="data_row"><td><b>|<br/>|<br/>|<br/>|<br/>|<br/>|</b></td><td>';
				foreach($article_languages as $subsubimg){
					if($subsubimg['idarticles']==$subimg['idarticles']){
						echo $subsubimg['fullname'].': <b>'.$subsubimg['title'].'</b><br/>';
						$menu_items_languages[$subsubimg['idarticle_languages']]=$subsubimg['fullname'];
						$used_languages[$subsubimg['idlanguages']] = $subsubimg['fullname'];
						if(isset($notused_languages[$subsubimg['idlanguages']])){
							unset($notused_languages[$subsubimg['idlanguages']]);
						}
					}
				} 
			echo '</td><td>';
				echo form_open('admin/change_article_priority/'.$subimg['idarticles']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$subimg['showorder'])).form_submit('submit', ucfirst($this->site['ustaw'].' '.$this->site['kolejnosc'])).form_close();
			echo '</td><td>';
				echo form_open('/admin/add_article_language/'.$subimg['idarticles']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($this->site['dodaj_wersje_jezykowa'])).form_close();
				echo form_open('/admin/edit_article_language').form_dropdown('idarticle_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['edytuj_wersje_jezykowa'])).form_close();
				echo form_open('admin/delete_article_language/'.$subimg['idarticles']).form_dropdown('idarticle_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['usun'])).form_close();
			echo '</td><td>';
					echo form_open('/admin/add_article/'.$subimg['idarticles']).form_submit('submit', ucfirst($this->site['dodaj_podartykul'])).form_close();
			echo '</td></tr><tr class="space_row"><td></td><td></td><td></td><td></td><td></td></tr>';	
			menu_rek($article_languages, $site, 0, $languages, $subimg['idarticles']);				
		}
	}
	echo '<tr><td><br/><br/></td></tr></table>';
?>
</td></tr></table>