<? include('checkcookie.php'); ?>
<h3>Баннеры,ожидающие модерации</h3>
<br>
<?
if(isset($_POST["del"])){
$id=intval($_POST["id"]);
mysql_query("DELETE FROM `tb_advban` WHERE `id`='$id'");
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Баннер удален!</div>";
}
if(isset($_POST["ok"])){
$id=intval($_POST["id"]);
mysql_query("UPDATE `tb_advban` SET `modered`='1' where `id`='$id'");
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Баннер одобрен!</div>";
}
if(isset($_POST["no"])){
$id=intval($_POST["id"]);
if(isset($_POST["reas"])){
$reas=$_POST["reas"];
mysql_query("update `tb_advban` set `modered`='2', reas='$reas' where `id`='$id'");
echo "<div style='text-align:center;margin-top: -10px;padding: 10px;'>Баннер отклонен</div>";
}else{
?>
<center><form action='' method='post'>
<input type='hidden' name='no' value='no'>
<input type='hidden' name='id' value='<?=$id ?>'>
<input type='text' name='reas' value='введите причину'>
<input type='submit' value='подтвердить отклонение'>
</form>
<?
}
}
?>

<table class="adn">
<tr class="lineb">
<td width="50">№</td><td>Баннер</td><td>Разместил</td>
<td></td>
<td></td>
</tr>
<?
if(isset($_GET["deleted"]) && intval($_GET["deleted"]) == 1) {
$zapros = "`modered`='1'";
}else{
$zapros = "`modered`='0'";
}
$tabla = mysql_query("SELECT * FROM `tb_advban` where $zapros ORDER BY `id` ASC");
if(mysql_num_rows($tabla) > 0){
while ($registro = mysql_fetch_array($tabla)) {
$row = mysql_fetch_assoc(mysql_query("SELECT `username` FROM `b_users` WHERE `id`='".$registro["fromus"]."'"));
$uname = $row["username"];
echo "<tr class='liney ell'>
<td align=center>". $registro["id"] ."</td>
<td align=center><a href='".$registro["url"]."' target='_blank'>".$registro["url_img"]."</a></td>
<td align=center>".$registro["fromus"]." | $uname</a></td>";

if(isset($_GET["deleted"]) && intval($_GET["deleted"]) == 1) {
echo "<td colspan='2' align='center'>";
echo "<form action='' method='post'>";
echo "<input type='hidden' name='id' value='".$registro["id"]."'>";
echo "<input type='submit' name='del' value='Удалить'>";
echo "</form></td>";
}else{
?>
<td align=center>
<form action='' method='post'>
<input type='hidden' name='id' value='<?=$registro["id"] ?>'>
<input type='submit' name='ok' value='Одобрить'>
</form>
<form action='' method='post'>
<input type='hidden' name='id' value='<?=$registro["id"] ?>'>
<input type='submit' name='no' value='Отклонить'>
</form>
</td>
</tr>
<?
}
}
} 
?>
</table>