<?
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_zag =_pre($_POST['rec_zag']);
$rec_opis=_pre($_POST['rec_opis']);
$rec_tel=_pre($_POST['rec_tel']);
$rec_icq=_pre($_POST['rec_icq']);
$opl_data=$_POST['opl_data'];
$prim =_pre($_POST['prim']);

if(!$rec_zag) $err .= 'Укажите заголовок<br>';
if(!$rec_opis) $err .= 'Укажите описание<br>';
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($rec_url)
	$rec_cont='<a rel="nofollow" href="'.$rec_url.'"><b>'.$rec_zag.'</b></a><br>'.$rec_opis;
	else
	$rec_cont='<b>'.$rec_zag.'</b><br>'.$rec_opis;
	
	if($rec_tel)
	$rec_cont .= '<br><img border=0 src="'.dir_top().'icon/tel.gif"> '.$rec_tel;
	if($rec_icq)
	$rec_cont .= '<br><img border=0 src="'.dir_top().'icon/icq.gif"> '.$rec_icq;
	
	
	
if ($err=="")
	{
	mysql_query("UPDATE rec SET 
	rec_zag ='".$rec_zag."', 
	rec_opis='".$rec_opis."', 
	rec_url='".$rec_url."',  
	rec_cont='".$rec_cont."',
	rec_tel='".$rec_tel."', 
	rec_icq='".$rec_icq."',
	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());
$nr2 = mysql_num_rows($r2);
if(!$nr2) exit();
$rr2 = mysql_fetch_array($r2);
$rec_opis=$rr2['rec_opis'];
$rec_zag=$rr2['rec_zag'];
$rec_url=$rr2['rec_url'];
$rec_tel=$rr2['rec_tel'];
$rec_icq=$rr2['rec_icq'];
$opl_data=$rr2['opl_data'];
$prim=$rr2['prim'];

$titl="Текстовый рекламный блок";
require ('top.php'); 
if($err) echo "<p><font color=red>".$err."</font></p>";
echo '<p><table width=200><tr><td valign=top bgcolor="#D0E0ED">'.$rr2['rec_cont'].'</table></p>';

?>
<form name="form" method="post" action="">
<table >
<tr>
  <td width="170">Заголовок </td>
  <td><textarea name="rec_zag" cols="50" rows="2" ><? echo str_replace("<br>","\n",$rec_zag); ?></textarea></td>
</tr>
<tr>
  <td>Описание </td>
  <td><textarea name="rec_opis" cols="50" rows="4" ><? echo str_replace("<br>","\n",$rec_opis); ?></textarea></td>
</tr>
<tr>
  <td>Ссылка</td>
  <td><input type="text" name="rec_url" size="60" value="<? echo $rec_url; ?>"></td>
</tr>

<tr>
  <td>Tel</td>
  <td><input type="text" name="rec_tel" size="60" value="<? echo $rec_tel; ?>"></td>
</tr>

<tr>
  <td>ICQ</td>
  <td><input type="text" name="rec_icq" size="60" value="<? echo $rec_icq; ?>"></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="<?=$id_rec?>">
</td>
</tr>
</table>
</form>
<?
require('bottom.php');
?>