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

$id_rec=intval($_REQUEST['id_rec']);

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) 
	{
	$err="";
	$rec_img=$_POST['rec_img'];
	$banner=$_POST['banner'];
	$opl_data=$_POST['opl_data'];
	$prim =_pre($_POST['prim']);
	if(!$opl_data) $err .= 'Укажите, до какой даты оплачен блок<br>';


	if(trim($_POST['rec_url']))
		{
		$dom=trim($_POST['rec_url']);
		$dom=strip_tags($dom);
		$dom=str_replace("'","",$dom);
		$dom=str_replace("`","",$dom);
		$dom=str_replace("\"","",$dom);
		if (strpos ($dom, "http:") === 0)
		$pos=strpos ($dom, "http:")+7; else $pos=0;
		$dom=substr($dom, $pos, strlen($dom)-$pos); 
   		$rec_url="http://".$dom; 
		} 
	else $rec_url='';


	if (!$err && $_FILES['fil']['tmp_name'])
		{
		$ext = type_img($_FILES['fil']['type']);
  		if ($ext != ".gif" && $ext != ".jpg" && $ext != ".jpeg") 
  		$err .= "Недопустимый формат файла. Допускаются только файлы в формате GIF, JPG<br>";
		
		if(copy($_FILES['fil']['tmp_name'], $base_path.$rec_img))
			{
			$size_img = getimagesize($_FILES['fil']['tmp_name']);
			$banner=$size_img[0]."_".$size_img[1];
			$rec_img = 'banner/'.$id_rec.$ext;
			} 
		}
	
	
	if (!$err)
		{
		if($rec_url)
		$rec_cont='<a rel="nofollow" href="'.$rec_url.'"><img border=0 src="'.dir_top().$rec_img.'"></a>';
		else
		$rec_cont='<img border=0 src="'.dir_top().$rec_img.'">';
		
		mysql_query("UPDATE rec SET 
		rec_url='".$rec_url."',
		rec_img='".$rec_img."',
		banner='".$banner."',
		rec_cont='".$rec_cont."',
		opl_data='".$opl_data."',
		opl='1',
		prim='".$prim."'
		WHERE id_rec='".$id_rec."'");
	
		include('_svod_rec.php');
		echo "<HTML><HEAD><meta http-equiv='Refresh' content='0; URL=refresh.php?i=all_rec_user.php'></HEAD></HTML>";
		exit();
		} 
}

$r2 = mysql_query ("SELECT * FROM rec WHERE id_rec = '".$id_rec."'") or die(mysql_error());
$rr2 = mysql_fetch_array($r2);

$opl_data=$rr2['opl_data'];
$prim=$rr2['prim'];

$titl="Графический баннер GIF";
require ('top.php'); 
if($err) echo "<p><font color=red>".$err."</font></p>";
if($rr2['rec_cont'])
echo '<p><table width=200><tr><td valign=top >'.$rr2['rec_cont'].'</table></p>';
?>
<form enctype="multipart/form-data" name="form" method="post" action="">
<table>
<tr>
  <td width="170">Ссылка</td>
  <td><input type="text" name="rec_url" size="60" value="<? echo $rr2['rec_url']; ?>"></td>
</tr>

<tr>
  <td>FILE</td>
  <td><input  type="file" name="fil" size="50"></td>
</tr>

<tr>
	<td>Разместить до</td>
	<td><input readonly="readonly" value="<?=$opl_data?>" name="opl_data" class="date-pick dp-applied"></td>
</tr>

<tr>
	<td>Пометки администратора</td>
	<td><textarea name="prim" rows="5" cols="60"><?=stripslashes(htmlspecialchars_decode($prim))?></textarea></td>
</tr>

<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>

<tr>
<td>  <input type="submit"  class="submit" name="Submit" value="Изменить"></td>
<td>
<input type="hidden" name="MM_insert" value="form">
<input type="hidden" name="id_rec" value="<?=$_REQUEST['id_rec']?>">
<input type="hidden" name="rec_img" value="<?=$rr2['rec_img']?>">
<input type="hidden" name="banner" value="<?=$rr2['banner']?>">
</td>
</tr>
</table>
</form>
<?
require('bottom.php');
?>