<?php 
include "bank.php";
$result = $conn->query("SELECT * FROM `users` WHERE token = '".sanitize($_GET['token'])."' ");
$resn = $result->num_rows;
		 if ($resn > 0) {
				// output data of each row
				$row = $result->fetch_assoc();
					// print_r($row );
					$uid = $row['id'];
					$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'])
					);
				if(isset($_POST['mah'])){
					
			//	print_r($_POST);
					$sql = "SELECT * FROM `package` WHERE id='".sanitize($_POST['id'])."' ORDER BY code DESC  ";
					$result3 = $conn->query($sql);
					$row = $result3->fetch_assoc(); 
					$mahane = $row['price']/12;
					$takhfif = ((($row['price']*($fsd/100))*$udata['fata']['darsad'])/100)/12;
					$mande = $mahane-$takhfif;
					
					
					//print_r(array('mahan'=>$mahane,'takhfif'=>$takhfif,'mande'=>$mande));
					if($mahane == $mande){ $gimat = $mahane*sanitize($_POST['mah']); }else{ $gimat = $mande*sanitize($_POST['mah']); }
					
					$redirect = 'http://systemsms.ir/api/verfy.php?token='.sanitize($_GET['token']);
					$amount = $gimat*10;
					$fac = json_encode(array('type'=>'tamdid','code'=>sanitize($_POST['id']),'time'=>sanitize($_POST['mah']),'amount'=>$amount));
					$result = send($payapi,$amount,$redirect,$fac);
					
					$result = json_decode($result);

					if($result->status) {
						$go = "https://pay.ir/payment/gateway/$result->transId";
						header("Location: $go");
					} else {
						echo $result->errorMessage;
						
					}
				//exit();
				}
				
					
					

					
				
				}else{
						$udata = array();
						 $title = "Ooopss";
					 }
				
			?>
					
							
					
				

<!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;">


