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

if (@$_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/archives/'></HEAD></HTML>";
	}
	else echo "<br /><br /><br /><br /><center><strong class=\"up dark_red\">Не удалось удалить заказ!</strong></center>";
}
else
{
	function show_page_list_index ($page, $num, $count_on_page)
	{
		echo "<table align=center><tr><td>";
		if (!isset($page) && intval($page) == 0) $page = 1;
		$count_pages = intval($num / $count_on_page);
		$ostatok = $num % $count_on_page;
		if($ostatok > 0) $count_pages++;
		if ($page>1) echo " <a href = \"http://".$_SERVER['HTTP_HOST'].$GLOBALS['p']."/admin/archives/page/".($page - 1)."/\" title = \"Предыдущая страница\"><<</a> ";
		$diapazon = 5;
		$page_from = $page - $diapazon; 
		if($page_from < 1) $page_from = 1;
		$page_to = $page + $diapazon; 
		if($page_to > $count_pages) $page_to = $count_pages;
		for ($i = $page_from; $i <= $page_to; $i++)
		{
			if ($i == $page) echo " [$i] ";
			else echo "<a href =\"http://".$_SERVER['HTTP_HOST'].$GLOBALS['p']."/admin/archives/page/$i/\" title = \" $i страница \">[$i]</a>";
		}
		if ($page<$count_pages) echo " <a href = \"http://".$_SERVER['HTTP_HOST'].$GLOBALS['p']."/admin/archives/page/".($page + 1)."/\" title = \"Следующая страница\">>></a> ";
		echo "</td></tr></table>";
	}

	$num = mysql_num_rows(mysql_query("SELECT id FROM jshop_tovar WHERE end = 'yes'"));
	@$start = page_list ($_GET['page'], $num, $COUNT_SHOW_ITEMS);
	$query = mysql_query("SELECT A.id as tovar_id, A.*, B.* FROM jshop_tovar as A, jshop_clients as B WHERE A.end = 'yes' AND A.id_clients = B.id LIMIT $start,$COUNT_SHOW_ITEMS");
	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/archives/".$arr['tovar_id']."/drop/\" onClick='return ConformDelete(this);'>Удалить из БД</a>
</td>";
			$client = $arr['name'];
			echo "</tr>";
		}
	echo "</table>";
	@show_page_list_index($_GET['page'], $num, $COUNT_SHOW_ITEMS);
	}
	else echo "<br /><br /><br /><br /><br /><br /><br /><div class=table_item align=center><b class=\"up dark_red\">В архиве заказов нет :(</b></div>";
}
?>