<?
include 'mysql.php';
include_once("include/sesi.php");
Error_Reporting(E_ALL & ~E_NOTICE);
include_once("include/antixak.php");
include 'include/ini.php';
$_title = 'Персонаж';
include 'include/header.php';
$log = htmlspecialchars(stripslashes($log));
$pas = htmlspecialchars(stripslashes($pas));
/////////////////////////////////////////////////////
$text = @file("MySql/base123/reg/$log.dat");
if ($text!=""){
$udata = explode(":||:",$text[0]);
$login=trim($udata[0]);
$password=trim($udata[1]);}
////////////////////////////////////////////////////////
if (isset($user)) {

switch($go) {

default:

echo "<form action=\"sellrukvesh.php?$sd&go=go&name=$name&id=$id\" method=\"post\"><small>Сколько?:</small><br/>";
echo "<input name=\"kol\" maxlength=\"10\" title=\"*N\" emptyok=\"true\"/><br/>";
echo "<form action=\"sellrukvesh.php?$sd&go=go&name=$name&id=$id\" method=\"post\"><small>Комментарий:</small><br/>";
echo "<input name=\"kom\" maxlength=\"50\" title=\"*N\" emptyok=\"true\"/><br/>";
echo "<small>Цена за 1 штуку:</small><br/>";
echo "<input name=\"cena\" maxlength=\"10\" title=\"*N\" emptyok=\"true\"/><br/>";
echo '<input type="submit" value="Продать!" /></form>';

break;

case 'go':

$kol = htmlspecialchars(stripslashes($kol));
$id = htmlspecialchars(stripslashes($id));
$cena = htmlspecialchars(stripslashes($cena));

if(eregi("[^0-9]",$kol)){echo"<small>Вводите число, а не буквы!</small>"; include_once"include/down.php"; exit;}
if(eregi("[^0-9]",$cena)){echo"<small>Вводите число, а не буквы!</small>"; include_once"include/down.php"; exit;}

if(empty($cena)){echo"<small>Вы не ввели цену товара.</small>"; include_once"include/down.php"; exit;}
if(empty($kol)){echo"<small>Вы не ввели колличество товара.</small>"; include_once"include/down.php"; exit;}


$file = @file("MySql/base123/item/$log.dat");
$file = array_reverse($file);
$data = explode(":||:",$file[$id]);

if($data[4]=="Olimpiad Medal"){echo"<small>Продажа медалей ЗАПРЕЩЕНА!</small>"; include_once"include/down.php"; exit; }
if($kol>$data[3]){echo"<small>У вас нет столько вещей!</small>"; include_once"include/down.php"; exit; }
$text="$data[0]||$data[1]||$data[2]||$kol||$data[4]||$cena||$text||";

$fp=fopen("MySql/base123/sellruk/$log.dat","w");
flock($fp,LOCK_EX);
fputs($fp,"$text");
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);

$kol=$data[3]-$kol;

if($kol=="0"){



$file=file("MySql/base123/item/$log.dat");
$file = array_reverse($file);
$fp=fopen("MySql/base123/item/$log.dat","w");
flock ($fp,LOCK_EX);
for ($i=0;$i< sizeof($file);$i++) { if ($i==$id) {unset($file[$i]);} }
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}else{


$file=file("MySql/base123/item/$log.dat");
$file = array_reverse($file);
$fp=fopen("MySql/base123/item/$log.dat","w");
flock ($fp,LOCK_EX);
for ($i=0;$i< sizeof($file);$i++) { if ($i==$id) {unset($file[$i]);} }
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);

$text="$data[0]:||:$data[1]:||:$data[2]:||:$kol:||:$data[4]:||:";

$fp=fopen("MySql/base123/item/$log.dat","a+");
flock($fp,LOCK_EX);
fputs($fp,"$text\r\n");
fflush($fp);
flock($fp,LOCK_UN);
fclose($fp);

}

echo"<small>Вещи выставленны на продажу.<br/><a href=\"sellruktime.php?$sd\">Продолжить</a></small>";

break;

}
}else{echo"<small>Пароль или логин неверен!</small>";}

include_once"include/down.php";
?>
