<?
session_start();

if (isset($_POST["url"])) 
{ 
	function limpiarez($mess)
	{ 
		$mess=str_replace(";"," ",$mess);
		$mess=str_replace("$"," ",$mess);
		$mess=str_replace("'"," ",$mess);
		$mess=strip_tags($mess);
		return $mess;
	}
		
	$plan=limpiarez($_POST["plan"]);
	if (is_numeric($plan)!="true" or $plan<=0)
	{
		echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Введено неверное значение в поле 'Количество посещений', оно должно быть числовым и больше 0!!!";
		include('footer.php');
		exit();
	}

	$url1=limpiarez($_POST["url"]);

	$description=limpiarez($_POST["description"]);

	$highlight=$_POST["highlight"];
	if ($highlight!=0 and $highlight!=1)
	{
		echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Ошибка ввода!!!";
		include('footer.php');
		exit();
	}
	
	$url1=htmlspecialchars($url1);
	$description=htmlspecialchars($description);

	if ($plan==""){echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Указаны не все поля";include('footer.php'); exit();}
	if ($url1==""){echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Указаны не все поля";include('footer.php'); exit();}
	if ($description==""){echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Указаны не все поля";include('footer.php'); exit();}

	$user=uc($_SESSION["username"]);
	$pass=uc($_SESSION["password"]);

	require('config.php');

	$res=mysql_query("select count(username) as kolvo from tb_users where username='$user' and password='$pass'");
	$row=mysql_fetch_array($res);
	$kolvo=$row["kolvo"];

	$res=mysql_query("select money from tb_users where username='$user' and password='$pass'");
	$res=mysql_fetch_array($res);
	$money=$res["money"];

	$sql="select price from tb_config where item='mfadyn'";
	$res=mysql_query($sql);
	$dyn=mysql_result($res,0,0);
	
	
	$sql = "SELECT * FROM tb_config WHERE item='hide_httpref'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    $hide_httprefprice = $row["price"];
	
	
	

	$sql="select price from tb_config where item='mfahldyn'";
	$res=mysql_query($sql);
	$hldyn=mysql_result($res,0,0);

	$amount=$plan*$dyn;
	if ($highlight==1) $amount=$amount+$hldyn;
	
	if($kolvo==0) { echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;Ошибка! Для заказа рекламы с внутреннего счета Вам необходимо авторизоваться!";include('footer.php'); exit(); }
	if($money<$amount) {echo "<img src=\"images/error.png\" align=\"middle\">&nbsp;На Вашем балансе недостаточно средств!";include('footer.php'); exit(); }
	
	$expa=$money-$amount;
	
	$fechainicia=time();

	$sql = "INSERT INTO tb_ads1 (fechainicia, paypalemail, plan, url, description, tipo, highlight, use_http_ref) VALUES('$fechainicia','$user','$plan','$url1','$description','ads','$highlight', '$hide_ref_use')";
	mysql_query($sql) or die(mysql_error());

	$t=date("d.m.Y", time());
	$res=mysql_query("select count(id) as kol from tb_adsdate1 where data='$t'");
	$res=mysql_Fetch_array($res);
	if($res["kol"]>0)
	{
		mysql_query("update tb_adsdate1 set kolvo=kolvo+1 where data='$t'");
	}else{
		mysql_query("insert into tb_adsdate1 (data,kolvo) values ('$t','1')");
	}

	$sql="update tb_users set money='$expa' where username='$user'";
	mysql_query($sql) or die(mysql_error());

        

	
	echo "<center><img src=\"images/ok.png\" align=\"middle\">&nbsp;<b><green>Ваша ссылка добавлена</green></b></center>";
	include('footer.php');
	exit();
}
?>
<div align="center"><div id="form">
<fieldset style="width: 100%; background: ;">
<form method="post" action="moneyforadv.php?adv=baner">
<table width="400" border="0" align="center"><br><br>
  <tr>
    <td width="150" align="left"><p><label>URL картинки:</label></p></td>
    <td width="250" align="left"><input type="text" name="description" size="25" maxlength="100" autocomplete="off" class="field" value="" tabindex="2" /></td>
  </tr>
  <tr>
    <td width="150" align="left"><p><label>URL:</label></p></td>
    <td width="250" align="left"><input type="text" name="url" size="25" maxlength="150" autocomplete="off" class="field" value="http://" tabindex="3" /></td>
  </tr>
  <tr>
    <td width="150" align="left"><p><label>Кол-во визитов:</label></p></td>
<td width="250" align="left"><input name="plan" type="text" size="6" maxlength="6" />
</td>
</tr>




<tr>

</select></td></tr>
  <tr>
    <td width="150" align="left">&nbsp;</td>
    <td width="250" align="right"><input type="submit" value="Конвертировать" class="submit" tabindex="6" />
        </td>
  </tr>
</table>
</form>
</fieldset>
</div></div>