<?php
$_SESSION['title']="Эталоны товаров";
heads($headers_page, $set_ob_start);   //подключение шапки    tovar
// Сортировка
$sort='';
if(isset($_GET['sort']))$sort=ft_nic($_GET['sort']);
if (isset($_POST['sort'])){$sort=ft_nic($_POST['sort']);}
echo "<form class='c03' action='' method='post'>";
if($types=get_type_tov())
{        //this.options[this.selectedIndex].value;
echo "<br />Сортировка  <select name='sort'  onchange='location href=''>";
echo "<option value=''".($sort==''?" selected='selected'":null).">все</option>\n";
foreach($types as $k=>$v)
{
echo "<option value='$k'".($k==$sort?" selected='selected'":null).">$v</option>\n";
}  
echo "</select><input type='submit' name='' value='прим' />";
}
echo "</form>";
//
$dw='';
if($sort!='')$dw=" WHERE `type`='$sort'";
#echo $dw."<br />";
//
$all=mysql_result(mysql_query("SELECT count(*) FROM `tovar` $dw"),0);
$pnumber=10; //$user['set_p_str']; //Элементов на страницу 1;//
    if(!isset($_GET['page'])){$_GET['page']=1;}
		//$n=new Navigator($all,$pnumber);
    $n=k_page($all,$pnumber);
    if($_GET['page']=='end'){$page=$n;}
    else{$page=intval($_GET['page']);}
    if($page<1){$page=1;}
    $start=$page*$pnumber-$pnumber;
    if($start<1){$start=0;}
//
$tovars=mysql_query("SELECT * FROM `tovar`$dw ORDER BY `type` DESC, `price` DESC LIMIT $start,$pnumber");

if(mysql_num_rows($tovars))
{
echo "<div class='c03'>";
  while($data=mysql_fetch_assoc($tovars))
  {
  
  echo "<div class='menu'>[$data[type_name]] $data[name] $data[massa] кг. $data[price] руб. <br />
  <a href='?l=tedit&t=$data[id]'> [edit]</a>
  <a href='?l='> [info]</a>
  <a href='?l='> [del]</a> 
  </div>";
    
  }
echo "</div>";
if($n>1){echo str2($link="?l=tovars&sort=$sort&",$n,$page);}
}else{echo "<div class='c07'>Нет товаров!</div>";}
echo "<div class='menu'><a href='?l=newtovar'>+ Добавить товар</a></div>";
?>