<?php 
include "bank.php";
$result = $conn->query("SELECT * FROM `users` WHERE token = '".sanitize($_GET['token'])."' ");
		 if ($result->num_rows > 0) {
				// output data of each row
				$row = $result->fetch_assoc();
					// print_r($row );
					$uid = $row['id'];
					$fn = $row['finderid'];
					$noom = json_decode($row['numbers']);
					$smsprice = json_decode(package($row['level']) , true);
					//print_r($smsprice);
					unset($smsprice['afzoode']);
					$udata = array
					(
						'id'=> $row['id'],
						'userstats' => '1',
						'name'=> $row['name'],
						'username'=>$row['username'],
						'mood'=>$row['mood'],
						'numbers'=> $noom ,
						'st'=>$row['st'],
						'exp'=>rooz($row['exp']),
						'level'=>$row['level'],
						'token'=>$row['token'],
						'credit'=>$row['credit'],
						'smsprice'=>$smsprice,
						'finder'=>$row['finderid'],
						'fata'=>fulluser($row['finderid'])
					);
					$cri = $row['credit'];
					$exp = $row['exp'];
					if(($exp-time()) < 0){
						$exp = time();
					}
					//$exp = $exp + 31536000;
					$uname = $row['username'];
					$pass =$row['password'];
					$from = $noom[2];
					
				
				
				//print_r($udata);
				
			//	print_r($_POST);
				
				
				
		
				
			?>
					
							
					
				
<!DOCTYPE html>
<html lang="en" >
<head>
  <title>تمدید نرم افزار</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

<link rel="stylesheet" href="style.css">
  <script >
  function tofa( num, dontTrim ) {

    var i = 0,

        dontTrim = dontTrim || false,

        num = dontTrim ? num.toString() : num.toString().trim(),
        len = num.length,

        res = '',
        pos,

        persianNumbers = typeof persianNumber == 'undefined' ?
            ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'] :
            persianNumbers;

    for (; i < len; i++)
        if (( pos = persianNumbers[num.charAt(i)] ))
            res += pos;
        else
            res += num.charAt(i);

    return res;
	
}
  </script>
<style>
*{
	font-family: IRANSans;
}
@font-face {
      font-family: 'insta';
      src: url('./font/insta.eot?22168112');
      src: url('./font/insta.eot?22168112#iefix') format('embedded-opentype'),
           url('./font/insta.woff?22168112') format('woff'),
           url('./font/insta.ttf?22168112') format('truetype'),
           url('./font/insta.svg?22168112#insta') format('svg');
      font-weight: normal;
      font-style: normal;
    }
     
     
    .demo-icon
    {
      font-family: "insta";
      font-style: normal;
      font-weight: normal;
      speak: none;
     
      display: inline-block;
      text-decoration: inherit;
      width: 1em;
      margin-right: .2em;
      text-align: center;
      /* opacity: .8; */
     
      /* For safety - reset parent styles, that can break glyph codes*/
      font-variant: normal;
      text-transform: none;
     
      /* fix buttons height, for twitter bootstrap */
      line-height: 1em;
     
      /* Animation center compensation - margins should be symmetric */
      /* remove if not needed */
      margin-left: .2em;
     
      /* You can be more comfortable with increased icons size */
      /* font-size: 120%; */
     
      /* Font smoothing. That was taken from TWBS */
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
     
      /* Uncomment for 3D effect */
      /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
    }

.rofi {
    margin: 2% 5%;
}
.rofi span {
    float: left;
	    font-size: 12px;
}
.modal-dialog {
    position: relative;
    width: auto;
    margin: 10px 20px 10px 10px;
}

.inpage {
    margin: 3% !important;
    background: white;
    padding: 1%;
    /* -webkit-box-shadow: 1px 11px 22px -2px rgba(199,197,199,1); */
    -moz-box-shadow: 1px 11px 22px -2px rgba(199,197,199,1);
    box-shadow: -1px 8px 24px 0px rgb(204, 201, 201);
    border-radius: 4px;
    font-size: 16px;
    color: #818181;
    font-weight: 100;
    text-align: right;
    width: 94%;
    direction: rtl;
}
.inpage i {
    float: right;
    margin: 0 0 0 16px;
}
.chel {
    padding: 10px;
    width: 48%;
    float: right;
    margin: 1%;
    text-align: center;
    min-height: 100px;
}
.col3 {
    background: #f9c54c;
}

.col2 {
    background: #e6e3e3;
}

.col1 {
    background: gold;
}

.col4 {
    background: aqua;
}
.blueline {
    background: #237BDC;
    position: absolute;
    width: 100%;
    height: 17%;
    top: 0;
    z-index: 998;
    /* border-left: 5px solid; */
    margin: 0 auto;
    left: 0;
    border-radius: 0 0 100% 100%;
}
.ripple{position:relative;overflow:hidden;transform:translate3d(0,0,0)}.ripple:after{content:"";display:block;position:absolute;width:100%;height:100%;top:0;left:0;pointer-events:none;background-image:radial-gradient(circle,#000 10%,transparent 10.01%);background-repeat:no-repeat;background-position:50%;transform:scale(10,10);opacity:0;transition:transform .5s,opacity 1s}.ripple:active:after{transform:scale(0,0);opacity:.2;transition:0s}
.modal-body {
    direction: rtl;
}
ul.datelist {
    list-style: none;
    padding: 0;
}

.datelist li {
    float:right;
    width:33%;
    text-align:center;
    background:blue;
    color:white;
    padding:5px;
    border-left:1px solid 
}
li.ripple.active {
    background: cadetblue;
}
span.takh {
    text-decoration: line-through;
    color: darkred;
}
span.vahed {
    font-size: 11px;
}.chel span {
    font-size: .8em;
}
</style>
  
  
</head>
<body style="padding-top: 20%;background: transparent;">


<div class="blueline" ></div>
<div class="container" >
	<div class="row">
		<div class="col-md-12 headpage mar" >
		 <center><i class="far fa-credit-card"></i><br/>نتیجه پرداخت</center>
		</div> 
		<br/><br/><br/><br/><br/>
		<div class="mar headpage"  >
			<?php
		$transId = $_POST['transId'];
		$result = verify($payapi,$transId);
		$result = json_decode($result, true);
		//print_r($result);Array ( [status] => 1 [amount] => 5000 )
		//INSERT INTO `payment`(`id`, `uid`, `price`, `datatype`, `date`, `transid`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6])
		//UPDATE `users` SET `credit`= WHERE 1
		//Array ( [status] => 1 [transId] => 181 [factorNumber] => 10 [description] => [cardNumber] => 123456******1234 [message] => OK )

		if($result['status'] == 1){
			$fid1 = $_POST['factorNumber'];
			$fid = json_decode($fid1,true);
			
			$mablagh = $result['amount'];
			$Nmab = floor(($mablagh*9)/100);
			$ve  = $mablagh;
			$newmab = $mablagh+$cri;
			$dt = time();
			//print_r($fid);
			//echo "INSERT INTO `payment`(`uid`, `fid`, `price`, `datatype`, `date`, `transid`) VALUES ($uid,$fn,$mablagh,$fid1,$dt,$transId)";
			
			
			$conn->query("INSERT INTO `payment`(`uid`, `fid`, `price`, `datatype`, `date`, `transid`) VALUES ('$uid','$fn','$mablagh','$fid1','$dt','$transId')");
			
				if($fn > 0){
					
					
					if($fid['type'] == 'balance'){
						$for = "balance";
						//$sood =  floor(($mablagh*6)/100);
						
						$sood  = calsood($udata['level'],$result['amount']);
						
						
					}elseif($fid['type'] == 'tamdid'){
						
						
						$packprice= packid($fid['code'])['price'];
						$asl = floor($packprice*($fsd/100))/12;
						//print_r($fid);
						$darsad = floor($asl*($udata['fata']['darsad']/100));
						$sood = ($asl-$darsad)*$fid['time'];
						//echo $asl."/".$darsad."/".$sood;
						//exit();
						//$Nmab = floor(($ve*30)/100);
						$for = "tamdid";
					}
					
					if($sood > 0){
						addbalance($fn,$sood,$udata['fata']['credit']);
						$conn->query("INSERT INTO `soood`(`fromid`, `toid`, `money`, `fortype`, `date`) VALUES ($uid,$fn,$sood,'$for',$dt)");
						
						$fp = getuser($finder,$udata['fata']['pushid']);
					if($fp !== ""){
						 pushsend("اطلاعیه پرداخت سود","مبلغ ".tofa($sood)."ریال اربابت خرید کاربر ".hid($udata['username'])." برای شما واریز شد",array($udata['fata']['pushid']));
					}
						
					}
					
				}
			
			if($fid['type'] == 'balance'){
				$conn->query("UPDATE `users` SET `credit`=$newmab WHERE id=".$uid);
			//	echo "UPDATE `users` SET `credit`=$newmab WHERE id=".$uid;
				echo( mysqli_error($conn));
				?>
				<table dir="rtl" class="table table-striped">
					<tbody>
					  <tr>
						<td>پرداخت از بابت : </td>
						<td class="jb" >افزایش موجودی</td>
					  </tr>
					  <tr>
						<td>وضعیت پرداخت :</td>
						<td class="jb" >موفق</td>
					  </tr>
					  <tr>
						<td>کد تراکنش</td>
						<td class="jb" ><?php echo $transId; ?></td>
					  </tr>
					</tbody>
				  </table>
				
				<?php
				
			}elseif($fid['type'] == 'tamdid'){
				
				$exp = $exp + ($fid['time']*2625200);
				$level = packid($fid['code'])['code'];
				
			//	echo "UPDATE `users` SET `exp`='$exp', 'level'='".packid($fid['code'])['code']."' WHERE id=".$uid;
				$conn->query("UPDATE `users` SET `exp`='$exp', `level`='$level' WHERE id=".$uid); 
				echo $conn->error;
				 ?>
				<table dir="rtl" class="table table-striped">
					<tbody>
					  <tr>
						<td>پرداخت از بابت : </td>
						<td class="jb" >تمدید پنل</td>
					  </tr>
					  <tr>
						<td>مبلغ پرداختی : </td>
						<td class="jb" ><?php echo $fid['amount']; ?> ريال</td>
					  </tr>
					  <tr>
						<td>وضعیت پرداخت :</td>
						<td class="jb" >موفق</td>
					  </tr>
					  <tr>
						<td>کد تراکنش</td>
						<td class="jb" ><?php echo $transId; ?></td>
					  </tr>
					</tbody>
				  </table>
				<?php }
		}else{ ?>
				<table dir="rtl" class="table table-striped">
					<tbody>
					  
					  <tr>
						<td>وضعیت پرداخت :</td>
						<td class="jb" >نا موفق</td>
					  </tr>
					  
					</tbody>
				  </table>
				
  <?php } ?>
		  </div>
	</div>
		  
		  
</div>
</body>
</html>
<?php	
				
				
			}else{
				//echo "0 results";
				$data = array("userstats" => "0" ,"msg" => "token is invalide" );
				echo json_encode($data );
			}

?>