{{include file='head.tpl' inline}}

{{function name="countPages" iPages=1 iPageNumber=1 sUrl="" sUrl2=""}}
	{{$sUrl2 = preg_replace( '/^\\?/', '&amp;', $sUrl2 )}}
	{{if $iPageNumber > 1}}
		<a href="{{$sUrl}}{{if $iPageNumber > 2}}&amp;iPage={{$iPageNumber - 1}}{{/if}}{{$sUrl2}}">&laquo;&nbsp;{{$lang.pages_prev}}</a>
	{{/if}}
	{{$iPaginationSpacer = false}}
	{{section name=pages start=1 loop=$iPages+1 step=1}}
		{{if $smarty.section.pages.index != $iPageNumber && (abs($smarty.section.pages.index - $iPageNumber) <= $config.pagination_counter_admin || $smarty.section.pages.index <= $config.pagination_counter_admin || $smarty.section.pages.index >=  + $iPages - $config.pagination_counter_admin + 1)}}
			<a href="{{$sUrl}}{{if $smarty.section.pages.index > 1}}&amp;iPage={{$smarty.section.pages.index}}{{/if}}{{$sUrl2}}">{{$smarty.section.pages.index}}</a>
		{{$iPaginationSpacer = false}}
		{{elseif $smarty.section.pages.index == $iPageNumber}}
			<strong>{{$smarty.section.pages.index}}</strong>
		{{else}}
			{{if $iPaginationSpacer === false}}
			<strong>...</strong>
			{{$iPaginationSpacer = true}}
			{{/if}}
		{{/if}}
	{{/section}}
	{{if $iPageNumber < $iPages}}
		<a href="{{$sUrl}}&amp;iPage={{$iPageNumber + 1}}{{$sUrl2}}">{{$lang.pages_next}}&nbsp;&raquo;</a>
	{{/if}}
{{/function}}

{{function name="selectOptions" aOptions=0 mOption=0}}
	{{foreach from=$aOptions item=sOption}}
		<option value="{{$sOption@key}}" {{if ( is_array( $mOption ) && in_array( $sOption@key, $mOption ) ) || ( $sOption@key == $mOption )}}selected="selected"{{/if}}>{{$sOption}}</option>
	{{/foreach}}
{{/function}}

{{* funkcja przed usuniêciem spacji *
{{function page_tree aPageTree=$aProduct.aPagesTree bMenu=true}}
	{{if $bMenu && isset($aPageTree.sMenu)}}
		{{$aPageTree.sMenu}}&nbsp;&raquo;&nbsp;
	{{/if}}
	{{foreach from=$aPageTree.aPath item=aPage}}
		{{$aPage.sName}}
		{{if !$aPage@last}}
			&nbsp;&raquo;&nbsp;
		{{/if}}
	{{/foreach}}
{{/function}}
*                                    *}}
{{function page_tree aPageTree=$aProduct.aPagesTree bMenu=true}}{{if $bMenu && isset($aPageTree.sMenu)}}{{$aPageTree.sMenu}}&nbsp;&raquo;&nbsp;{{/if}}{{foreach from=$aPageTree.aPath item=aPage}}{{$aPage.sName}}{{if !$aPage@last}}&nbsp;&raquo;&nbsp;{{/if}}{{/foreach}}{{/function}}

<script type="text/javascript">
	var request_type = '{{$_GET.request_type}}';
