<?php
    include ('db.php');
	session_start();
    error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
    if(isset($_POST['submit']))	{
        $id = $_POST['loginid'];	
        $pass = $_POST['passwrd'];
		$sql = "SELECT app_no, DATE_FORMAT(dob,'%d%m%Y') as dob FROM app_details WHERE app_no = '".$id."' and  DATE_FORMAT(dob,'%d%m%Y') = '".$pass."'";		
		$resource =mysqli_query($link, $sql);			
		$count = mysqli_num_rows($resource);
		if($count>0){            
			foreach($resource as $user) { 
				if($user['app_no'] != $id)
				{
                    echo "<script>
                        alert('Invalid login id. Please enter Application/Registration No. in valid format');
                    </script>";
				}
				else if($user['dob'] != $pass)
				{
                    echo "<script>
                        alert('Invalid password');
                    </script>";
				}
				else{
					$_SESSION['app_no'] = $user['app_no'];
					$_SESSION['uid'] = $user['app_no'];
					$_SESSION["lid"] = "1";
                    //header('Location:/law-clerk-preview');
                    header('Location:score-card.php');
				}  
			}
		}
		else {
            echo "<script>
                alert('Invalid login id & password');
            </script>";
		}
    }
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title> High Court Recruitment </title>
        <link id="favicon" rel="shortcut icon" type="image/png" href="images/fevicon.jpg" />
        <link href="css/styles.css" rel="stylesheet" />
        <style>
            .head {
                background-color: #ffffff !important;
                border-bottom: 7px solid #1f537e;
            }
            .logo-name {
                font-size: 32px;
                color: #000;
                font-weight: 600;
                font-family: ui-sans-serif;
            }
        </style>
        
    <script type="text/javascript">
        function fnLogin() {
            var uid = document.getElementById("loginid");
            var pass = document.getElementById("passwrd");
            if (uid.value == '') {
                alert("Please Enter 'Login ID'. ");
                uid.focus();
                return false;
            }
            else if (pass.value == '') {
                alert("Please Enter 'Password'. ");
                pass.focus();
                return false;
            }
            return true;
        }
    </script>
    </head>
    <body>
        <header>
            <div class="container col-lg-4" style="margin-top: 10px; margin-bottom: 10px;">
                <div class="row p-4 bg-light rounded-3">
                    <div class="col-lg-12">
                        <p class="fs-6 text-center">
                            <b>HIGH COURT OF MADHYA PRADESH : JABALPUR</b>
                            <br>
                            <b>LEGAL ASSISTANT/LAW CLERK-CUM-RESEARCH ASSISTANT EXAMINATION-2022-23</b>
                    </div>
                    <div class="section-header" style="text-align: center;">Login for Score Card</div>
                    <div class="col-lg-12" style = "border: thin solid #1f537e; margin-top: -5px;">
                    <form  name="class"  action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">    
                        <div class="form-group row top-pad">
                            <div class="col-sm-2"></div>
                            <div class="col-sm-8 pad-top">
                                <div caption"> Application/Registration No. <span class="error">*</span></div>
                                <input type="text" name="loginid" id="loginid" placeholder="MPLAW00000" class="form-control" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group row top-pad">
                            <div class="col-sm-2"></div>
                            <div class="col-sm-8 pad-top">
                                <div caption"> Password(DOB in DDMMYYYY format) <span class="error">*</span></div>
                                <input type="password" name="passwrd" id="passwrd"  class="form-control" placeholder = "DDMMYYYY" autocomplete="off">
                            </div>
                        </div>   
                        <div class="form-group row top-pad">
                            <div class="col-sm-2"></div>
                            <div class="col-sm-8 pad-top" style = "margin-bottom: 15px;">
                                <button id = "submit" name = "submit" onclick = "return fnLogin()" style = "width:100%" class="btn btn-info"> Login</button>
                            </div>
                        </div>    
                    </form>                     
                    </div> 
                </div>
            </div>
        </header>
    </body>
</html>