<?php
	session_start();
    if(isset($_POST['submit']))	{
        $name = $_POST['loginid'];	
        $contact = $_POST['passwrd'];
        
        echo 'Hello';	
		$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 "Invalid login id";
				}
				else if($user['dob'] != $pass)
				{
					echo "Invalid password";
				}
				else{
					$_SESSION['app_no'] = $user['app_no'];
					$_SESSION['uid'] = $user['app_no'];
					$_SESSION["lid"] = "1";
                    //header('Location:/law-clerk-preview');
                    header('Location:preview.php');
				}  
			}
		}
		else {
			header('Location: https://mphc.gov.in');
			die(); 
		}
    }
?>
<!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="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css" rel="stylesheet" />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>    
        <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;
            }
            else{         
                $.ajax({
                    type: "POST",
				    url: "candidate-validate.php?i="+uid.value+"&p="+pass.value,
                })
                .done(function (msg) {                    
                    alert(msg);
                    if(msg == "Invalid login id")
                    {
                        alert(msg);
                        uid.focus();
                        return false;
                    }
                    else if(msg == "Invalid password")
                    {
                        alert(msg);
                        pass.focus();
                        return false;
                    }
                    else{
                       alert("OK");
                    }
                });
            }
        }
    </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>
                            <br>
                            <b>ONLINE APPLICATION FORM</b>
                    </div>
                    <div class="section-header" style="text-align: center;">Login For Continue</div>
                    <div class="col-lg-12" style = "border: thin solid #1f537e; margin-top: -5px;">
                    <form  name="class"  method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">    
                        <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 type="button" id = "submit" name = "submit" style = "width:100%" class="btn btn-info"> Login</button>
                            </div>
                        </div>    
                    </form>                     
                    </div> 
                </div>
            </div>
        </header>
    </body>
</html>