<?php
include ("txt/header.php");
?> 
<script language="JavaScript">
function sr() {
if (pt.value!="") {
location.href=pt.value;
}
}
</script>
<table width="560" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td height="22" class="menu">
<div align="center">
Категории товаров
</div>
</td>
</tr>
<tr> 
<td align="center" valign="top" class="menu"><table width="560" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center" valign="top" bgcolor="#FFFFFF"><table width="550" border="0" cellspacing="5" cellpadding="0">
<tr> 
<td>
<center>
<?php
if (isset($_GET['subcat'])) {
$subcat=$_GET['subcat'];
}
if (!isset($subcat) || $subcat==" ") {
die('Не выбрана подкатегория!');
} 
$query="select page_number from settings where (first='1')";
$res_n=mysql_query($query);
$rown=mysql_fetch_assoc($res_n);
$page_number=$rown["page_number"];
$subcat=mysql_escape_string($subcat);

$query="select name from subcategories where (first='$subcat')";
$res=mysql_query($query);
$number_of_rows=mysql_num_rows($res);
if ($number_of_rows<=0) {
die ('Такой подкатегории не существует!');
}
$row=mysql_fetch_assoc($res);
$name_of_subcat=$row["name"];
$name_of_subcat=stripslashes($name_of_subcat);
echo "<center><font size=2 face='Verdana'><b>$name_of_subcat</font></center><br>";
$nowtime=time();
$query="select * from goods where (parent='$subcat' and srok>$nowtime and quantity>0)  order by srok asc";
$res=mysql_query($query);
$total=mysql_num_rows($res);
if ($total>0) {
$mestopage=$page_number;
if (isset($_GET['niz'])) {
$niz=$_GET['niz'];
}
else {
$niz="";
}
if (isset($_GET['verh'])) {
$verh=$_GET['verh'];
}
else {
$verh="";
}
if ($niz=="" || $verh=="" || $niz<0 || $verh<0 || eregi ("[^0123456789]",$niz) || eregi ("[^0123456789]",$verh)) {
$niz=0;
$verh=$mestopage-1;
}
$pages=ceil ($total/$mestopage);
$pages=$pages-1;
echo "<table class='t'>";
echo "<tr bgcolor=white><td><center><font size=2>Название</td>";
echo "<td><center><font size=2>Продавец</td>";
echo "<td><center><font size=2>Осталось времени</td>";
echo "<td><center><font size=2>Ставка</td></tr>";
@mysql_data_seek($res,$niz);
$i=$niz;
while ($i<=$verh) {
$myrow=mysql_fetch_assoc($res);
$name_of_good=$myrow["name"];
$name_of_good=stripslashes($name_of_good);
$end=$myrow["srok"];
$stay=$end-$nowtime;
$days=$stay/86400;
$days_show=floor($days);
$hours=$stay/3600-$days_show*24;
$hours_show=floor($hours);
$minutes=$stay/60-$days_show*1440-$hours_show*60;
$minutes_show=floor($minutes);
$bid_of_good=$myrow["bid"];
if ($bid_of_good==0) {
$bid_of_good="нет";
}
$seller_crc=$myrow["seller"];
$query="select name from users where (crcname='$seller_crc')";
$ress=mysql_query($query);
$myrows=mysql_fetch_assoc($ress);
$seller=$myrows["name"];
$id=$myrow["first"];
if ($name_of_good!="") {
$name_of_good=substr($name_of_good,0,20);
$name_of_good=$name_of_good."...";
echo "<tr bgcolor=white><td><center><a href=\"commodity.php?com=$id\"><u>$name_of_good</u></a></td>";
echo "<td><center><a href=\"profile.php?user=$seller_crc\"><u>$seller</u></a></td>";
echo "<td><center>";
if ($days_show>0) {
echo "$days_show дней ";
}
if ($hours_show>0) {
echo "$hours_show час. "; 
}
echo "$minutes_show мин.";
echo "</td>";
echo "<td><center>$bid_of_good</td>";
echo "</tr>";
}
$i++;
}
echo "</table>";
}
else {
echo "В данной категории нет товаров";
}
?>
<br>
<?php
if ($total>0) {
echo "<table>";
echo "<tr><td>Всего товаров: $total</td>";
echo "<td><select name='pt' onChange=\"sr()\" align=right style='font-size:12'>";
echo "<option>Страницы";
for ($j=0;$j<=$pages;$j++) {
$niz2=$j*$mestopage;
$verh2=$niz2+$mestopage-1;
$pok=$j+1;
echo "<option value=goods.php?niz=$niz2&verh=$verh2&subcat=$subcat>$pok";
}
echo "</select></td></tr></table>";
}
?>
</td>
</tr>
</table></td>
</tr>
</table></td></tr></table>
<br>
</td>
</tr>
</table></td>
</tr>
<?php
include ("txt/footer.php");
?> 

