<?
include_once 'config_wk_pay.php';
include ('core/system.php');

$action = 2;


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']))
	{
	$sq=$dbc->query("SELECT * FROM `worldkassa` WHERE `id_bill` = '".$_POST['id_bill']."'"); $sql = $sq->num_rows;



	if ($sql>0)

		{
		$data= $sq->fetch_assoc();


		if ($_POST['summa']<$data['summa'])
			{
			//Можно поставить уведомление на подмену суммы пополнения
			}
			elseif($_POST['hash']!=md5($hash.$id_shop.$_POST['id_bill'].$_POST['summa']))
			{
			//Можно поставить уведомление, что не совпал хеш
			}
			else
			{
			if ($data['type']=='1')
				{
                $dbc->query("UPDATE `users` SET `gold` = `gold`+".($data['summa']*$curs_almaz)." WHERE `id` = '".$data['id_user']."'");


				}
				elseif($data['type']=='2')
				{
				$dbc->query("UPDATE `users` SET `money` = `money`+".($data['summa']*$curs_money)." WHERE `id` = '".$data['id_user']."'");

				}
			$dbc->query("UPDATE `worldkassa` SET `time_oplata` = '".time()."' WHERE `id` = '".$data['id']."'");

$es = $data['summa']*$curs_almaz;

	$us=$dbc->query("SELECT * FROM `users` WHERE `id` = '".$data['id_user']."'")->fetch_assoc();
if($us['clan']>0 and $action==1){                $dbc->query("UPDATE `clan` SET `kazna` = `kazna`+".($data['summa']*$curs_almaz)." WHERE `id` = '".$us['clan']."'");}

/// под брак


if($us['brak']>0){


$brak=$dbc->query("SELECT * FROM `users` WHERE `id` = '".$us['brak']."'")->fetch_assoc(); 

$kas  = $es*50/100;
$kas  = floor($kas);

$dbc->query("UPDATE `users` SET `gold` = `gold`+".$kas." WHERE `id` = '".$brak['id']."'");


$dbc->query("INSERT INTO `journal` SET `user_id`='".$brak['id']."', `text`='<a href=\"pers.php?ank=".$us['id']."\">".$us['login']."</a> выполнил покупку золота. вам подарок <img src=img/money/money.png>".$kas."'
,`time`='".time()."'"); 


$dbc->query("UPDATE `users` SET `journal`=`journal`+1 WHERE `id`='".$brak['id']."'");   }









if($es>=500){   







    $until = 604800 + TIME;
$dbc->query("update `users` set `daytovip` = '".$until."' , `vip`=1 where `id` = '".$us['id']."'");} 




if($es>=5000){    







    $until = 2592000 + TIME; 
$dbc->query("update `users` set `daytovip` = '".$until."' , `vip`=1 where `id` = '".$us['id']."'");} 




/*
$tyf = $es*10;


$dbc->query("UPDATE `users` SET `rub` = `rub`+'".$tyf."' WHERE `id` = '".$us['id']."'");


$sys = $es*1000;


$dbc->query("update `users` set `serebro` = `serebro`+'".$sys."' where `id` = '".$us['id']."'");





if($es>=500){ $dbc->query("update `users` set `snow` = `snow`+50 where `id` = '".$us['id']."'"); }

if($es>=2000 and $es<3000){











    $until = 7776000 + TIME;


$dbc->query("update `users` set `daytovip` = '".$until."' , `vip`=1 where `id` = '".$us['id']."'");}

*/
if($es>=5000){














$dbc->query("update `users` set `serebro` = `serebro`+20000000, `rub`=`rub`+200000, `leg`=`leg`+3000 where `id` = '".$us['id']."'");



include 'super_action.php';




}









/*

$until = 7776000 + TIME;


$dbc->query("update `users` set `daytovip` = '".$until."' , `vip`=1 where `id` = '".$us['id']."'");

$dbc->query("update `clan` set `sera` = `sera`+1000000, `rub`=`rub`+30000, `kazna`=`kazna`+2500 where `id` = '".$us['clan']."'");

$dbc->query("INSERT INTO `clan_journal` SET `clan`='".$us['clan']."', `user`='".$us['id']."', `text`='<img src=img/class/".$us['storona']."/".$us['pers']."/pers.png><a href=\"pers.php?ank=".$us['id']."\">".$us['login']."</a> Активировал акцию. казна пополнена на <img src=\"img/money/money.png\"> 2500 <img src=\"img/money/rubin.png\"> 30000 <img src=\"img/stat/sera.png\">1000000',        `time`='".time()."'");


*/


if($es>=5000){

/*
if($us['s_pet']==0){












$pet_buy = $dbc->query("SELECT * FROM `pets_tj` WHERE `id` = 8")->fetch_assoc();

$dbc->query("INSERT INTO `user_pets` SET 

`id_user` = '$us[id]', 
`id_pets` = '$pet_buy[id]', 
`name` = '$pet_buy[name]',
`str` = '$pet_buy[str]',
`vit` = '$pet_buy[vit]',
`def` = '$pet_buy[def]',
`img` = '$pet_buy[img]',
`level` = '1',
`arena_battle` = '10'
,`lite`='iLegendary'") or die(mysql_error());  

$dbc->query("UPDATE `users` SET 
 
`s_pet` =  '1'
 WHERE `id` = '$us[id]'") or die(mysql_error());  }

*/





 }




//include 'action_items.php';


//include_once 'action_mart.php';









//include_once 'action_clan.php';





			}
		}
	}
?>
