<?
if (!defined('webid')) {
    exit();
}
if (!(isset($_SESSION["username"]) && isset($_SESSION["password"]))) {
    header("Location: /");
	exit();
}

if ($_GET['from'] == 'balance') {
    $rowxfс = mysql_fetch_array( mysql_query( "SELECT(SELECT count(*) FROM seo_basket WHERE fromid='$_SESSION[iduser]' AND type='7') balsssdf" ) ); 
    if($rowxfс['balsssdf'] > 0) { 
	    header("Location: /");
	    exit();
	} else {
	$summ = mysql_result(mysql_query("SELECT sum(price) FROM seo_basket WHERE fromid='$_SESSION[iduser]'"),0);
	$admoney = mysql_result(mysql_query("SELECT admoney FROM tb_users WHERE id='$_SESSION[iduser]'"),0);
	if ($admoney < $summ or $summ <= 0){
	?>
	<script type="text/javascript">
    hax({url:'/basket/msg=19', id:'flax'});
	</script>
	<noscript>
	<meta http-equiv="refresh" content="0; url=/basket/msg=19" />
	</noscript>
	<?
	}else{
		$sql = mysql_query("SELECT * FROM seo_basket WHERE fromid='$_SESSION[iduser]'");
		while ($row = mysql_fetch_assoc($sql)) {
			$ident = $row['ident'];
			$price = $row['price'];
			$type = $row['type'];
			switch($type) {
			    case '1': $nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса динамической ссылки № $ident с помощью рекламного счета')"); mysql_query("UPDATE tb_ads SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;
			
			    case '6': $nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса письма № $ident с помощью рекламного счета')"); mysql_query("UPDATE seo_paymails SET balance=balance+'$price' WHERE id='$ident' AND fromid='$_SESSION[iduser]'");
			    break;
			
			    case '2':$nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса контекстной ссылки № $ident с помощью рекламного счета')");  mysql_query("UPDATE tb_statlinks SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;
			
			    case '3':$nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса баннера № $ident с помощью рекламного счета')"); 
			    mysql_query("UPDATE tb_advban SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;
				
				case '9':$nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса баннера (100x100) № $ident с помощью рекламного счета')"); 
			    mysql_query("UPDATE tb_advban_100 SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;			    
				
				case '10':$nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса баннера (200x300) № $ident с помощью рекламного счета')"); 
			    mysql_query("UPDATE tb_advban_300 SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;				
			
			    case '4': $res = mysql_fetch_assoc(mysql_query("SELECT * FROM seo_refbirj WHERE rid='$ident'"));
			    $rid = $res['rid'];
			    $trid = $res['trid'];
			    $price = $res['price'];
                $usstat = mysql_fetch_array(mysql_query("SELECT reyting FROM tb_users WHERE id = '$trid'"));
                $price = $price * 0.8;
                $viruchka = $price - ($price * 0.8);
                mysql_query("INSERT INTO tb_viruchka (ident, money, month, year) VALUES (7, '$viruchka', '" . date('m', time()) . "', '" . date('Y', time()) . "')");
                $autoback = mysql_fetch_array(mysql_query("SELECT id, autoback, referer FROM tb_users WHERE id = '$_SESSION[iduser]'"));
			    mysql_query("UPDATE tb_users SET referer='$_SESSION[iduser]', referer2='" . $autoback['referer'] . "', toref=0, toref2=0, autoproc = '$autoback[autoback]' WHERE id = '$rid'");
                mysql_query("UPDATE tb_users SET referer2='$_SESSION[iduser]', toref=0, toref2=0 WHERE referer = '$rid' and id != '" . $autoback['id'] . "'");
                mysql_query("UPDATE tb_users SET money=money+'$price' WHERE id='$trid'");
			    mysql_query("DELETE FROM seo_refbirj WHERE rid='$ident'"); $nowtime=time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$trid','$nowtime','7','Ваш реферал # $rid Продан на бирже рефералов!')"); 
                break;
			
			    case '5':$nowtime = time();
			    mysql_query("InSERT InTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса задания № $ident с помощью рекламного счета')"); 
			    mysql_query("UPDATE seo_tasks SET balance=balance+'$price' WHERE id='$ident' AND fromid='$_SESSION[iduser]'");
			    break;
				
				case '8':$nowtime=time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Оплата штрафа за нарушение правил проекта с помощью рекламного счета')"); 
			    mysql_query("UPDATE tb_users SET finestatus='0' WHERE id='$_SESSION[iduser]'");
			    $finesummam = mysql_fetch_array(mysql_query("SELECT fine FROM tb_config WHERE id = '1'"));
				mysql_query("INSERT INTO tb_viruchka (ident, money, month, year) VALUES (10, '$finesummam[fine]', '" . date('m', time()) . "', '" . date('Y', time()) . "')");
				break;				

			    case '11':$nowtime = time();
			    mysql_query("INSERT INTO tb_allhistory (idus,data,doing,title) values ('$_SESSION[iduser]','$nowtime','4','Пополнение баланса рекламной цепочки № $ident с помощью рекламного счета')");  mysql_query("UPDATE cep_links SET balance=balance+'$price' WHERE id='$ident' AND fromus='$_SESSION[iduser]'");
			    break;				
		    };
		}
        mysql_query("DELETE FROM seo_basket WHERE fromid='$_SESSION[iduser]'");
		mysql_query("UPDATE tb_users SET admoney=admoney-'$summ' WHERE id='$_SESSION[iduser]'");
		?>
		<script type="text/javascript">
        hax({url:'/mdyn', id:'flax'})
        </script>
        <noscript>
        <meta http-equiv="refresh" content="0; url=/mdyn" />
        </noscript>
	<?
	}
    } 
} else
if ($_GET['from'] == 'webmoney'){
	if ($merchant == 1) {
	$price=mysql_result(mysql_query("SELECT sum(price) FROM seo_basket WHERE fromid='$_SESSION[iduser]'"),0);
		?><h3 style="border-bottom: 1px dotted #cccccc; color: #1c62b9; text-shadow: 0 1px 0 #fafafa;">Оплата корзины</h3>
		<center>Для продолжения оплаты нажмите кнопку "оплатить"...<br /><br />
		<form method="POST" action="https://merchant.webmoney.ru/lmi/payment.asp">
		<input type="hidden" name="LMI_PAYMENT_AMOUNT" value="<?=$price?>" />
		<input type="hidden" name="LMI_PAYMENT_DESC" value="Оплата корзины от пользователя <?=$_SESSION['iduser'] ?>" />
		<input type="hidden" name="LMI_PAYEE_PURSE" value="<?=$sitepurse?>" />
		<input type="hidden" name="id" value="<?=$_SESSION['iduser']; ?>" />
		<input type="submit" class='big_btn' value="Оплатить" /></center><br />
		<?
	}else{
		$price=mysql_result(mysql_query("SELECT sum(price) FROM seo_basket WHERE fromid='$_SESSION[iduser]'"),0);
		?><h3 style="border-bottom: 1px dotted #cccccc; color: #1c62b9; text-shadow: 0 1px 0 #fafafa;">Оплата корзины</h3>
		<center>Для продолжения оплаты нажмите кнопку "оплатить"...<br /><br />
		<a href='wmk:payto?Purse=<?=$sitepurse ?>&Amount=<?=$price ?>&Desc=Оплата корзины пользователя <?=$_SESSION['iduser'] ?>&BringToFront=Y'><input type='button' class='big_btn' value='Оплатить' /></a></center><br />
		
		<?
	}
} else
if ($_GET['from'] == 'payeer'){
	$price=mysql_result(mysql_query("SELECT sum(price) FROM seo_basket WHERE fromid='$_SESSION[iduser]'"),0);
	$m1 = iconv("windows-1251", "utf-8", "Оплата корзины от пользователя ".$_SESSION['username']."");
	$m_shop = '93488196'; /// ID 
	$m_orderid = ''.$_SESSION['iduser'].'';
	$m_amount = number_format($price, 2, '.', '');
	$m_curr = 'RUB';
	$m_desc = base64_encode($m1);
	$m_key = 'JHGVf43usfGUVF'; /// Секретный ключ

	$arHash = array(
		$m_shop,
		$m_orderid,
		$m_amount,
		$m_curr,
		$m_desc,
		$m_key
	);
	$sign = strtoupper(hash('sha256', implode(':', $arHash)));
	?>
	<center>Для продолжения оплаты нажмите кнопку "оплатить"...<br /><br />
	<form method="GET" action="//payeer.com/merchant/">
		<input type="hidden" name="m_shop" value="<?=$m_shop?>">
		<input type="hidden" name="m_orderid" value="<?=$m_orderid?>">
		<input type="hidden" name="m_amount" value="<?=$m_amount?>">
		<input type="hidden" name="m_curr" value="<?=$m_curr?>">
		<input type="hidden" name="m_desc" value="<?=$m_desc?>">
		<input type="hidden" name="m_sign" value="<?=$sign?>">
		<input type="submit" name="m_process" class='big_btn' value="Оплатить" />
	</form>
	<?	
} else
if ($_GET['from'] == 'robo'){
	$price=mysql_result(mysql_query("SELECT sum(price) FROM seo_basket WHERE fromid='$_SESSION[iduser]'"),0);
	$robokassaLogin = 'seosarru';
    $InvId = time();
    $pwd1 = '19casper78';
    $SignatureValue = md5( $robokassaLogin . ':' . $price . ':' . $InvId . ':' . $pwd1 . ':shpa=' . $_SESSION['iduser'] );
	?>
	<h3 style="border-bottom: 1px dotted #cccccc; color: #1c62b9; text-shadow: 0 1px 0 #fafafa;">Оплата корзины</h3>
	<center>Для продолжения оплаты нажмите кнопку "оплатить"...<br /><br />
    <form method="POST" action="https://merchant.roboxchange.com/Index.aspx" >
		<input type="hidden" name="MrchLogin" value="<?=$robokassaLogin?>" />
		<input type="hidden" name="OutSum" value="<?=$price?>" />
		<input type="hidden" name="InvId" value="<?=$InvId?>" />
		<input type="hidden" name="Desc" value="Payment baskets Users: <?=$_SESSION['iduser'] ?>" />
		<input type="hidden" name="SignatureValue" value="<?=$SignatureValue?>" />
		<input type="hidden" name="Encoding" value="utf-8" /><input type="hidden" name="Culture" value="ru" />
		<input type="hidden" name="shpa" value="<?=$_SESSION['iduser']?>" />
	    <input type="submit" class='big_btn' value="Оплатить" /></center><br />
	</form>
	<?
}
?>