<?
include_once 'config.php';
include_once 'start.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']))
	{
	$sql=mysql_query("SELECT * FROM `worldkassa` WHERE `id_bill` = '".$_POST['id_bill']."'");
	if (mysql_num_rows($sql)>0)
		{
		$data=mysql_fetch_assoc($sql);
		if ($_POST['summa']<$data['summa'])
			{
			//Можно поставить уведомление на подмену суммы пополнения
			}
			elseif($_POST['hash']!=md5($hash.$id_shop.$_POST['id_bill'].$_POST['summa']))
			{
			//Можно поставить уведомление, что не совпал хеш
			}
			else
			{
			    $procent=$data['summa']/100;
			    if($data['summa']>=1)$bonus=($procent*400);
			    $ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".$data['id_user']."'"));
$mcu=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_user` WHERE `id_user` = '$ku[id]'"));
$mc=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective` WHERE `id` = '$mcu[id_collective]'"));
if($mc['bank']>=1)
{
    $bank=($data['summa']/100)*($mc['bank']*5);
}
 $summa=($data['summa']+$bonus+$bank);
			    $time=time();
			mysql_query("UPDATE `worldkassa` SET `time_oplata` = '".time()."' WHERE `id` = '".$data['id']."'");
			mysql_query("UPDATE `kolhoz_user` SET `fermoney` = `fermoney`+'".$summa."' WHERE `id` = '".$data['id_user']."'");
			$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".$data['id_user']."'"));
			if($ku['expbonus']<5000)
			{
			    			mysql_query("UPDATE `kolhoz_user` SET `expbonus` = `expbonus`+'".$data['summa']."' WHERE `id` = '".$data['id_user']."'");

			}
			if($data['summa']>=299 && $ku['exp5']<1)
			{
			   $timee=(3600*24*5);
    mysql_query("UPDATE `kolhoz_user` SET `exp5` = '1', `exp5_time` = '".($ku['exp5_time']>$time?"".($ku['exp5_time']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '".$data['id_user']."'");

			}

if($data['summa']>=99)
{
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '82', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '82', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '82', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '82', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '82', `id_user` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `greynickdostup` = '1', `bonus_ticket` = `bonus_ticket`+'5' WHERE `id` = '".$data['id_user']."'");
$text='Вам начислены бонусы за покупку. Подробнее на странице [url=/?action]Акции[/url].';
}
if($data['summa']>=300)
{
    			$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".$data['id_user']."'"));
    		mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '116', `id_user` = '$ku[id]'");

$timee=(3600*24*15);
mysql_query("UPDATE `kolhoz_user` SET `money2x_time` = '".($ku['money2x_time']>$time?"".($ku['money2x_time']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '$ku[id]'");
$timeeAction=(3600*24*10);
mysql_query("UPDATE `kolhoz_user` SET `action_time` = '".($ku['action_time']>$time?"".($ku['action_time']+$timeeAction)."":"".($time+$timeeAction)."")."' WHERE `id` = '".$data['id_user']."'");
$timee2=3600*24*30;
mysql_query("UPDATE `kolhoz_user` SET `premium_time` = '".($ku['premium_time']>$time?"".($ku['premium_time']+$timee2)."":"".($time+$timee2)."")."' WHERE `id` = '$ku[id]'");

mysql_query("UPDATE `kolhoz_user` SET  `animal_ticket` = `animal_ticket`+'5' WHERE `id` = '".$data['id_user']."'");
$sheep=mysql_fetch_array(mysql_query("SELECT * FROM `sheeps` WHERE `id_user` = '".$data['id_user']."'"));
mysql_query("".($sheep['sheep']<=0?"INSERT INTO `sheeps` (`id_user`,`sheep`) VALUES ('".$data['id_user']."','7')":"UPDATE `sheeps` SET `sheep` = `sheep` + '7' WHERE `id_user` = '".$data['id_user']."'")."");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '113', `id_user` = '".$data['friend']."'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '113', `id_user` = '".$data['friend']."'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '113', `id_user` = '".$data['friend']."'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '113', `id_user` = '".$data['friend']."'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '113', `id_user` = '".$data['friend']."'");

$procent=$data['summa']/100;
			    if($data['summa']>=1)$bonus=($procent*400);
$summa2=($data['summa']+$bonus);
mysql_query("UPDATE `kolhoz_user` SET `fermoney` = `fermoney`+'".$summa2."' WHERE `id` = '".$data['friend']."'");
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '".$data['friend']."', `id_kont` = '701', `msg` = '
Ваш друг  [url=/?user=".$data['id_user']."]".$ku['nick']."[/url] подарил вам:
Фермани: [img]/images/fermoney.png[/img] ".$summa2."
Животное Леопон: 5 штук.

Желаем вам приятной игры!', `time` = '$time', `type` = 'to'");	
}
if($data['summa']>=500)
{
    			$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".$data['id_user']."'"));
    		mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_petground` SET `id_pet` = '119', `id_user` = '$ku[id]'");

$timee=(3600*24*30);
mysql_query("UPDATE `kolhoz_user` SET `money2x_time` = '".($ku['money2x_time']>$time?"".($ku['money2x_time']+$timee)."":"".($time+$timee)."")."' WHERE `id` = '$ku[id]'");
$timeeAction=(3600*24*10);
mysql_query("UPDATE `kolhoz_user` SET `action_time` = '".($ku['action_time']>$time?"".($ku['action_time']+$timeeAction)."":"".($time+$timeeAction)."")."' WHERE `id` = '".$data['id_user']."'");
$timee2=3600*24*90;
mysql_query("UPDATE `kolhoz_user` SET `premium_time` = '".($ku['premium_time']>$time?"".($ku['premium_time']+$timee2)."":"".($time+$timee2)."")."' WHERE `id` = '$ku[id]'");

$sheep=mysql_fetch_array(mysql_query("SELECT * FROM `sheeps` WHERE `id_user` = '".$data['id_user']."'"));
mysql_query("".($sheep['sheep']<=0?"INSERT INTO `sheeps` (`id_user`,`sheep`) VALUES ('".$data['id_user']."','15')":"UPDATE `sheeps` SET `sheep` = `sheep` + '15' WHERE `id_user` = '".$data['id_user']."'")."");

$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".$data['id_user']."'"));
$mcu=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_user` WHERE `id_user` = '$ku[id]'"));
$mc=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective` WHERE `id` = '$mcu[id_collective]'"));
mysql_query("UPDATE `kolhoz_collective` SET  `bank` = `bank` +'7', `soil` = `soil` + '7', `irrigate` = `irrigate` + '7', `vet` = `vet` + '7', `greenhouse` = `greenhouse` + '7', `cellar` = `cellar` + '7', `school` = `school` + '7' WHERE `id` = '$mc[id]'");
mysql_query("UPDATE `kolhoz_user` SET  `expbonus` = `expbonus`+'500' WHERE `id` = '".$data['id_user']."'");

}

mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '".$data['id_user']."', `id_kont` = '701', `msg` = '
На ваш счет поступил платеж [img]/images/fermoney.png[/img] ".$data['summa']."
Бонус за акцию: [img]/images/fermoney.png[/img] ".$bonus."
Бонус за банк: [img]/images/fermoney.png[/img] ".$bank."
Всего начислено: [img]/images/fermoney.png[/img] ".$summa."

".$text."

Желаем вам приятной игры!', `time` = '$time', `type` = 'to'");			}
		}
	}
	?>