<?php
/*session_start();
session_start();
if(!isset($_SESSION["acountancystudent"])) {	header("Location:index.php");
session_unset(); session_destroy();
header ("location:index.php"); }*/
?>
<?php include "conn_sbcs.php"; 
if (isset($_GET['matricno_rerocess'])) {
    $txnref = uniqid('sbcstx');
	$stdmatricno= $_SESSION['stdmatricno'];
	//// for biodata
	$sql1 = "SELECT * FROM biodata  WHERE  matricno='".$stdmatricno."' ;";
	$result1=$mysqli->query($sql1);
	$student1 = $result1->fetch_array(MYSQLI_ASSOC);
	 
	
	///// for fee
	
	$queryp = "SELECT *FROM stdfee WHERE programmetype = '" . $student1['programme'] . "' AND level = '" . $_POST['level'] . "' AND semester='".$_SESSION['semester']."' AND acyear='".$_SESSION['acyear']."' ";
$resultp=$mysqli->query($queryp);
	$rowp = $resultp->fetch_array(MYSQLI_ASSOC);}
	//echo $rowp['progamount'];
	?>
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript">

                   var message="This function is not allowed here.";
                   function clickIE4(){

                                 if (event.button==2){
                                 alert(message);
                                 return false;
                                 }
                   }

                   function clickNS4(e){
                                 if (document.layers||document.getElementById&&!document.all){
                                                if (e.which==2||e.which==3){
                                                          alert(message);
                                                          return false;
                                                }
                                        }
                   }

                   if (document.layers){
                                 document.captureEvents(Event.MOUSEDOWN);
                                 document.onmousedown=clickNS4;
                   }

                   else if (document.all&&!document.getElementById){
                                 document.onmousedown=clickIE4;
                   }

                   document.oncontextmenu=new Function("alert(message);return false;")

    </script>
<title>TOPS SCHOOLS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='//fonts.googleapis.com/css?family=Pompiere' rel='stylesheet' type='text/css'>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<?php include ('head.php') ?>
<div class="content_bg">
<div class="wrap">
<div class="section group">
  <div class="col span_2_of_3">
<div class="contact-form">
				  	<h3>Certificate of Registration Form  ( S.B.C.S)</h3><br/> Confirmation Platform: 
                    <div>
						     	<span><label> Student's Name: <?= $student1['surname'] ?> <?= $student1['othernames'] ?></label></span></div>
						    <div>
						     	<span><label>Matric Number: <?= $_SESSION['stdmatricno'] ?></label></span></div>
                            <div>
						     	<span><label>Prog/Dep: <?= $student1['programme'] ?>; <?= $student['department'] ?></label></span></div>
                                <div>
						     	<span><label>Semester: <?= $_SESSION['semester'] ?></label></span></div>
                                <div>
						     	<span><label>Session: <?= $_SESSION['acyear'] ?></label></span></div>
                                <div>
						     	<span><form method="post" action=""><select name="level"  id="level" onchange="this.form.submit()">
						     	  <option  value="<?php echo $_POST['level'] ?>"><strong><?php if ($_POST['level']=='') echo 'Pls! Select Your Current Level'; else if ($_POST['level']==$_POST['level']) echo $_POST['level'] ?></strong></option>
						     	  <option>ND1</option>
						     	  <option>ND2</option>
						     	  <option>ND3</option>
						     	  <option>HND1</option>
						     	  <option>HND2</option>
						     	  <option>HND3</option>
						     	  </select></form>
						    </span></div>

<?php

