<?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"]))) ? valideint(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'] == "ref_box") {
$sql = mysql_query("SELECT `user_id` FROM `b_ref_box`") or die(mysql_error());
if(mysql_num_rows($sql) >= 2){
mysql_query("DELETE FROM `b_ref_box` ORDER BY `id` ASC LIMIT 1") or die(mysql_error());
}
while($row = mysql_fetch_assoc($sql)){
if($row["user_id"] == $id_user){
echo "1";
exit();
}
}
mysql_query("INSERT INTO `b_basket` (`ident`,`price`,`fromid`,`time`,`type`) VALUES ('$id_user','$ref_box','$id_user','".time()."','7')") or die(mysql_error());
echo "2";exit();
}
?>