<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	require ('classes/config.php');


if(!empty($_POST['submit'])) 
	{
		$submittedref = $_POST["txn_ref"];
		$sql=sprintf("SELECT * FROM epayment_pin WHERE txn_ref='$submittedref'");
		$res=mysql_query($sql) or die("select  fails");
		$no=mysql_num_rows($res);
			if ($no==0) {	
				$sqls=sprintf("SELECT txn_ref from tranzact_t WHERE txn_ref='$submittedref' AND responsecode='00' AND ptype='schfee'");
				$ress=mysql_query($sqls) or die("select  fails");
				$nos=mysql_num_rows($ress);
					if ($nos==0) {
						$msg ='<div class=bg-warning>Sorry! Payment was not Successful / Transaction Error for this Transaction Refrence No: '. $submittedref .'</div>';
					}else{
						echo '<h2> Print Your Online Registration Login Pin</h2>';
							$p1 = (substr(rand(1, 10000000000),0,5));
							$p2 = (substr(rand(1, 10000000000),0,5));
							$p3 = (substr(rand(1, 10000000000),0,5));
							$pf = $p1.$p2;
							$s = "SREG17".$p3;
							$tnx= $submittedref;
                   
				   			$sqln = mysql_query("INSERT INTO epayment_pin(pin,serial_no,txn_ref,status,usedbyid,log_time) 
		   								VALUES('$pf','$s','$tnx','not-used','0','0000-00-00 00:00:00')") or die(mysql_error());
						  // unset($_SESSION['txn_ref']);
						   echo "<h2>TXN: ".$tnx."</h2>";
						   echo "<h2>PIN: ".$pf."</h2>";
						   echo "<h2>S/N: " .$s."</h2>";
                                         exit();
					}
			}else{
				echo '<div class=bg-success>Sorry! Login Pin has been Generated Once for this Transaction Refrence No: '. $submittedref .'</div>';
				while($rows = mysql_fetch_array($res)){
                            $pin= $rows['pin'];
                            $serial= $rows['serial_no'];
							$tra= $rows['txn_ref'];
                        }
				echo '<h2> Print Your Online Registration Login Pin</h2>';
				echo "<h2>TXN: ".$tra."</h2>";
				echo "<h2>PIN: ".$pin."</h2>";
				echo "<h2>S/N: " .$serial."</h2>";
				exit();
			}
		
	}	
?> 
 
 
 <div class="rightp">
            	<h1>Re-Generate Pin</h1>
                <div class="kontent">
            		<form method="post" action="" role="form">  
                    		<em>Please Enter your <strong>Transaction</strong> to check your Transaction back</em>                      	
                        	<div class="form-group input-group">
				       			<input type="text" class="form-control" placeholder="Enter Transaction ID" name="txn_ref" autocomplete="off" required>
                           	<span class="input-group-btn">
                   				<input type="submit" class="btn btn-danger" name="submit" value="Get Transaction" title="Search Student"> 
                       		</span>
                            </div>
                        </form>
                        <?php echo $msg; ?>
                        
                	<hr>
                </div>
            


</div></div><!-- content -->  