<? include('checkcookie.php');

if(isset($_POST["no"])){
$no=intval($_POST["no"]);
mysql_query("DELETE FROM `b_basket` WHERE `fromid`='$no'");
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Корзина пользователя $no очищена!</div>";
}
if(isset($_POST["ok"])){
$m_orderid = intval($_POST["ok"]);
include($_SERVER['DOCUMENT_ROOT']."/merchant/success-merch.php");
mysql_query("DELETE FROM b_basket WHERE fromid='$m_orderid'");
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Корзина одобрена</div>";
}
$sql=mysql_query("SELECT `fromid`,`price`,`time` FROM `b_basket` ORDER by `time` DESC") or die(mysql_error());
if(mysql_num_rows($sql)==0){
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Корзин нет</div>";
exit();
}
while($row=mysql_fetch_assoc($sql)){
$fromid = $row["fromid"];
$price[$fromid] = $price[$fromid]+$row["price"];
} 
?>
<table style="border:medium none;border-collapse:collapse;" width="400px">
<tr class="lineb">
<td align="center">ID опльзователя</th>
<td align="center">Сумма</td>
<td colspan="2"></td>
</tr>
<?
$sql2=mysql_query("SELECT `fromid`,`price`,`time` FROM `b_basket` ORDER by `time` DESC") or die(mysql_error());
while($row=mysql_fetch_assoc($sql2)){

$fromide = $row["fromid"];
if($i[$fromide] != 2){
?>
	<tr class='liney ell'>
	<td align=center><?=$fromide ?></td><td align=center><?=$price[$fromide]; ?>
	</td>
	<td align=center><form action='' method='post'>
	<input type='hidden' name='ok' value='<?=$fromide ?>'>
	<input type='submit' value='Разместить'>
	</form>
	</td>
	<td align=center><form action='' method='post'>
	<input type='hidden' name='no' value='<?=$fromide ?>'>
	<input type='submit' value='удалить'>
	</form></td>
	</tr>
	<?
	
	}
	$i[$fromide]=2;
}
echo "</table>";
exit();
?>