<?
if (!defined('SITE')) die();

if (isset($_GET['op']) && $_GET['op'] == "yes")
{
	$query = mysql_query("UPDATE jshop_tovar SET end = 'yes' WHERE id = '".intval($_GET['tovar_id'])."' LIMIT 1");
	if($query)
	{
		echo "<br /><br /><br /><br /><center><strong class=\"up dark_blue\">Заказ помечен как выполненный</strong></center>";
		echo "<HTML><HEAD><META HTTP-EQUIV='Refresh' CONTENT='0; URL=".$h."/admin/zakaz/'></HEAD></HTML>";
	}
	else echo "<br /><br /><br /><br /><center><strong class=\"up dark_red\">Не удалось провести заказ!</strong></center>";
}
elseif (isset($_GET['op']) && $_GET['op'] == "drop")
{
	$query = mysql_query("DELETE FROM jshop_tovar WHERE id = '".intval($_GET['tovar_id'])."' LIMIT 1");
	if($query)
	{
		echo "<br /><br /><br /><br /><center><strong class=\"up dark_blue\">Заказ удален</strong></center>";
		echo "<HTML><HEAD><META HTTP-EQUIV='Refresh' CONTENT='0; URL=".$h."/admin/zakaz/'></HEAD></HTML>";
	}
	else echo "<br /><br /><br /><br /><center><strong class=\"up dark_red\">Не удалось удалить заказ!</strong></center>";
}
else
{
	$query = mysql_query("SELECT A.id as tovar_id, A.*, B.* FROM jshop_tovar as A, jshop_clients as B WHERE A.end = 'no' AND A.id_clients = B.id");
	if (mysql_num_rows($query))
	{
		echo "<table width=100% cellpadding=1 cellspacing=1 border=0>";
		echo "<tr bgcolor=#F8F8F8><td colspan=10 align=center><div class=table_item><b class=\"up dark_red\">Непроведённые заказы</b></div></td></tr></table><br />";
		echo "<table width=100% cellpadding=10 cellspacing=0 border=1 align=center bordercolor=#EFEFEF>
		<tr bgcolor=#FFFFFF valign=top>
		<td width=3% align=center><strong>№№</strong></td>
		<td width=8% align=center><strong>Дата и время заказа</strong></td>
		<td width=12% align=center><strong>Имя покупателя</strong></td>
		<td width=14% align=center><strong>Телефон покупателя</strong></td>
		<td width=20% align=center><strong>Дополнительная информация о покупателе</strong></td>
		<td width=25% align=center><strong>Содержание заказа</strong></td>
		<td width=12% align=center><strong>Действие</strong></td>
		</tr>";
	
		while($arr = mysql_fetch_array($query))
		{
			echo "<tr bgcolor=FFFFFF valign=top>";
	
			echo "<td align=center>№ ".$arr['tovar_id']."</td>";
			echo "<td align=center>".$arr['date']." ".$arr['time']."</td>";
			echo "<td align=center>".$arr['name']."</td>";
			echo "<td align=center>".$arr['phone']."</td>";
			echo "<td>";
			if (isset($arr['email']) && $arr['email'] != "")
			{ echo "E-mail: ".$arr['email']; }
			else { echo "E-mail не указан<br />"; }
			if (isset($arr['text']) && $arr['text'] != "")
			{ echo "<br />Коментарии к заказу: ".$arr['text']; }
			else { echo "Коментарии не указаны"; }
			echo "</td>";
			echo "<td>";
			$query_tovar = mysql_query("SELECT A.*, B.* FROM jshop_cat as A, jshop_categories as B WHERE A.id = '".$arr['id_tovara']."' AND A.category = B.id");
			$tovar = mysql_fetch_array($query_tovar);
			echo "Название товара: ".$tovar['name']."<br />";
			echo "Категория: ".$tovar['category_name']."<br />";
			echo "Стоимость: ".$tovar['price']."руб.<br />";
			echo "</td>";

			echo "<td align=center><a href=\"".$h."/admin/zakaz/".$arr['tovar_id']."/yes/\">Провести</a><br />
<a href=\"".$h."/admin/zakaz/".$arr['tovar_id']."/drop/\" onClick='return ConformDelete(this);'>Удалить из БД</a>
</td>";
			$client = $arr['name'];
			echo "</tr>";
		}
	echo "</table>";
	}
	else echo "<br /><br /><br /><br /><br /><br /><br /><div class=table_item align=center><b class=\"up dark_red\">Новых заказов нет :(</b></div>";
}
?>