<?php 
ob_start();
session_start();
include_once("db_connect.php");
if(isset($_SESSION["logged_in"]) && $_SESSION["logged_in"]==true){
	echo '<div class="alert alert-warning" role="alert">You have already loggedin <a href="logout.php">Click here to logout</a></div>';
	exit;
}
$errormsg="";
if (isset($_POST['login'])) {
	$username = mysqli_real_escape_string($conn, $_POST['username']);
    $stud_cate = mysqli_real_escape_string($conn, $_POST['stud_cate']);
	if(empty($username)){
	   $errormsg .= '<div class="alert alert-danger" role="alert">Valid Reference ID is Required.</div>'; 
	} else {
	    $result = mysqli_query($conn, "SELECT * FROM upload_data_ug2 WHERE ref_no = '" . $username. "' and status='" . $stud_cate. "'");
    	if(mysqli_num_rows($result) > 0){
    	    $row = mysqli_fetch_array($result);
    	    $_SESSION['user_id'] = $row['id'];
    	    $_SESSION['ref_no'] = $row['ref_no'];
    		$_SESSION['user_name'] = $row['stud_name'];
    		$_SESSION['logged_in'] = true;
    		header("Location: indexnew.php");
    	} else {
    	    $errormsg .= '<div class="alert alert-danger" role="alert">Invalid Reference ID.Please see on above of printed Document</div>';
    	}
	}
}
include('header.php');
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Har Prasad Das Jain College,	Ara, Bhojpur</title>
<link href="head_foot.css" rel="stylesheet" />
<script type="text/javascript" src="script/ajax.js"></script>
</head>

<header>
    <h2>Har Prasad Das Jain College, Ara, Bhojpur</h2>
</header>

<div class="container">
	<div class="row">
		<div class="col-md-4 col-md-offset-4 well" style="margin-top:30px;">
		    <?php echo $errormsg; ?>
			<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">
				<fieldset>
					<legend>Login</legend>						
					<div class="form-group">
						<label for="name">Registration Number</label>
						<input type="text" name="username" placeholder="20000000000" required class="form-control" />
					</div>	
					<div class="form-group">
						<label for="name">Student Category</label>
						<select name="stud_cate">
						  <option selected="selected" value="">-Select- Student Category</option>
                                        <option value="Regular">Regular</option>
                                         </select>
						
					</div>
					
					<div class="form-group">
						<input type="submit" name="login" value="Login" class="btn btn-primary" />
					</div>
					
				

				</fieldset>
			</form>
		</div>
	</div>
		
</div>


<footer>
 <p></p>
 <p></p>
  <p></p>
   <p></p>
</footer>
<?php include('footer.php');?>