if (isset($_POST['level'])) {

    $mysqli->query("INSERT INTO payments(transaction_no,matric_no,level,semester,acyear) VALUES('" . $txnref . "','".$_SESSION['stdmatricno']."','".$_POST['level']."','".$_SESSION['semester']."','".$_SESSION['acyear']."')");
	$acctno=$rowp['acctno'];
	$acctid=$rowp['acctid'];
    $tamount = ( $rowp['progamount']/*-CONVENIENCE_FEE*/);
    $xml_items = '';

    $topay = $tamount + CONVENIENCE_FEE;

    $cut = (($topay * 1.5) / 100);

    $commission = CONVENIENCE_FEE - $cut;


    $xml_items .= '<item_detail item_id="1" item_name="SBCS-TOPS" item_amt="' . (($tamount-30) * 100) . '" bank_id="' . $acctid . '" acct_num="' . $acctno . '" />';
    $xml_items .= "\n";
    $xml_items .= '<item_detail item_id="2" item_name="SBCS-TOPS-CONVENIENCE FEE" item_amt="' . (($commission+30) * 100 ) . '" bank_id="' . BANK_ID2 . '" acct_num="' . BANK_ACC_NUM2 . '" />';
    $xml_items .= "\n";
    $pamount = $topay * 100;

    $concatenation = $txnref . P_ID . P_I_ID . $pamount . SITE_REDIRECT_URL . MAC_KEY;
    $hash = hash('sha512', $concatenation);
    ?>

    <form name="pay_form" action="<?= WEBPAY_URL ?>" method="post" id="pay_form">
        <input name="product_id" type="hidden" value="<?= P_ID ?>" />
        <input name="amount" type="hidden" value="<?= $pamount ?>" />
        <input name="currency" type="hidden" value="566" />
        <input name="site_redirect_url" type="hidden" value="<?= SITE_REDIRECT_URL ?>" />
        <input name="site_name" type="hidden" value="<?= BASE_PATH ?>" />
        <input name="cust_id" type="hidden" value="<?= $_SESSION['matric_no'] ?>" />
        <input name="cust_id_desc" type="hidden" value="Student" />
        <input name="cust_name" type="hidden" value="<?= $student1['surname'].' '.$student1['othernames'] //$_SESSION['full_name'] ?>" />
        <input name="cust_name_desc" type="hidden" value="Customer Name" />
        <input name="txn_ref" type="hidden" value="<?= $txnref ?>" />
        <input name="txnref" type="hidden" value="<?= $txnref ?>" />
        <input name="pay_item_id" type="hidden" value="<?= P_I_ID ?>" />
        <input name="pay_item_name" type="hidden" value="Name of Fees/Payment" />
        <input name="local_date_time" type="hidden" value="<?= date("d-M-y h:i:s"); ?>" />
        <input name="hash" type="hidden" value="<?= $hash ?>" />
        <input name="payment_params" type="hidden" value="college_split" />
        <input name="xml_data" type="hidden" value='<payment_item_detail>
               <item_details detail_ref="<?= $txnref ?>" college="SBCSTOPS">
               <?= $xml_items ?>
               </item_details>
               </payment_item_detail>'/>				    	  
						   <?php /*?> <div>
						     	<span><label> Student's Name: <?= $student['surname'] ?> <?= $student['othernames'] ?></label></span></div>
						    <div>
						     	<span><label>Matric Number: <?= $_SESSION['stdmatricno'] ?></label></span></div>
                            <div>
						     	<span><label>Prog/Dep: <?= $student['programme'] ?>; <?= $student['department'] ?></label></span></div>
                                <div>
						     	<span><label>Semester: <?= $_SESSION['semester'] ?></label></span></div>
                                <div>
						     	<span><label>Session: <?= $_SESSION['acyear'] ?></label></span></div><?php */?>
						    <div>
						     	<span><label>Transaction : #<?= $txnref ?></label>
						     	</span>
                              <span>
					     	  <label><strong>Level: <?php echo $_POST['level'] ?></strong></label>
					     	  </span></div>
						    <div>
						     	<span><label>Amount: <?= $tamount ?></label></span></div>
		    <div>
						   		
            <span style="font-size:16px; color:#F00"><?php echo $message; ?></span></div>
<button type="submit" class="btn btn-primary btn-lg">Click to Proceed <i class="fa fa-chevron-right"></i></button>

					    </form>
                            <?php
}
?>
				    </div>
  				</div>				
		  </div>
 <div class="clear"></div>
 </div>
</div>
<div class="f_bg">
<div class="wrap">
<div class="footer">
		<div class="f_logo">
			<a href=""><img src="images/logo.png" alt=""></a>
		<div class="copy">
<p class="w3-link">&copy; 2018 School's Tops. All rights reserved | <a href="http://lorattech.com/">.</a></p> 		</div>
 		</div>
		<div class="f_grid">
		<div class="social">
				<ul class="follow_icon">
						<li><a href="#" style="opacity: 1;">Get Updates Via</a></li>
					<li><a href="#" style="opacity: 1;"><img src="images/fb.png" alt=""></a></li>
					<li><a href="#" style="opacity: 1;"><img src="images/g+.png" alt=""></a></li>
					<li><a href="#" style="opacity: 1;"><img src="images/tw.png" alt=""></a></li>
					<li><a href="#" style="opacity: 1;"><img src="images/rss.png" alt=""></a></li>
				</ul>
			</div>
		</div>
	<?php include ('bottom.php') ?>
		<div class="clear"></div>
</div>
</div>
</div>
<script src="vendors/jquery/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="vendors/bootstrap/js/bootstrap.min.js"></script>
<?php
if (isset($_POST['pay'])) {
    ?>
    <script>
        var form = $('#pay_form');
    //form.submit();
    </script>
<?php } ?>  
</body>
</html>