<?php
	if ($resn > 0) { 
		if( $udata['exp'] < 1){
			?> 
			<!-- Modal -->
			
			<div id="myModal" class="modal fade" role="dialog">
			  <div class="modal-dialog">

				<!-- Modal content-->
				<div class="modal-content">
				  
				  <div class="modal-body">
				  <h1><center><i class="demo-icon icon-attention-4">&#xe806;</i></center></h1>
					<p><center>مدت زمان استفاده از نرم افزار برای شما به پا یان رسیده است لطفا با انتخاب یک پکیج آن را تمدید نمایید</center></p>
				  </div>
				  <div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">بستن</button>
				  </div>
				</div>

			  </div>
			</div>
			<script type="text/javascript">
				$(window).on('load',function(){
					$('#myModal').modal('show');
				});
			</script>
			<?php 
		} 
?>




				<?php
				$sql = "SELECT * FROM `package` ORDER BY code DESC ";
				$result = $conn->query($sql);

					// output data of each row
					while($row = $result->fetch_assoc()) {
					//  echo '<div class=" ripple chel col'.$row['id'].'" >'.$row['title'].'<hr/>'.tofa($row['price']/12).' تومان/ماهانه</div>';
					
					$mahane = $row['price']/12;
					$crp = $row['crp'];
					$smsprice = json_decode($row['smsprice'],true);
					
					if($udata['finder'] == 0){
						$takhfif = 0;
					}else{
						$takhfif = ((($row['price']*($fsd/100))*$udata['fata']['darsad'])/100)/12;
					}
					
					$mande = $mahane-$takhfif;
					
					if($mahane == $mande){ $gimat = tofa($mande*12); }else{ $gimat = "<span class='takh' >".tofa($mahane*12)."</span> ".tofa($mande*12); }
					?>
					
					<div id="myModal<?php echo $row['id']; ?>" class="modal fade" role="dialog">
						  <div class="modal-dialog">
							<!-- Modal content-->
							<div class="modal-content">
							  <div class="modal-header">
									<button type="button" class="close" data-dismiss="modal">&times;</button>
									<h4 class="modal-title"><?php echo $row['title']; ?></h4>
								  </div>
							  <div class="modal-body">
								<div class="row" > 
									<i class="demo-icon icon-credit-card-2">&#xe802;</i>  قیمت : <?php echo tofa($mahane); ?> <span class="vahed" >(تومان/ماهانه)</span><hr/>
									<i class="demo-icon icon-gift">&#xe823;</i>  اعتبار هدیه ماهانه : <?php echo tofa($crp); ?> <span class="vahed" >(تومان/ماهانه)</span><hr/>
									<i class="demo-icon icon-mail">&#xe804;</i>   حداقل قیمت پیامک : <?php echo tofa($smsprice['985000145']); ?><span class="vahed" >(ریال)</span><hr/>
									<i class="demo-icon icon-handshake-o">&#xf2b5;</i>تخفیف معرف شما :  <?php echo tofa($takhfif); ?><span class="vahed" >(تومان/ماهانه)</span><hr/>
								</div>
								<div class="row col-md-12" >
								<ul class="datelist">
									<li class="ripple m<?php echo $row['id']; ?>3 rool<?php echo $row['id']; ?>" onclick="resdate<?php echo $row['id']; ?>(3)" >
									<span  >3 ماهه </span>
									</li>
									<li class="ripple m<?php echo $row['id']; ?>6 rool<?php echo $row['id']; ?>"  onclick="resdate<?php echo $row['id']; ?>(6)" >
									<span>6 ماهه </span>
									</li>
									<li class="ripple m<?php echo $row['id']; ?>12 active rool<?php echo $row['id']; ?>"  onclick="resdate<?php echo $row['id']; ?>(12)" >
									<span >12 ماهه </span>
									</li>
								</ul>
								<hr/>
								
								
								
								<div class="col-xs-6 mab<?php echo $row['id']; ?>" > <?php echo $gimat; ?> تومان
								</div>
								<div class="col-xs-6" > مبلغ قابل پرداخت:
								</div>
								<div class="col-xs-6" > 
								
								<?PHP if( $udata['exp'] < 1 || $udata['level'] == $row['code']){ ?>
								<form action="" class="mar" method="post" >
									<div class="form-group" dir="rtl" >
									
									 <input type="hidden" readonly  class="form-control" id="id<?php echo $row['id']; ?>"  value="<?php echo $row['id']; ?>" name="id">
									 <input type="hidden" readonly  class="form-control" id="mah<?php echo $row['id']; ?>"  value="12" name="mah">
									</div>

									<button type="submit" class="btn btn-default"  width="100%" >پرداخت از درگاه بانک</button>
								  </form>
								<?php }else{
									echo '<p type="submit" >امکان تغیر سرویس تا '.$udata['exp'].' روز دیگر میسر نیست</ح>';
								}  ?>
								  
								</div>
								<div class="col-xs-6" > 
								
									<button type="submit" class="btn btn-default" width="100%" >کارت به کارت</button>
								 
								  
								</div>
								</div>
								
							  </div>
							  <div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">بستن</button>
							  </div>
							</div>

						  </div>
						</div>
					<script>
					
						function resdate<?php echo $row['id']; ?>(mah){
							var mahane= <?php echo $mahane; ?>;
							var mande= <?php echo $mande; ?>;
								if(mahane == mande){
									var mab = mahane*mah;
									var nama = tofa(mab.toLocaleString()) + "تومان";
								}else{
									var mab = mande*mah;
									var nama = "<span class='takh' >" + tofa((mahane*mah).toLocaleString()) + "</span> " + tofa(mab.toLocaleString()) + " تومان ";
								}
								
							$(".mab<?php echo $row['id']; ?>").html(nama);	
							$("#mah<?php echo $row['id']; ?>").val(mah);
							$(".rool<?php echo $row['id']; ?>").removeClass("active");
							$(".m<?php echo $row['id']; ?>"+ mah).addClass("active");
						}
					</script>
					<?php 
					}
				 ?>

<div class="blueline" ></div>
<div class="container" >
	<div class="row">
		<div class="col-md-12 headpage mar" >
		 <center><i class="demo-icon icon-graduation-cap">&#xe80a;</i><br/>تمدید پنل</center>
		
		
		</div> 
		<br/><br/><br/>
		<div class="col-md-12  mar" >
		 <p for="email">سرویس فعلی :  <?php echo packim($udata['level'])['title']; ?><hr/> مهلت استفاده :  <?php echo $udata['exp']; ?> روز</p>
		</div>
		
		    <div class="col-xs-12 inpage" >
			
			<?php
				$sql = "SELECT * FROM `package` ORDER BY code DESC ";
				$result = $conn->query($sql);

					// output data of each row
					while($row = $result->fetch_assoc()) {
						
						
						
					  echo '<div  data-toggle="modal" data-target="#myModal'.$row['id'].'" class=" ripple chel col'.$row['id'].'" >'.$row['title'].'<hr/><span>'.tofa($row['price']/12).' تومان/ماهانه</span></div>';
					}
				
			?>
				  
				  
				  
		  </div>
		  
		  
	</div>
		  
		  
</div>
<?php }else{  ?>

	<center style="padding: 0 10%;">
	<!--<h1><span style=" font-size: 115px; " > <i class="demo-icon icon-emo-sleep">&#xe80b;</i>  </span></h1>-->
		<img src="surprise.gif" width="50%" />
		<h4> اکانت شما در دستگاه دیگری استفاده شده است </h4>
		<p>شما میتواند با خروج و ورود دوباره با  نام کاربری و رمز عبور خود به اطلاعات دسترسی پیدا کنید</p>
	</center>

 <?php } ?>

</body>
</html>
