<?php
include("../FCKeditor/fckeditor.php") ;
include ("ad_header.php");
?>
<HTML><HEAD><TITLE>Просмотр товара</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
</HEAD>
<BODY text=#000000 vLink=#00468c aLink=#ff6633 link=#0053a2 bgColor=#ffffff>
<center>
<?php
if (isset($_POST['com'])) {
$com=$_POST['com'];
}
if (isset($_GET['com'])) {
$com=$_GET['com'];
}
if (!isset($com) || $com==" ") {
die('Не выбран товар!');
} 
$com=mysql_escape_string($com);
$query="select * from goods where (first='$com')";
$res=mysql_query($query);
$total=mysql_num_rows($res);
if ($total<=0) {
die('Такой товар не существует!');
}
$row=mysql_fetch_assoc($res);
$name=$row["name"];
$name=stripslashes($name);
$cat=$row["parent"];
$query="select first from subcategories where (first='$cat')";
$cats=mysql_query($query);
$rowcats=mysql_fetch_assoc($cats);
$id_of_category=$rowcats["first"];
$type=$row["type"];
$typeshow=str_replace ("one","Уникальный",$type);
$typeshow=str_replace ("mult","Несколько одинаковых",$typeshow);
$typeshow=str_replace ("unlim","Неограниченное количество",$typeshow);
$price=$row["price"];
$mprice=$row["mprice"];
$quantity=$row["quantity"];
$descr=$row["descr"];
$descr=stripslashes($descr);
$photo=$row["photo"];
$bid_of_good=$row["bid"];
if ($bid_of_good==0) {
$bid_of_good="нет";
}
$buyer=$row["buyer"];
if ($buyer=="no") {
$buyer_show="нет предложений";
$buyer="нет покупателей";
}
else {
$query="select name,email from users where (crcname='$buyer')";
$user_res=mysql_query($query);
$row_user=mysql_fetch_assoc($user_res);
$buyer_show=$row_user["name"];
$email_of_buyer=$row_user["email"];
$email_of_buyer=stripslashes($email_of_buyer);
$buyer_show="<a href=\"../profile.php?user=$buyer\" target='_blank'><u>$buyer_show</u></a>";
}
$end=$row["srok"];
$nowtime=time();
$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);
$id=$row["first"];
?>
<center>
<br>
<table bgcolor="#D3D3D3" width="560" border=0>
<form action="action_lot.php" name=form method="post">
<tr bgcolor=white>
<td><b>Название:</b></td><td><input type=text name='nazv' value="<?php echo $name; ?>" size=40></td>
</tr>
<tr bgcolor=white>
<td><b>Категория:</b></td><td>
<select name=cat>
<?php
$query="select * from subcategories";
$res=mysql_query($query);
while ($myrow=mysql_fetch_assoc($res)) {
$name_of_category=$myrow["name"];
$name_of_category=stripslashes($name_of_category);
$id=$myrow["first"];
if ($id==$id_of_category) {
echo "<option value=$id SELECTED>$name_of_category";
}
else {
echo "<option value=$id>$name_of_category";
}
}
?>
</select>
</td>
</tr>
<tr bgcolor=white>
<td><b>Тип аукциона:</b></td><td><?php echo "$typeshow"; ?></td>
</tr>
<tr bgcolor=white>
<td><b>Начальная цена:</b></td><td><input type=text name='price' value="<?php echo $price; ?>" size=5 maxlength=10></td>
</tr>
<?php
if ($type=="one") {
echo "<tr bgcolor=white><td><b>Цена моментальной продажи:</b></td><td><input type=text name='mprice' value='$mprice' size=5 maxlength=10></td></tr>";
}
if ($type=="one") {
echo "<tr bgcolor=white>";
echo "<td><b>Текущая ставка: </b></td><td>$bid_of_good</td>";
echo "</tr>";
}
echo "<tr bgcolor=white>";
echo "<td><b>";
if ($type=="one") {
echo "Наивысшую цену предложил: ";
}
else {
echo "Покупатели: ";
}
echo "</b></td><td>";
if ($type=="one") {
echo "$buyer_show";
}
else {
$buyer=str_replace ("profile.php","../profile.php",$buyer);
echo "$buyer";
}
echo "</td>";
echo "</tr>";
if ($type=="mult") {
echo "<tr bgcolor=white><td><b>Количество:</b></td><td><input type=text name='quantity' value='$quantity' size=5></td></tr>";
}
?>
<tr bgcolor=white>
<td><b>Осталось времени:</b></td><td>
<?php
if ($stay>0) {
if ($days_show>0) {
echo "$days_show дней ";
}
if ($hours_show>0) {
echo "$hours_show час. "; 
}
echo "$minutes_show мин.";
}
else {
echo "<font color=red>Завершился</font>";
}
?>
</td>
</tr>
<tr bgcolor=white>
<td><b>Описание:</b></td><td>
<?php
$os=getenv("HTTP_USER_AGENT");
if (!eregi("Opera",$os)) {
$oFCKeditor=new FCKeditor('descr') ;
$oFCKeditor->BasePath='../FCKeditor/';
$oFCKeditor->ToolbarSet='sell' ;
$oFCKeditor->Value="$descr";
$oFCKeditor->Width ='100%' ;
$oFCKeditor->Height='350' ;
$oFCKeditor->Create() ;
}
else {
echo "<textarea rows=6 cols=30 name=descr></textarea>";
}
?>
</td>
</tr>
<tr bgcolor=white><td colspan=2><center>
<input type=hidden name=com value='<?php echo "$com"; ?>'>
<input type=hidden name=type value='<?php echo "$type"; ?>'>
<input type=submit name=action value="change"><input type=submit name=action value="delete">
</td></tr>
</form>
</table>
<center>
<?php
if (file_exists("../photos/$photo") && $photo!="") {
echo "<img src='../photos/$photo'>";
}
?>

</BODY></HTML>
<?php
mysql_close ($link);
?>