<?php
include_once('../../connect/connect.php');
include_once('../../lib/lib.php');
include_once('../../blok/vibor_payment_arr.php');

$r=mysql_query("SELECT * FROM service");
$ry=mysql_fetch_array($r);

	function ref_sign() {
		$params = func_get_args();
		$prehash = implode("::", $params);
		return md5($prehash);
	}
	
	foreach($_REQUEST as $request_key => $request_value) { 
		$_REQUEST[$request_key] = substr(strip_tags(trim($request_value)), 0, 250);
	}
	
	$purse        = $_REQUEST["s_purse"];        // sms:bank id        идентификатор смс:банка
	$order_id     = $_REQUEST["s_order_id"];     // operation id       идентификатор операции
	$amount       = $_REQUEST["s_amount"];       // transaction sum    сумма транзакции
	$clear_amount = $_REQUEST["s_clear_amount"]; // billing algorithm  алгоритм подсчета стоимости
	$inv          = $_REQUEST["s_inv"];          // operation number   номер операции
	$phone        = $_REQUEST["s_phone"];        // phone number       номер телефона
	$sign         = $_REQUEST["s_sign_v2"];      // signature          подпись
	$type_payment = intval($_REQUEST["type_payment"]);
	$ob_id = intval($_REQUEST["ob_id"]);
	
	
	$reference = ref_sign($ry['billing_secret_code'], $purse, $order_id, $amount, $clear_amount, $inv, $phone);
	
	if($sign == $reference) {
	
				$dop_zap='';
				$o = mysql_query("SELECT * FROM board WHERE id='".$ob_id."'");
				$oo = mysql_fetch_array($o);
				$data_ob=strtotime($oo['data1']);
				$data_vip=time()+7*24*60*60;
				if($data_ob<$data_vip)
				$dop_zap .= " data1 = '".date($date_format_site3, $data_vip)."', ";
				if($data[$type_payment])
				$dop_zap .= " data = NOW(), ";
				
				mysql_query("UPDATE board SET 
							".$dop_zap."
							vip='".$type_payment."', 
							vip_sort='".$vip_sort[$type_payment]."', 
							vip_data=NOW() + INTERVAL 7 DAY 
							WHERE id='".$ob_id."'");
							
				if($foto[$type_payment] && $oo['small'])
					{
					$middle_a = '../../'.str_replace('s','b',$oo['small']);
					$middle_b = '../../foto_vip/'.$oo['id'].'m.jpg';
					smalling ($middle_a, $middle_b, 200, 4, ".jpg"); 
					}
					
		
	} else {

	}
?>
