<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	session_destroy();
	require ('classes/config.php');
	
	if(isset($_POST['search'])){
	 $sql = mysql_query("SELECT admission_status.formno,admission_students_details.surname,admission_students_details.othernames,
						admission_students_details.courses,admission_students_details.email,admission_students_details.phone,
						admission_students_details.session
						FROM admission_status, admission_students_details 
						WHERE admission_status.formno = '$_POST[fno]' 
						AND admission_students_details.formno = '$_POST[fno]'");
			while($srows = mysql_fetch_array($sql)){
			
				$fno = $srows['formno'];
				$fullname = $srows['surname']. " " . $srows['othernames'] ; 
				$surname= $srows['surname'];
				$othername= $srows['othernames'] ;
				$courses = $srows['courses'];
				$email = $srows['email'];
				$phone = $srows['phone'];
				$session = $srows['session'];
			}
				if ($courses =='Accountancy' || $courses =='Banking and Finance' || $courses =='Business Administration And Management'){ $faculty ="Faculty of Management Science"; }
				if ($courses =='Civil Engineering' || $courses =='Electrical Electronic Engineering' || $courses =='Mechanical Engineering' || $courses =='Mechatronics Engineering'){ $faculty ="Faculty of Engineering"; }
				if ($courses =='Architectural Technology' || $courses =='Building Technology' || $courses =='Estate Management' || $courses =='Surveying And Geo-informatics' || $courses =='Urban And Regional Planning' || $courses =='Quantity Surveying'){ $faculty ="Faculty of Environmental Studies"; }
				if ($courses =='Computer Science' || $courses =='Science Laboratory Technology' || $courses =='Statistics'){ $faculty ="Faculty of Applied Science"; }
				
				
				if (substr($_POST[fno],0,2)=='PU' || substr($_POST[fno],0,2)=='DP'){ $level ="NDI"; }
				if (substr($_POST[fno],0,2)=='FT'){ $level ="HNDI"; }
				
}elseif(isset($_POST['submit'])){
	
					if(($_POST['total'])=="" || ($_POST['fullname'])==""){
                    $msg ='<div class=bg-danger>Warning! No record to Process for your transacction</div>';
                    $err = "yes";}
					
				if ($err == ""){
					$surname = $_POST['surname'];
					$othername = $_POST['othername'];
					$faculty = $_POST['faculty']; 
					$fno = $_POST['fno'];
					$level = $_POST['level'];
					$courses = $_POST['courses'];
					$email = $_POST['email'];
					$phone = $_POST['phone'];
					$session = $_POST['session'];
					$amount = $_POST['total'];
					$transfee = $_POST['transfee'];
					$overhead = $_POST['overhead'];
					$a = (substr(rand(1, 10000000000),0,10));
					$txn_ref = $a.(substr($surname,0,2));
					$_SESSION['txn_ref']= $txn_ref;
					$charges = $transfee + $overhead;
					$amount_new = $amount - $charges;
					$fname = $surname . " " . $othername;
					
            		$sqls= mysql_query("INSERT INTO tranzact_t (surname,othername,faculty,department,fno,level,phone,email,session,amount,txn_fee,overhead,txn_ref,status,date_time) 
						VALUES('$surname','$othername','$faculty','$courses','$fno','$level','$phone','$email','$session','$amount_new','$transfee','$overhead','$txn_ref','UNPAID',NOW())") or die(mysql_error());
					
					$sqlw = mysql_query("INSERT INTO webpaylog (txnref,datetime,amount,responsedesc,responsecode,custname,custid) 
						VALUES('$txn_ref',NOW(),'$amount','null','null','$fname','$fno')") or die(mysql_error());
			
			$checkbox1=$_POST['sreg'];  
			$chk="";  
			foreach($checkbox1 as $chk1) {  
			  	$chk = $chk1;  
		   	  	$chk_char = preg_replace('/[0-9]/', "", $chk);
				$chk_type = substr($chk,6,1);
				$chk_unit = substr($chk,7,1);
				$chk_title = substr($chk,8);
			$sqlk = mysql_query("INSERT INTO tranzact_t_items(txn_ref,fees_description,amount) 
						VALUES ('$txn_ref','$chk_char','$chk')")or die(mysql_error());}
			if($sqlk==1){  
			  echo'<script>alert("Successfully Registered")</script>';  
		   	}else{  
			  echo'<script>alert("Failed To Registered")</script>';  
		   	}  		
	
			header("location: index.php?action=confirmation_preview");	
}
}
?>


       		<div class="rightp">
            	<h1>Bank Branch Payment Process</h1>
                <div class="kontent">
                    	<form method="post" action="" role="form">   
                        	<em>Student Appno is either your <strong>Form Number/Matric Number.</strong></em>                     	
                        	<div class="form-group input-group">
				       			<input type="text" class="form-control" placeholder="Enter Form Number/Matric Number "name="fno" autocomplete="on" required>
                           	<span class="input-group-btn">
                   				<input type="submit" class="btn btn-danger" name="search" value="Get Student" title="Search Student"> 
                       		</span>
                            </div>
                        </form>
                	<hr>
				<?php echo $msg; ?>	
                <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <?php if (substr($_POST[fno],0,2)!="" and $fullname != "") {?>
                                    <form method="post" action="" role="form" name="paymentList">
                                    	
                                        <div class="form-group">
                                        <input class="form-control" name="fullname" placeholder="Full Name" type="text" value="<?php echo $fullname ?>"  readonly="readonly" required />
                                        <input name="fno" type="hidden" value="<?php echo $_POST[fno] ?>" size="50" readonly="readonly" />
                                        <input name="surname" type="hidden" value="<?php echo $surname ?>" size="50" readonly="readonly" />
                                        <input name="othername" type="hidden" value="<?php echo $othername ?>" size="50" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Faculty" name="faculty" type="text" value="<?php echo $faculty ?>"readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Department" name="courses" type="text" value="<?php echo $courses ?>" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Level" name="level" type="text" value="<?php echo $level ?>" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Session" name="session" type="text" value="<?php echo $session ?>"  readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Phone" name="phone" type="phone" value="<?php echo $phone ?>"  /> 			
                                        <em style="color:#F00">Please Check or retype correct Phone Number</span></em>
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Email" name="email" type="email" value="<?php echo $email ?>"  />
                                        <em style="color:#F00">Please Check or retype correct Email</span></em>
                                        </div>
                                        

<script type="text/javascript">
	function checkTotal() {
		document.paymentList.total.value = '';
		var sum = 0;
		for (i=0;i<document.paymentList.sreg.length;i++) {
		  if (document.paymentList.sreg[i]) {
		  	sum = sum + parseInt(document.paymentList.sreg[i].value);
		  }
		}
		document.paymentList.total.value = (sum + parseInt(document.paymentList.transfee.value) + parseInt(document.paymentList.overhead.value)) + ".00";
	}
</script>


<table class="table table-bordered" border="0" width="300px">
       					<tr>
                            <th>Fees Description</th>
                            <th align="center">Price (<strike>N</strike>)</th>
                            <th align="center">Check</th>
                     	</tr>
                    	<?php	
						$point=0;
							if (substr($_POST[fno],0,2)=='PU' || substr($_POST[fno],0,2)=='FT')				
								$sql = mysql_query("SELECT fees_description, $level FROM payment_setting 
										WHERE mode='regular'");
										
							elseif (substr($_POST[fno],0,2)=='DP')
								$sql = mysql_query("SELECT fees_description, $level FROM payment_setting 
										WHERE mode='dpt'");
							else							
								$sql = mysql_query("SELECT fees_description, $level FROM payment_setting 
										WHERE mode='dpt'");
										                          
                        $i=0;
						$cu=0;
                        while($crow=mysql_fetch_array($sql)){
                        $i++;
						$fd= $crow['studentid'];
						$cu= $crow['courseunit']+ $cu;
                        $color=($i%2==0)?"lightblue":"white";
                    ?>
                                    <tbody>
                                        <tr >
                                            <td><?php echo $crow['fees_description'];?></td>
                                            <td align="right" width="70px"><?php echo $crow[$level];?></td>
                                            <td width="55px"><input type="checkbox" id="sreg"  onchange="checkTotal()" name="sreg[]" value="<?php echo $crow[$level].$crow['fees_description'];?>" /></td>
                                        </tr>
                                    </tbody>
                          <?php	
							}
							?>
                            <tr>
                                <td colspan="3" bgcolor="#FFFF66"><strong>NOTE:</strong> <em>All dues are to pay at once. Thanks</em></td>
                          	</tr>
                     </table>
                            		<div class="form-group">
                            		<label>Transaction Fee:</label>
                                        <input class="form-control" name="transfee" type="text" value="500.00" readonly="readonly" />
                                        </div>
                                   	<div class="form-group">
                            		<label>Access Charge:</label>
                                        <input class="form-control" name="overhead" type="text" value="700.00" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <label>Total Fee:</label>
                                        <input class="form-control" name="total" type="text" readonly="readonly" />
                                        </div>
                                        	<a href="index.php?action=bank_pay_option" class="btn btn-warning">Back</a>
                                        	<button type="submit" name="submit" class="btn btn-danger">Proceed to Payment</button>
                                    </form>
                                    <?php } ?>
                                </div>
                
                </div>
            </div>
        </div><!-- content -->    