<?php 
ob_start();
session_start();
if($_SESSION['userid']=="")
{
	header("location:index.php?msg1=notauthorized");
	exit();
}
	
include ("include/connection.php");

if(isset($_POST['submit'])=='Submit'){
	$mobile=($_POST['mobile']);
	$amount=($_POST['amount']);
	
	$sql12 = mysqli_query($con,"select * from tbl_user where mobile='$mobile'");
	$numrow = mysqli_num_rows($sql12);
	if($numrow != '0')
	{
	$numrow = mysqli_fetch_array($sql12);
	$userid = $numrow['id'];
	
$sql= "INSERT INTO `manual_recharge`(`userid`,`mobile`,`amount`) VALUES ('".$userid."','".$mobile."','".$amount."')";
$query=mysqli_query($con,$sql);


$today = date("Y-m-d H:i:s");
$sql3= mysqli_query($con,"INSERT INTO `tbl_walletsummery`(`userid`,`orderid`,`amount`,`type`,`actiontype`,`createdate`) VALUES ('".$userid."','".$orderid."','".$amount."','credit','manualrecharge','".$today."')");


$walletAvailablebalance=wallet($con,'amount',$userid);	
$finalbalanceCredit=$walletAvailablebalance+$amount;	
$sqlwallet= mysqli_query($con,"UPDATE `tbl_wallet` SET `amount` = '$finalbalanceCredit' WHERE `userid`= '$userid'");

echo ("<script LANGUAGE='JavaScript'>window.alert('Succesfully Updated');window.location.href='manual_recharge.php';</script>");
}else{
 echo ("<script LANGUAGE='JavaScript'>window.alert('Mobile Number Not Found');window.location.href='manual_recharge.php';</script>");   
}
	}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Adminsuit | Manual Recharge System</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
  <link rel="stylesheet" href="plugins/morris/morris.css">
  <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
  <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
  <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
<link rel="stylesheet" href="plugins/select2/select2.min.css">
<link rel="stylesheet" href="plugins/iCheck/all.css">
<link rel="stylesheet" type="text/css" href="css/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script src="plugins/jQuery/jQuery-2.2.0.min.js"></script>

  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <link rel="stylesheet" href="css/style.css">
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
<?php include ("include/header.inc.php");?>
 <?php include ("include/navigation.inc.php");?> 
  <div class="content-wrapper">
    <section class="content-header">
      <h1>Manual Recharge</h1>
      <ol class="breadcrumb">
        <li><a href="desktop.php"><i class="fa fa-dashboard"></i>Home</a></li>
        <li class="active">Manual Recharge</li>
      </ol>
    </section>

                        
    <!-- Main content -->
    <section class="content">
      <div class="row">
      <div class="col-xs-12 text-center">
          
          <?php if(isset($_GET['msg'])=="updt"){ ?>
              <span class="text-center red_txt">Update Successfully......</span><?php  } ?></div>
        <div class="col-xs-12">
          <div class="box">
          
      <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">
            <div class="box-body">
<div class="clearfix"></div>

<div class="col-sm-6">
              <div class="form-group">
              <label>Enter Mobile Number <i class="red_txt">*</i></label>
    <input type="text" class="form-control"  name="mobile" id="mobile" max="10" required>
              </div>
              </div>
  <div class="col-sm-6">
              <div class="form-group">
              <label>Amount</label>
              <input type="text" class="form-control"  name="amount" id="amount" required>
              </div>
              </div>          
                
             <div class="clearfix"></div>   
              <div class="form-group">
              <div class="text-center">
  
 <input type="submit" class="btn btn-primary" value="Submit"  name="submit" ></div>
                </div> 
               </div>
                
             
 

          </form>
          <br><br><br><br>
          <div class="row">
        <div class="col-md-12 text-center">
      <h4> Recharge List</h4>
      <br><br>
          <table id="example1" class="table table-bordered table-striped text-center" >
    <tr>
        <th>Mobile</th>
        <th>Amount</th>
        <th>Date</th>
    </tr>
<?php
$sql=mysqli_query($con,"select * from `manual_recharge`");
while($row=mysqli_fetch_array($sql))
{
$id=$row['id'];
?>
<tr>
    <td><?php echo $row['mobile']; ?></td>
    <td><?php echo $row['amount']; ?></td>
    <td><?php echo @date('d-m-Y', strtotime($row['created_at']));?></td>
    </tr>
<?php }?>
</table>
          </div></div>
          
  <br>    <br>   <br>   <br>       
  
 <script>

  $(function () {
    $('#example1').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": true,
      "ordering": false,
      "info": true,
      "autoWidth": true,
	  "pageLength": 100
    });
  });
</script>       
          </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
<?php include("include/footer.inc.php"); ?></div>


</body>
</html>
