<h1><?= ucfirst($this->site['produkty']);?></h1>
<?php
foreach($product_categories as $product_category){
	$used_languages = array();
	$menu_items_languages = array();
	$notused_languages = $languages;
	foreach($categories_languages as $product_language){
		if($product_language['idproduct_categories'] == $product_category['idproduct_categories']){
			$menu_items_languages[$product_language['idproduct_categories_languages']]=$product_language['fullname'];
			//$used_languages[$product_language['idlanguages']] = $product_language['fullname'];
			if(isset($notused_languages[$product_language['idlanguages']])){
				unset($notused_languages[$product_language['idlanguages']]);
			} 
		}
	} 
	echo '<table class="data_table"><tr class="admin_table_header"><td><h2>'.$product_category['type'].'</h2></td><td>';
		echo form_open(/*$site['lang']['skrot'].*/'admin/add_product_category_language/'.$product_category['idproduct_categories']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($this->site['dodaj_wersje_jezykowa'])).form_close();
		echo form_open(/*$site['lang']['skrot'].*/'/admin/edit_product_category_language').form_dropdown('idproduct_categories_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['edytuj_wersje_jezykowa'])).form_close();
		echo form_open('admin/delete_product_category_language/'.$product_category['idproduct_categories']).form_dropdown('idproduct_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['usun'])).form_close();
	echo '</td></tr></table>';
	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['cena']).'</td><td></td></tr>';
	$wasprinted = array();
	$i = 0;
	foreach($products as $product){	
		$allowprint = 1;
		foreach($wasprinted as $wasprint){
			if($wasprint==$product['idproducts']){
				$allowprint = 0;
				break;
		}
	}
	if($allowprint && $product['idproduct_categories']==$product_category['idproduct_categories']){
		
			$used_languages = array();
			$menu_items_languages = array();
			$notused_languages = $languages;
			$wasprinted[$i] = $product['idproducts'];
			$i++;
			echo '<tr class="data_row"><td><img src="/files/img/products/min/"'.$product['photo'].' alt="" /></td><td>';
				foreach($product_languages as $product_language){
					if($product_language['idproducts'] == $product['idproducts']){
						echo $product_language['fullname'].': <b>'.$product_language['title'].'</b><br/>';
						$menu_items_languages[$product_language['idproducts_languages']]=$product_language['fullname'];
						$used_languages[$product_language['idlanguages']] = $product_language['fullname'];
						if(isset($notused_languages[$product_language['idlanguages']])){
							unset($notused_languages[$product_language['idlanguages']]);
						}
					}
				} 
			echo '</td><td><table>';
				echo '<tr><td>Bez dodatków:</td><td>'.form_open('admin/change_product_price/'.$product['idproducts']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$product['price'])).form_submit('submit', ucfirst($this->site['ustaw'].' '.$this->site['cene'])).form_close().'</td></tr>';
				foreach($children as $child){
					if($child['idparent'] == $product['idproducts']){
						echo '<tr><td>'.$child['name'].'</td><td>'.form_open('admin/change_complet_price/'.$child['idparent'].'/'.$child['idchild']).form_input(array('name'=>'priority', 'size'=>'3', 'value'=>$child['complet_price'])).form_submit('submit', ucfirst($this->site['ustaw'].' '.$this->site['cene'])).form_close().'</td></tr>';
					}
				} 
			echo '</table></td><td>';
				echo form_open(/*$site['lang']['skrot'].*/'admin/add_product_language/'.$product['idproducts']).form_dropdown('idlanguage', $notused_languages ,'large').form_submit('submit', ucfirst($this->site['dodaj_wersje_jezykowa'])).form_close();
				echo form_open(/*$site['lang']['skrot'].*/'/admin/edit_product_language').form_dropdown('idproduct_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['edytuj_wersje_jezykowa'])).form_close();
				echo form_open('admin/delete_product_language/'.$product['idproducts']).form_dropdown('idproduct_languages', $menu_items_languages ,'large').form_submit('submit', ucfirst($this->site['usun'])).form_close();
				if(isset($galleries[$product['idgalleries']])){
					echo '<br/>Galeria podpięta do produktu: <b>'.$galleries[$product['idgalleries']].'</b>';
				}
			echo '<br/>'.form_open('admin/change_product_gallery/'.$product['idproducts']).form_dropdown('idgallery', $galleries ,'large').form_submit('submit', ucfirst($this->site['ustaw'])).form_close();;
			echo '</td><td>';
				echo form_open('admin/set_subproducts/'.$product['idproducts']);
				foreach($subproducts as $subproduct){
					echo form_checkbox($subproduct['idproducts'], 'accept', TRUE).$subproduct['name'].'<br/>';
				}
				
				echo form_submit('submit', ucfirst($this->site['ustaw'])).form_close();
			echo '</td></tr><tr class="space_row"><td></td><td></td><td></td><td></td></tr>';	
		}
	}
	echo '</table>';
}
?>