<?php 
//ob_start();session_start();
require_once('includes/initialize.php');

date_default_timezone_set('Africa/Lagos');
// if ($session->is_logged_in()) {
//     //redirect_to("dashboard.php");
// }


//If link is clicked from the mail, kindly activate the link and proceed with payment or scratch card page//


$error=array(
1=>'Student data could not be retrieve',
2=>'Admission type not selected !',
3=>'Your password confirmation do not match.',
4=>'Activation link could not be sent, check your internet connection.'

);


$_SESSION['lev']='PGD';

if (isset($_GET['email']) && isset($_GET['token'])){
    

    
    
  $chkActivation='';

   echo  $email=$_SESSION['email']= $_GET['email'];
  echo $token=$_SESSION['token']= $_GET['token'];
  
  
  
  $existingUser='';
    
    $existingUser=StudentAcct::existingAcct($email);
    
    foreach($existingUser as $user){
        
        if (isset($user->acc_id)){
            redirect_to("duplicate.php");
        }
    }
  
  
  
  $updateActivation=StudentAcct::StdupdateAcc($email, $token);

if ($updateActivation){

 $accDetails=StudentAcct::accidbyemail($email, $token); 


  
$_SESSION['stdid']=$accDetails->id;

}
 
}else{
   // redirect_to('index.php');
}



if (isset($_POST['submit'])){
    
    //echo "Gone clicked";
    
    //echo $_POST['p_option'];
  if (!empty($_POST['p_option']) && ($_POST['p_option']=='card') ){

    redirect_to('card-payment.php');
  }else if (!empty($_POST['p_option']) && ($_POST['p_option']=='online')){
      
      
      $stu='';$keyData='';$stdid='';
       $stdid= $_SESSION['stdid'];
       
       if (!isset($_POST['ftype']) || empty($_POST['ftype'])){
           
            $msg = emsg($error[2]);  
       }else {
       
        $_SESSION['online']=$_POST['online'];
                        $ftype= $_POST['ftype'];
                        
                        

            $stu = Online::acc_online($stdid);

            if (isset($stu)){
                $a = (substr(rand(1, 10000000000), 0, 10));
                $txt_ref = strtoupper($a . (substr($stu->surname, 0, 2)));
                $amount=9100;$txt_fee=300;


                $_SESSION['Amt']=$amount; $ftype='';
                      $_SESSION['txn_ref']=$txt_ref;
                      
                        $_SESSION['online']=$_POST['online'];
                        $ftype= $_POST['ftype'];
//echo $stu->id." ".$amount." ".$txt_ref;

// submit_stu_data($id='',$amount='',$txt_fee='',$txt_ref='',$ftype='')
                $keyData = Online::submit_stu_data($stu->id,$amount,$txt_fee, $txt_ref, $ftype);
                
                  redirect_to('online-payment.php');
                
            }else{
            $msg = emsg($error[1]);  
            }

        
             
            }


      
      
      

   
  }else{
    //Do nothing
  }
}

//ob_end_flush();
?>



<?php include_layout_template('headers.php')?>

<style type="text/css">
  
  #ptype{
    display: none;
  }
</style>



<center>
<div class="headers">

<span class="head-styling-left">Admission Portal</span>

<span class="head-styling-right">Preview Page</span>

</div>

</center>
<hr style="border:inset 1px solid">
    
<div class="row">

  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <center>


      <div class="page-container">
      <div class="page-header-text">
        <h2>Select Payment Mode</h2>
        </div>

        <div class="page-content-text" >


<center>


<form method="POST" action="">



<?php if (isset($msg)){?>
        <div class="form-row">
    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <label  style="width: 100%; margin-top: 5px"><?php echo '<center>'.$msg.'</center>'; ?></label>
      
    </div>
  </div>
<?php }?>



  <div class="form-row">
    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      
      <span><strong>Total Amount: </strong><span><strong>N9,100 (Nine thousand one hundred naira only)</strong></span></span>
    </div>

        <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      
      <span><strong>Application Form: </strong><strong>N8,500</strong> </span> 
     <span><strong>&nbsp &nbsp &nbsp &nbsp &nbsp</strong>Transaction Charges: </strong><strong>N600</strong></span>
    </div>


    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <span>Select your preferred payment mode:</span>
    </div>

  </div>


    <div class="form-row">
    
    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <label  style="margin-left: -38%">Payment plan</label>
      <select class="form-control" name="p_option" required="required" id="poption" style="width: 50%">
        <option value="">Choose...</option>
        <?php
        
        if (($_SESSION['lev']=='PGD')){
            
        }else {?>
        <option value="online">Pay Online</option>
        <?php } ?>
        <option value="card">Scratch Card</option>
      </select>
    </div>
   
  </div>



 <div class="form-row" id="ptype">
    
    <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <label style="margin-left: -38%">Admission type</label>
      <select class="form-control" name="ftype" required="required" style="width: 50%">
        <option value="">Choose...</option>
        <?php if ($accDetails->level !='ND'){
        echo '<option value="FT">Full Time</option>';
        }
        ?>
        <option value="DP">Daily Part Time</option>
      </select>
    </div>
   
 
</div>


  <div class="well">
  <input type="submit" class="btn btn-success btn-lg" name="submit" id="submit"  value="Proceed">
</div>
<!-- <li><a href="#" aria-label="Next"></a></li> -->

  
</form>
<?php echo enquiryMsg();?>
</center>
</div>
</div>
</center>
</div>
</div>
</div>




 














 <script src="Jquery/jquery-2.1.3.min.js"></script>

<script src="bootstrap/js/bootstrap.js"></script>
</body>
</html>



  
  <script type="text/javascript">
  

  document.title='Application Portal::View Payment option';
  
  $(document).ready(function(){
  
 
 
 $('#poption').change(function() {
     
     
 var p = $(this).val();

//alert(p);
    
      if (p=='online'){
      $("#ptype").css("display","block"); 
    }else if (p=='card'){
        // $("#ptype").css("display","none"); 
       
       $('#submit').click(function(){
           
           //alert(p);
           window.location.href = "https://admission.oscotechesaoke.edu.ng/card-payment.php";
       });
        
    } 
    })
    
  })
</script>
 
