<?
session_start();
require_once('../connect/connect.php'); 
include_once('../lib/lib.php');
require('pdk.php');

//include_once('svod_rec.php');

$base_path="../";

$titl="Рекламные блоки";
require ('top.php'); 

echo '<p>
<font size=+1><a href="add_banner.php">Добавить графический баннер (gif)</a></font><br>
<font size=+1><a href="add_flash.php">Добавить flash-баннер (swf)</a></font>
</p>';


if($_POST['d_r'] && $_POST['yes'])	
	{
	$r = mysql_query ("SELECT * FROM rec WHERE id_rec = '".$_POST['d_r']."' ") or die(mysql_error());
	$rr = mysql_fetch_array($r);
	if($rr['rec_img'] && file_exists($base_path.$rr['rec_img']) && is_file($base_path.$rr['rec_img']))
	unlink($base_path.$rr['rec_img']);
	mysql_query ("DELETE FROM rec WHERE id_rec='".$_POST['d_r']."' ") or die(mysql_error());
	include('_svod_rec.php');
	}

if($_GET['del_rec'])	
	{
	$del_rec=intval($_GET['del_rec']);
	$rd = mysql_query ("SELECT * FROM rec WHERE id_rec='".$del_rec."' ") or die(mysql_error());
	$nrd=mysql_num_rows($rd);
	$rrd=mysql_fetch_array($rd);
	if($nrd)
		{
		echo '<table width=300 bordercolor=red border=3 cellSpacing=0 cellPadding=5><tr><td>';
		echo '<p>Вы действительно хотите удалить рекламный блок под номером: <b>'.$del_rec.'</b> ?';
		if($rrd['opl'])
		echo '<br><font color=red>Предупреждение: этот рекламный блок оплачен до '.$rrd['opl_data'].'</font>';
		?>
		<form action="all_rec_user.php" method="post" name="form" >
  		<input name="d_r" type="hidden" value="<? echo $del_rec; ?>">
		<input class="submit" type="submit" name="yes" value="Да">
		<input class="submit" type="submit" name="no" value="Нет">
		</form>
		<?
		echo '</td></tr></table>';
		}
	}


$query = "SELECT * FROM rec ";

$maxRows_Recordset1=5;
$pn = 0;
if (isset($_GET['pn'])) 
 {
  $pn = $_GET['pn'];
 }
$startRow_Recordset1 = $pn * $maxRows_Recordset1;

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query, $startRow_Recordset1, $maxRows_Recordset1);

$r2 = mysql_query($query_limit_Recordset1, $connect) or die(mysql_error());
$rr2 = mysql_fetch_array($r2);

$all_Recordset1 = mysql_query($query);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

do
	{
	if($rr2['id_rec'])
		{
		echo '<table>';
		echo '<tr><td valign=top width=200>';

		echo '<a href="all_rec_user.php?del_rec='.$rr2['id_rec'].'">Удаление блока</a>';
		if($rr2['str'])
			{
			echo '<br><a href="rec_user.php?id_rec='.$rr2['id_rec'].'">Размещение блока</a>';
			if(strtotime($rr2['opl_data']) > time())
			echo '<br>Размещено до <font color=#8A0000>'.date($date_format_site, strtotime($rr2['opl_data'])).'</font> ';
			else
				{
				if($rr2['rec_typ']==1)
				echo '<br><a href="edit_rec.php?id_rec='.$rr2['id_rec'].'"><font color=red>Просрочено</font></a>';
				elseif($rr2['rec_typ']==2)
				echo '<br><a href="edit_banner.php?id_rec='.$rr2['id_rec'].'"><font color=red>Просрочено</font></a>';
				elseif($rr2['rec_typ']==3)
				echo '<br><a href="edit_flash.php?id_rec='.$rr2['id_rec'].'"><font color=red>Просрочено</font></a>';
				}
			}
		else
		echo '<br><a href="rec_user.php?id_rec='.$rr2['id_rec'].'"><font color=red>Укажите размещение блока</font></a>';

		if($rr2['rec_typ']==1)
		echo '<br><a href="edit_rec.php?id_rec='.$rr2['id_rec'].'">Редактирование блока</a>';
		elseif($rr2['rec_typ']==2)
		echo '<br><a href="edit_banner.php?id_rec='.$rr2['id_rec'].'">Редактирование блока</a>';
		elseif($rr2['rec_typ']==3)
		echo '<br><a href="edit_flash.php?id_rec='.$rr2['id_rec'].'">Редактирование блока</a>';
	
		echo '<font color=green>';
		if($rr2['prim'])
		echo '<br><br>'.$rr2['prim'];
		echo '</font>';

		echo '<td valign=top width=200>';

		if($rr2['rec_typ']==1)
		echo '<table width=200><tr><td valign=top bgcolor="#D0E0ED">'.$rr2['rec_cont'].'</table>';

		elseif($rr2['rec_typ']==2)
		echo '<table width=200><tr><td valign=top >'.$rr2['rec_cont'].'</table>';

		elseif($rr2['rec_typ']==3)
			{
			$wh=explode("_",$rr2['banner']);
			echo '<table width=200><td valign=top ><tr><td>
			<div>
			<script type="text/javascript">swfobject.embedSWF("'.$rr2['rec_cont'].'", "Banner'.$rr2['id_rec'].'", "'.$wh[0].'", "'.$wh[1].'", "9.0.0", "", false, "");</script>
			<div id="Banner'.$rr2['id_rec'].'"></div>
			</div>
			</table>';
			}

		echo '</table>';
		echo '<hr>';
		}
	} while($rr2 = mysql_fetch_array($r2));

pages3(10, $totalPages_Recordset1, $_GET['pn']);

require('bottom.php');
?>