</script>
</head>
<body>
	<h1>{{$lang.Products}}</h1>
	<div class="filter">
		<form action="" method="get" id="products-search-form" >
			<fieldset>
				<input type="hidden" name="request_type" value="{{$_GET.request_type}}" />
				<input type="hidden" name="p" value="{{$_GET.p}}" />
				<label for="product-search">{{$lang.search}}</label>
				<input id="product-search" type="text" name="sPhrase" value="{{$_GET.sPhrase}}" class="input" size="25" />
				<select name="iCategory">
					<option value="">{{$lang.Select}} - {{$lang.Category}}</option>
					{{foreach from=$aSearch.aSearchCategories item=aCategory}}
						<option value="{{$aCategory.iPage}}" {{if $aCategory.bSelected}}selected="selected"{{/if}}>{{$aCategory.sName}}</option>
						{{foreach from=$aCategory.aSubcategories item=aSubCategory}}
							<option value="{{$aSubCategory.iPage}}" {{if $aSubCategory.bSelected}}selected="selected"{{/if}}>&raquo;&nbsp;{{$aSubCategory.sName}}</option>
						{{/foreach}}
					{{/foreach}}
				</select>
				<select name="iProducer">
					<option value="">{{$lang.Select}} - {{$lang.Producer}}</option>
					{{selectOptions aOptions=$aSearch.aProducers mOption=$_GET.iProducer}}
				</select>
				<label for="iProduct">{{$lang.Id}}</label>
				<input id="iProduct" type="text" name="iProduct" value="{{$_GET.iProduct}}" class="input" size="50" />
				<input type="submit" class="submit" value="{{$lang.search}}" />
			</fieldset>
		</form>
		<div class="clear"></div>
	</div>
	{{if count( $aProducts.aList ) > 0}}
		<form action="?p={{$_GET.p}}" method="post" id="products-multiselect">
			<fieldset>
				<table class="list" id="products">
					<thead>
						<tr>
							<td colspan="5" class="pages">{{if $aProducts.aPagesCountData.iCount > 1}}{{$lang.Pages}}: {{countPages iPages=$aProducts.aPagesCountData.iCount iPageNumber=$aProducts.aPagesCountData.iPageNumber sUrl="admin.php?request_type=`$_GET.request_type`&amp;p=products-multiselect" sUrl2=$sUrlExt}}{{/if}}</td>
						</tr>
						<tr>
							<th class="enabled">{{$lang.Select}}</th>
							<th class="id">{{$lang.Id}}</th>
							<th class="photo">{{$lang.Photo}}</th>
							<th class="name">{{$lang.Name}}</th>
							<th class="pages">{{$lang.Pages}}</th>
						</tr>
					</thead>
					<tfoot>
						<tr class="actions">
							<td colspan="5" class="pages">{{if $aProducts.aPagesCountData.iCount > 1}}{{$lang.Pages}}: {{countPages iPages=$aProducts.aPagesCountData.iCount iPageNumber=$aProducts.aPagesCountData.iPageNumber sUrl="admin.php?request_type=`$_GET.request_type`&amp;p=products-multiselect" sUrl2=$sUrlExt}}{{/if}}</td>
						</tr>
					</tfoot>
					<tbody>
						{{foreach from=$aProducts.aList item=aProduct}}
							<tr>
								<td class="enabled"><input type="checkbox" name="aSelected[{{$aProduct.iProduct}}]" id="selected-{{$aProduct.iProduct}}" /></td> 
								<td class="id"><label for="selected-{{$aProduct.iProduct}}">{{$aProduct.iProduct}}</label></td>
								<td class="photo">{{if isset( $aProduct.aDataImage )}}<a href="{{$config.dir_files}}{{$aProduct.aDataImage.sFileName}}" class="photo"><img src="{{$config.dir_files}}30/{{$aProduct.aDataImage.sFileName}}" alt="(f)"/></a>{{/if}}</td>
								<td class="name"><label for="selected-{{$aProduct.iProduct}}">{{$aProduct.sName}}</label></td>
								<td class="pages">{{page_tree aPageTree=$aProduct.aPages}}</td>
							</tr>
						{{/foreach}}
					</tbody>
				</table>
				<div class="save float"><div class="floatcontainer">
					<td class="save"><input type="submit" class="submit" name="sOption" value="{{$lang.Save}}" /></td>
				</div></div>
			</fieldset>
		</form>
	{{else}}
		<div class="msg" id="error">
			<img src="{{$config.dir_templates}}admin/images/ico/msg_error.png" class="imgv" alt="" /> {{$lang.Data_not_found}}
		</div>
	{{/if}}
	<div id="footer"></div>
</body>
</html>