<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	session_destroy();
	require ('classes/config.php');
	
	if(isset($_POST['search'])){ 
	   // echo '<h1>Online payment  is closed. Thanks</h1>';
	//	exit();
         if  (substr($_POST[fno],0,1)== 'P'){
           // echo '<h1>Online payment is closed. Thanks</h1>';
	    	//exit();
	    	$sql = mysql_query("SELECT * FROM utme_2017_students_details 
                                       WHERE formno = '$_POST[fno]'
                                       AND status = 'admitted'");
			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'];
				$level0 = $srows['programme'];
				$session = $srows['session']; 
			}
         }elseif (substr($_POST[fno],0,1)== '1'){
            // echo '<h1>Online payment is closed. Thanks</h1>';
	    	//exit();
            $sql = mysql_query("SELECT * FROM course_register WHERE matricno = '$_POST[fno]' AND semester='First' LIMIT 1");
			while($srows = mysql_fetch_array($sql)){
			
				$fno = $srows['matricno'];
				$fullname = $srows['surname']. " " . $srows['othername'] ; 
				$surname= $srows['surname'];
				$othername= $srows['othername'] ;
				$courses = $srows['courses'];
				$email = $srows['email'];
				$phone = $srows['phone'];
				$level0 = $srows['level'];
				$session = '2017/2018';
			}
         }else{	
            // echo '<h1>Online payment is closed. Thanks</h1>';
	    	//exit();
             $sql = mysql_query("SELECT admission_2017_students_details.formno, admission_2017_students_details.surname,
                                       admission_2017_students_details.othernames,admission_2017_students_details.courses,
                                       admission_2017_students_details.email,admission_2017_students_details.phone,
                                       admission_2017_students_details.programme,admission_2017_students_details.session,
                                       admission_status.formno,admission_status.reg_cleared
                                       FROM admission_2017_students_details,admission_status
                                       WHERE admission_2017_students_details.formno = '$_POST[fno]'
                                       AND admission_status.formno = '$_POST[fno]'
                                       AND admission_status.reg_cleared= 'cleared'"); 
            
           /*  $sql = mysql_query("SELECT admission_2016_students_details.formno, admission_2016_students_details.surname,
                                       admission_2016_students_details.othernames,admission_2016_students_details.courses,
                                       admission_2016_students_details.email,admission_2016_students_details.phone,
                                       admission_2016_students_details.programme,admission_2016_students_details.session,
                                       admission_status.formno,admission_status.reg_cleared
                                       FROM admission_2016_students_details,admission_status
                                       WHERE admission_2016_students_details.formno = '$_POST[fno]'
                                       AND admission_status.formno = '$_POST[fno]'
                                       AND admission_status.reg_cleared= 'cleared'");*/
                                       
			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'];
				$level0 = $srows['programme'];
				$session = $srows['session']; 
			}
			  if ($courses=='Accountancy' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if ($courses=='Banking and Finance' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if ($courses=='Business Administration And Management' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='Civil Engineering' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='Estate Management' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='Computer Science' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='(Microbiology (Option)' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='Chemistry (Option)' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  if($courses=='Physics with Electronics (Option)' AND $level0=='HND'){echo '<h1>Online payment is closed. Thanks</h1>'; exit();}
			  
		 }
				if ($courses =='Accountancy'){ $faculty ="Faculty of Management Science" and $facultycode = "01" and $programme = 'Accountancy' and $programmecode = '01' and $departmentcode = '01'; }
				if ($courses =='Banking and Finance'){ $faculty ="Faculty of Management Science" and $facultycode = "01" and $programme = 'Banking and Finance' and $programmecode = '03' and $departmentcode = '03'; }
				if ($courses =='Business Administration And Management'){ $faculty ="Faculty of Management Science" and $facultycode = "01" and $programme = 'Business Administration And Management' and $programmecode = '05' and $departmentcode = '05'; }
				if ($courses =='Civil Engineering'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Civil Engineering' and $programmecode = '06' and $departmentcode = '06'; }
				//if ($courses =='Business Administration And Management'){ $faculty ="Faculty of Management Science" and $facultycode = "01" and $programme = 'Business Administration And Management' and $programmecode = '24' and $departmentcode = '05'; }
				
				if ($courses =='Electrical Electronic Engineering'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Electrical Electronic Engineering(ND)' and $programmecode = '08' and $departmentcode = '08'; }
				if ($courses =='Power/Machine(Option)'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Electrical Electronic Engineering(POWER)' and $programmecode = '22' and $departmentcode = '08'; }
				if ($courses =='Electronic/Telecommunication (Option)'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Electrical Electronic Engineering(TELECOM)' and $programmecode = '21' and $departmentcode = '08'; }
				if ($courses =='Mechanical Engineering'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Mechanical Engineering' and $programmecode = '11' and $departmentcode = '11'; }
				if ($courses =='Mechanical Engineering' and $level0 == 'HND'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Mechanical Engineering(PLANT)' and $programmecode = '18' and $departmentcode = '11'; }
				if ($courses =='Mechanical Engineering' and $level0 == 'HND I'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Mechanical Engineering(PLANT)' and $programmecode = '18' and $departmentcode = '11'; }
				if ($courses =='Mechatronics Engineering'){ $faculty ="Faculty of Engineering" and $facultycode = "02" and $programme = 'Mechatronics Engineering' and $programmecode = '23' and $departmentcode = '23'; }
				
				if ($courses =='Architectural Technology'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Architectural Technology' and $programmecode = '02' and $departmentcode = '02'; }
				if ($courses =='Building Technology'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Building Technology' and $programmecode = '04' and $departmentcode = '04'; }
				if ($courses =='Estate Management'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Estate Management' and $programmecode = '09' and $departmentcode = '09'; }
				if ($courses =='Surveying And Geo-informatics'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Surveying And Geo-informatics' and $programmecode = '14' and $departmentcode = '14'; }
				if ($courses =='Urban And Regional Planning'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Urban And Regional Planning' and $programmecode = '15' and $departmentcode = '15'; }
				if ($courses =='Quantity Surveying'){ $faculty ="Faculty of Environmental Studies" and $facultycode = "03" and $programme = 'Quantity Surveying' and $programmecode = '12' and $departmentcode = '12'; }
				
				if ($courses =='Computer Science'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Computer Science' and $programmecode = '07' and $departmentcode = '07'; }
				if ($courses =='Statistics'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Statistics' and $programmecode = '13' and $departmentcode = '13'; }
				if ($courses =='Science Laboratory Technology'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Science Laboratory Technology' and $programmecode = '19' and $departmentcode = '19'; }
				
				if ($courses =='(Microbiology (Option)'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Microbiology (Option)' and $programmecode = '25' and $departmentcode = '19'; }
				if ($courses =='Chemistry (Option)'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Chemistry (Option)' and $programmecode = '26' and $departmentcode = '19'; }
				if ($courses =='Physics with Electronics (Option)'){ $faculty ="Faculty of Applied Science" and $facultycode = "04" and $programme = 'Physics with Electronics (Option)' and $programmecode = '27' and $departmentcode = '19'; }

				
				
				if (substr($_POST[fno],0,2)=='PU' and $level0 == 'ND') { $level ='NDI' and $levelcode = "01"; }
				if (substr($_POST[fno],0,2)=='DP' and $level0 == 'ND'){ $level ='NDI' and $levelcode = "01"; }
                if (substr($_POST[fno],0,2)=='CA' and $level0 == 'ND'){ $level ='NDI' and $levelcode = "01"; }
				if (substr($_POST[fno],0,2)=='FT' and $level0 == 'HND'){ $level ='HNDI' and $levelcode = "03"; }
				if (substr($_POST[fno],0,2)=='DP' and $level0 == 'HND'){ $level ='HNDI' and $levelcode = "03"; }
                if (substr($_POST[fno],0,2)=='CA' and $level0 == 'HND'){ $level ='HNDI' and $levelcode = "03"; }
                
                if (substr($_POST[fno],0,1)=='1' and $level0 == 'ND I'){ $level ='NDII' and $levelcode = "02"; }
				if (substr($_POST[fno],0,1)=='1' and $level0 == 'HND I'){ $level ='HNDII' and $levelcode = "04"; }


if($faculty == 'Faculty of Environmental Studies' || $faculty == 'Faculty of Applied Science' || $faculty == 'Faculty of Engineering'){$status = 'science';}
if($faculty == 'Faculty of Management Science'){$status = 'non-science';}
				
}elseif(isset($_POST['submit'])){
	
					if(($_POST['total'])=="0" || ($_POST['fullname'])==""){
                    $msg ='<div class=bg-danger>Warning! No record to Process for your transaction</div>';
                    $err = "yes";}
					
				if ($err == ""){
					$surname = $_POST['surname'];
					$othername = $_POST['othername'];
					$faculty = $_POST['faculty']; 
                                        $facultycode = $_POST['facultycode'];
					$fno = $_POST['fno'];
					$level = $_POST['level'];
                                        $levelcode = $_POST['levelcode'];
					$courses = $_POST['courses'];
                                        $departmentcode = $_POST['departmentcode'];
                                        $programme = $_POST['programme'];
                                        $programmecode = $_POST['programmecode'];
					$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.(strtoupper(substr($surname,0,2)));
					$_SESSION['txn_ref']= $txn_ref;
                                        $_SESSION['wayout']= "School Fee";
					$charges = $transfee + $overhead;
					$amount_new = $amount - $charges;
                                        $fname = $surname . " " . $othername;
					
            		$sqls= mysql_query("INSERT INTO tranzact_t (surname,othername,faculty,facultycode,department,departmentcode,programme,programmecode,fno,level,levelcode,phone,email,session,amount,txn_fee,overhead,txn_ref,ptype,status,date_time) 
						VALUES('$surname','$othername','$faculty','$facultycode','$courses','$departmentcode','$programme','$programmecode','$fno','$level','$levelcode','$phone','$email','$session','$amount_new','$transfee','$overhead','$txn_ref','schfee','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());
			
			$check=$_POST['sreg']; 
                        $inputcode=$_POST['code']; 
			$chk="";
			 for ($i=0; $i<sizeof($check);$i++){ 
			  	$chk = $check[$i]; 
                                $cd = implode(',', $inputcode); 
		   	  	$chk_char = preg_replace('/[0-9]/',"", $chk);
				//$chk_code = substr($chk,0,2);
				$chk_desc = substr($chk_char,1);
                                if($chk_desc == 'Tuition Fee'){$fcode = '01';}
                                if($chk_desc == 'ICT'){$fcode = '02';}
                                if($chk_desc == 'Sports Development'){$fcode = '03';}
                                if($chk_desc == 'ID Cards'){$fcode = '04';}
                                if($chk_desc == 'SIWES'){$fcode = '05';}
                                if($chk_desc == 'Matric Fee'){$fcode = '06';}
                                if($chk_desc == 'Practicals_Resource Center Fee'){$fcode = '07';}
                                if($chk_desc == 'Entrepreneurship Fee'){$fcode = '08';}
                                if($chk_desc == 'Handbook_Orientation Fee'){$fcode = '09';}
                                if($chk_desc == 'Coordinator Fee'){$fcode = '10';}
                                if($chk_desc == 'Registration Fee'){$fcode = '11';}
                                if($chk_desc == 'Library'){$fcode = '12';}
                                if($chk_desc == 'Examinations'){$fcode = '13';}
                                if($chk_desc == 'Development Levy'){$fcode = '14';}
			$sqlk = mysql_query("INSERT INTO tranzact_t_items(txn_ref,feecode,fees_description,amount) 
						VALUES ('$txn_ref','$fcode','$chk_desc','$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>Payment Processing</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="off" 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" />
                                        <input class="form-control" placeholder="Faculty Code" name="facultycode" type="hidden" value="<?php echo $facultycode ?>"readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Department" name="courses" type="text" value="<?php echo $courses ?>" readonly="readonly" />
                                        <input class="form-control" placeholder="Department Code" name="departmentcode" type="hidden" value="<?php echo $departmentcode ?>" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Programme" name="programme" type="text" value="<?php echo $programme ?>" readonly="readonly" />
                                        <input class="form-control" placeholder="Programme Code" name="programmecode" type="hidden" value="<?php echo $programmecode?>" readonly="readonly" />
                                        </div>
                                        <div class="form-group">
                                        <input class="form-control" placeholder="Level" name="level" type="text" value="<?php echo $level ?>" readonly="readonly" />
                                        <input class="form-control" placeholder="Level Code" name="levelcode" type="hidden" value="<?php echo $levelcode ?>" 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(master,group) {
		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.getElementById("sreg") = true;
		  }
		}
		document.paymentList.total.value = (sum + parseInt(document.paymentList.transfee.value) + parseInt(document.paymentList.overhead.value)) + ".00";
		var cbarray = document.getElementsByName(group);
    for(var i = 0; i < cbarray.length; i++){
        cbarray[i].checked = master.checked;
		cbarray[i].checked = master.disable = true;

    }
	}
	
</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>
                        <tr>
                           <td colspan="3" bgcolor="#FFFF66"><strong>Click One to select all fee Items</strong></td>
                        </tr>
                    	<?php	
			      $point=0;
			       if (substr($_POST[fno],0,2)=='PU' || substr($_POST[fno],0,2)=='FT')				
					$sql = mysql_query("SELECT DISTINCT code,fees_description, $level FROM payment_setting 
							    WHERE mode='regular' and status='$status' and $level != '0'");
										
				elseif (substr($_POST[fno],0,2)=='DP')
					$sql = mysql_query("SELECT DISTINCT code,fees_description, $level FROM payment_setting 
							    WHERE mode='dpt' and status='$status' and $level != '0'");
							    
				elseif (substr($_POST[fno],0,2)=='CA')							
					$sql = mysql_query("SELECT DISTINCT code,fees_description, $level FROM payment_setting 
							    WHERE mode='pt' and status='$status' and $level != '0'");
				
				elseif (substr($_POST[fno],0,1)=='1' and substr($_POST[fno],2,1)=='1' )							
					$sql = mysql_query("SELECT DISTINCT code,fees_description, $level FROM payment_setting 
							    WHERE mode='regular' and status='$status' and $level != '0'");
				
				elseif (substr($_POST[fno],0,1)=='1' and substr($_POST[fno],2,1)=='2' )							
					$sql = mysql_query("SELECT DISTINCT code,fees_description, $level FROM payment_setting 
							    WHERE mode='dpt' and status='$status' and $level != '0'");
										                          
                        $i=0;

						$cu=0;
                        while($crow=mysql_fetch_array($sql)){
                        $i++;
						$sum= $crow['$level'];
						$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(this,'sreg[]')" 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="300.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=pay_option" class="btn btn-warning">Back</a>
                                        	<?php //if (substr($_POST[fno],0,1)!='1'){ ?>
                                        	<button type="submit" name="submit" class="btn btn-danger">Proceed to Payment</button>
                                        	<?php //} ?>
                                    </form>
                                    <?php } ?>
                                </div>
                
                </div>
            </div>
        </div><!-- content -->    
        
