<?php
session_start();
header( 'Content-type: text/html; charset=windows-1251' );
error_reporting( 1 );
require($_SERVER['DOCUMENT_ROOT']."/sfb.php");

$id_user = (isset($_SESSION["iduser"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["iduser"]))) ? intval(trim($_SESSION["iduser"])) : false;

if(!isset($_SESSION['iduser'])) { exit(); }
if(!isset($_POST['func'])) { exit(); }
if($_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest") { exit(); }

// жалоба на серфинг
if($_POST['func'] == "add_comp") {
$ident = valideint($_POST["id"]);
if(mysql_num_rows(mysql_query("SELECT * FROM `user_zal` WHERE `link_id`='$ident' AND `user`='$id_user'"))==0){
$abuse = iconv("UTF-8", "windows-1251", validetext($_POST["text"]));
mysql_query("INSERT INTO `user_zal` (`link_id`,`user`,`date`,`text`) values ('$ident','$id_user','".time()."','$abuse')") or die(mysql_error());
mysql_query("UPDATE `tb_ads` SET `all_zh`=`all_zh`+'1' WHERE `id`='$ident'") or die(mysql_error());
mysql_query("UPDATE `tb_ads` SET `modered`='2' WHERE `all_zh`>'5'") or die(mysql_error());
echo "1";exit();
}else{echo "2";exit();}
}
?>