<?php

    include('dbconn.php');


    session_start();
    $msg="";

    $sitetitle = "NKN Academy & Training Provider";
    $year = date("Y");
    $copyrights = "Copyright © ".$year." NKN Academy";
    $version = "Version 1.0.0";

   if($_SERVER["REQUEST_METHOD"] == "POST") {

       if (isset($_POST['btnlogin'])) {
           $loguname = mysqli_real_escape_string($conn,$_POST['username']);
           $logpw = mysqli_real_escape_string($conn,$_POST['password']);
           
           $sql = "SELECT * FROM $tbluseracc WHERE Username = '$loguname' and Password = '$logpw'";
        
           $result = mysqli_query($conn,$sql);
           $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
           
           $count = mysqli_num_rows($result);
           
           if($count === 1) {
                $_SESSION['login_id'] = $row['AutoIndex'];
                $_SESSION['login_user'] = $loguname;
                $_SESSION['login_fullname'] = $row['FullName'];
                $_SESSION['login_usertype'] = $row['UserType'];
            
                $loginfullname = $_SESSION['FullUserName'];
                $loginid = $row['AutoIndex'];
               
                header("location: ./dashboard.php");
              }

            else
              {
                  $msg = "Invalid Login Details!";
              }
       }
   }
?>


<!DOCTYPE html>
<html lang="en" class="h-100">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, shrink-to-fit=9">
		<meta name="description" content="<?php echo $sitetitle ?>">
		<meta name="author" content="<?php echo $sitetitle ?>">
		<title><?php echo $sitetitle ?></title>
		
		<!-- Favicon Icon -->
        <link rel="icon" type="image/png" href="images/nkn-logo-horizontal.png">
		
		<!-- Stylesheets -->
        <?php include 'plugincss.php' ?>

	</head>

<body>				
	<div class="form-wrapper">
		<div class="app-form">
			<div class="app-form-sidebar">
				<div>
                    <center><img src="images/nkn-logo-horizontal.png" width="50%"></center>
                    <br>
                    <center><h3 style="color:#FFFFFF">NKN ACADEMY & TRAINING PROVIDER</h3></center>
				</div>
				<div class="sign_sidebar_text">
					<center><h3 style="color:#FFFFFF">NKN ACADEMY & TRAINING PROVIDER</h3></center>
                    <center><h5 style="color:#FFFFFF">NO 1234 FIRST FLOOR LORONG,</h5></center>
                    <center><h5 style="color:#FFFFFF">KS 1/3 TAMAN KULIM SQUARE,</h5></center>
                    <center><h5 style="color:#FFFFFF">LUNAS,</h5></center>
                    <center><h5 style="color:#FFFFFF">09600 KULIM KEDAH DARUL AMAN,</h5></center>
                    <center><h5 style="color:#FFFFFF">Tel : +6016-487 6512</h5></center>
                    <center><h5 style="color:#FFFFFF">E-Mail : kavinyar98@gmail.com</h5></center>
				</div>
			</div>
			<div class="app-form-content">
				<div class="container">
					<div class="row justify-content-center">
						<div class="col-xl-7 col-lg-6 col-md-7">
							<div class="registration">
                                <center><img src="images/nkn-logo-horizontal.png" alt="logo" width="35%" /></center>
                                    <form class="row g-3 needs-validation"  method="post" action="" novalidate>
									<center><h2 class="registration-title" style="align:center">Login Competition Management System</h2></center>
									<div class="form-group mt-5">
										<label class="form-label">Username</label>
										<input class="form-control h_50" type="username" id ="username" name="username" value="">
									</div>
									<div class="form-group mt-4">
										<div class="field-password">
											<label class="form-label">Password</label>
											<a class="forgot-pass-link" href="forgot_password.php" hidden>Forget Password?</a>
										</div>
										<div class="loc-group position-relative">
											<input class="form-control h_50" type="password" id="password" name="password" value="">
											<span class="pass-show-eye"><i class="fas fa-eye-slash"></i></span>
										</div>
									</div>
									<button class="main-btn btn-hover w-100 mt-4" type="submit" id="btnlogin" name="btnlogin">Login<i class="fas fa-sign-in-alt ms-2"></i></button>
								</form>
								
							</div>							
						</div>
					</div>
				</div>
				<div class="copyright-footer">
					<?php echo $copyrights ?>
				</div>
			</div>			
		</div>
	</div>

</body>
</html>
