<?php
        include("homeheader.php");

    ?>
	<script type="text/javascript">
 function validate() {
var str=document.form1.amount.value;
       var valid="1234567890.";
	   
	   for(i=0;i<str.length;i++){
	   if(valid.indexOf(str.charAt(i))==-1) {
	   alert("Error Entering Amount To Topup!");
	   document.form1.amount.value=="";
	   document.form1.amount.focus();
	   return false;
	   }
	   }
	   if(document.form1.amount.value=="") {
		   alert("Amount to Topup not Entered! Please try again.");
		   document.form1.amount.value=="";
	       document.form1.amount.focus();
		   return false;
		   
	   }
   }
</script>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title">
			     <div class="profile_pic" style="margin-top:-10px;">
			  <img src="../images/mlogo.png" alt="" class="img-circle profile_img" />
			    </div>
			  <!--i class="fa fa-paw"></i--> <span>Instant Airtime </span></a>
            </div>

            <div class="clearfix"></div>

			
            <!-- menu profile quick info -->
            <div class="profile">
              <div class="profile_pic">
			      <?php 
			  if($img == ""){
				  ?>
				   <img src="../profileimages/noimage.gif" alt="..." class="img-circle profile_img">
				  <?php
			  }else{
				?>
				 <img src="<?php echo $photo ?>" alt="..." class="img-circle profile_img" width="40px;" height="60px;">
            <?php				
			  }
			  ?>
              
              </div>
             <div class="profile_info">

                <span>Welcome,</span>
				<h2> <?php $fname = $dat['fname']; $lname = $dat['lname']; echo $fname." ".$lname ?> </h2>
             <!--   <h2>John Doe</h2> -->
              </div>
            </div>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
			  <br/>
                <h3>General</h3>
               
				 <ul class="nav side-menu">
                  <li ><a  href="adminpage.php" ><i class="fa fa-home"></i>  Home <span class="fa fa-chevron-right"></span></a> </li>
                  <li><a href="#">  Users <span class="fa fa-chevron-down"></span></a> 
				  <ul class="nav child_menu">
					    <li><a  href="adduser.php" ><i class="fa fa-bug"></i>Create User<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="viewuser.php" ><i class="fa fa-edit"></i>View Users<span class="fa fa-chevron-down"></span></a> </li>
					   </ul>
				  </li>
                  <li><a href="contacts.php">  View Contacts <span class="fa fa-chevron-right"></span> </a> </li>
                  <li><a href="groups.php"> View Groups  <span class="fa fa-chevron-right"></span> </a>   </li>
                  <li><a href="requests.php">Topup Requests  <span class="fa fa-chevron-right"></span> </a>   </li>
				  <li class="active"><a href="#">Topup My account <span class="fa fa-chevron-right"></span> </a>   </li>
				   <li><a> Reports <span class="fa fa-chevron-down"></span></a>  
				     
					   <ul class="nav child_menu">
					    <li><a  href="buyinghistory.php" > Purchase History <span class="fa fa-chevron-right"></span> </a> </li>
						<li><a  href="sendinghistory.php" > Sending History <span class="fa fa-chevron-right"></span> </a></li>
					   </ul>
				   </li>
                </ul>
				
              </div>

            </div>
			 </div>
        </div>
		
		<?php
        include("topmenubar.php");

         ?>
		 
		 
		 <!-- page content -->
        <div class="right_col" role="main">
		  <!-- /top navigation -->
		    <div class="row">
          <!-- top tiles -->
				<div class="row tile_count">
					<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
						<p>Airtime Portal </p>
					</div>
            
				</div>
			</div>
          <!-- /top tiles -->
		 
					<div class="x_title">
						<h2> Request Account Topup from Mobisky Innovations Ltd.  </h2>
							<div class="clearfix"></div>
					</div>
					 <div class="row" >
					<div class="x_content">

                    <form name="form1" class="form-horizontal form-label-left" method="post" action="" onsubmit="return validate()"  >

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Amount To Topup <span class="required" style="color:red;"><b>*</b></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="amount" class="form-control col-md-7 col-xs-12" data-validate-length-range="6" data-validate-words="2" name="amount" placeholder="Ksh." required="required" type="text">
                        </div>
                      </div>
                    
                        <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button type="reset" class="btn btn-primary">Cancel</button>
                          <input type="submit" name="submit"  class="btn btn-success" value="Send Request" />
                        </div>
                      </div>
					  
					  <?php
					   $frm = $dat['company']; 
					  if(isset($_POST['submit'])){
						   $amnt = $_POST['amount'];
						   $dte = date("Y-m-d");
						   
						   $s=mysql_query("select * from airtime_accounts where account_id='$session_id' and status='Pending'   ") or die(mysql_error());
						   $nmrw = mysql_num_rows($s);
						   if($nmrw > 0){
							   
							     echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-success"><i class="icon-hand-right"></i>Error Sending Request! You have a pending topup request.  </button>
                                    </div>';
						   }else{
							     $qry = mysql_query("insert into airtime_accounts values('','$session_id','$amnt',now(), '', '', 'Pending') ") or die(mysql_error());
						   
						   if($qry){
							    $qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
									$sdata=mysql_fetch_array($qry2);
												
									$actions = $sdata['user_actions'];
									mysql_query("update airtime_logs set user_actions='$actions Sent a topup request of Ksh. $amnt.' where id='$session_lid'  ");
							    echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-success"><i class="icon-hand-right"></i>Request sent Successfully! Thankyou. </button>
										
                                       
                                    </div>';
							   
						   }else{
							    echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-success"><i class="icon-hand-right"></i>Error Sending Request! Please Try Again! </button>
										
                                       
                                    </div>';
							   
						   }
							   
						   }
						    
					  }
					  
					  ?>
					  
                    </form>
					
                  </div>
		 </div>
				  <br/>
				
				 <div class="row" >
				   <div class="col-md-12 col-sm-12 col-xs-12">
					<div class="x_panel">
				   <h2> Previous Account Topup Requests from Mobisky </h2>
				      <div class="x_content">
				    <table id="datatable" class="table table-striped table-bordered">
                      <thead>
                        <tr>
						  <th>Amount Requested</th>
						  <th>Date Requested</th>
						  <th>Amount Awarded</th>
						  <th>Date Awarded</th>
                          <th>Status</th>
                        </tr>
                      </thead>
                      <tbody>
                      <?php
					  $frm  = $dat['company'];
					  $us = mysql_query("select * from airtime_accounts where account_id='$session_id'  ");
					   while($rws = mysql_fetch_assoc($us)){
							    $id=  $rws['id']; 
						         $amnt=  $rws['amount_requested'];
						         $sts=  $rws['status'];
						         $rdte=  $rws['date_requested'];
								  
								    echo "<tr>";
									echo '<td>' ."Ksh. ". $amnt . '</td>';
									echo '<td>' . $rdte . '</td>';
									echo '<td>' ."Ksh. ".$rws['amount_awarded'].'</td>';
									echo '<td>' .$rws['date_awarded'].'</td>';
									echo '<td>' .  $sts . '</td>';
						   }
						   
							  
                       echo "</tr>";
					  
					  ?>  
                       
                      </tbody>
                    </table>
				 </div> 
				 </div> 
			</div> 
		</div>  
				  
				  
                
		</div>
			    
		  
		          <!-- /page content. End of main -->

     <?php include("footerlinks.php"); ?>
	 
	  <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="./vendors/nprogress/nprogress.js"></script>
    <!-- Chart.js -->
    <script src="../vendors/Chart.js/dist/Chart.min.js"></script>
    <!-- gauge.js -->
    <script src="../vendors/bernii/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="../vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="../vendors/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="../vendors/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="../vendors/Flot/jquery.flot.js"></script>
    <script src="../vendors/Flot/jquery.flot.pie.js"></script>
    <script src="../vendors/Flot/jquery.flot.time.js"></script>
    <script src="../vendors/Flot/jquery.flot.stack.js"></script>
    <script src="../vendors/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="../js/flot/jquery.flot.orderBars.js"></script>
    <script src="../js/flot/date.js"></script>
    <script src="../js/flot/jquery.flot.spline.js"></script>
    <script src="../js/flot/curvedLines.js"></script>
    <!-- jVectorMap -->
    <script src="../js/maps/jquery-jvectormap-2.0.3.min.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="../js/moment/moment.min.js"></script>
    <script src="../js/datepicker/daterangepicker.js"></script>

		   <!-- Datatables -->
    <script src="../vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="../vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="../vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="../vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="../vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="../vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="../vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="../vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="../vendors/jszip/dist/jszip.min.js"></script>
    <script src="../vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="../vendors/pdfmake/build/vfs_fonts.js"></script>
	
	    <script src="../vendors/select2/dist/js/select2.full.min.js"></script>

  

    <!-- Datatables -->
	 <script>
      $(document).ready(function() {
        var handleDataTableButtons = function() {
          if ($("#datatable-buttons").length) {
            $("#datatable-buttons").DataTable({
              dom: "Bfrtip",
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
          }
        };

        TableManageButtons = function() {
          "use strict";
          return {
            init: function() {
              handleDataTableButtons();
            }
          };
        }();

        $('#datatable').dataTable();
        $('#datatable-keytable').DataTable({
          keys: true
        });

        $('#datatable-responsive').DataTable();

        $('#datatable-scroller').DataTable({
          ajax: "js/datatables/json/scroller-demo.json",
          deferRender: true,
          scrollY: 380,
          scrollCollapse: true,
          scroller: true
        });

        var table = $('#datatable-fixed-header').DataTable({
          fixedHeader: true
        });

        TableManageButtons.init();
      });
    </script>	
	
    <!-- Select2 -->
    <script>
      $(document).ready(function() {
        $(".select2_single").select2({
          placeholder: "Select a state",
          allowClear: true
        });
        $(".select2_group").select2({});
        $(".select2_multiple").select2({
       placeholder: "Chose Contacts to topup",
          allowClear: true
        });
      });
    </script>
    <!-- /Select2 -->	
		  
   
		  