<? 

include_once '../protected/sys.php';
include_once 'config.php';
						

if (isset($_POST['id_shop']) && is_numeric($_POST['id_shop']) && isset($_POST['id_bill']) && is_numeric($_POST['id_bill']) && isset($_POST['summa']) && is_numeric($_POST['summa']) && isset($_POST['hash']))
	{
$col=$db->rows("SELECT * FROM `worldkassa` WHERE `id_bill` =?",array($_POST['id_bill']));
	if($col>0)
		{
		$data=$db->fetch("SELECT * FROM `worldkassa` WHERE `id_bill` =?",array($_POST['id_bill']));
		if ($_POST['summa']<$data['summa'])
			{
			$insers=$db->query("INSERT INTO `worldkassa_error` SET `id_user`=?,`error`=?,`time`=?",array($user['id'],"Подмена суммы",time()));
			}
			elseif($_POST['hash']!=md5($hash.$id_shop.$_POST['id_bill'].$_POST['summa']))
			{
			$insers=$db->query("INSERT INTO `worldkassa_error` SET `id_user`=?,`error`=?,`time`=?",array($user['id'],"Подмена кеша",time()));
			}
			else
			{

			foreach($cena_gold as $gold=>$summa)
				{
				
				if ($summa==$data['summa']){
				$gold_u=$db->fetch("SELECT `gold` FROM `users` WHERE `id`=?",array($data['id_user']));
				$update=$db->query("UPDATE `users` SET `gold`=? WHERE `id`=?",array($gold_u['gold']+$gold,$data['id_user']));		
				}
}

				
			$update=$db->query("UPDATE `worldkassa` SET `time_oplata` = ? WHERE `id` = ?",array(time(),$data['id']));
			}
		}
	}
?>