<?php
session_start();
header("Content-type: text/html; charset=windows-1251");
if(isset($_SESSION["login"])){
define("PATH", $_SERVER['DOCUMENT_ROOT']);
include(PATH."/core/func.php");
include(PATH."/core/db.php");
include(PATH."/core/set.php");
include(PATH."/core/define.php");
include(PATH."/core/defineset.php");

$hide = "<script type='text/javascript'>
$('#sapper-".intval($_POST["id"])."').hide();
</script>";


db_connect();
$res = db_query("SELECT `summa` FROM `sapper_games` WHERE `id` = ".intval($_POST["id"])." AND `login` = '".db_string($_SESSION["login"])."'");
$err = NULL;
if(db_rows($res) == 0) {
	echo "<script type='text/javascript'>
$('.sapper-".intval($_POST["id"])."').html('Игра не найдена');
</script>";
}else{
	$row = db_assoc($res);
	db_query("UPDATE `".DBpref."users` SET `balance` = `balance` + ".round($row["summa"],2)." WHERE `login` = '".db_string($_SESSION["login"])."'");
	db_query("DELETE FROM `sapper_games` WHERE `id` = ".intval($_POST["id"]));
	echo "<script type='text/javascript'>
$('.sapper-".intval($_POST["id"])."').html('Удалено');
</script>";
}

db_close();
}
?>


