<?php
  include 'db.php';

  if(isset($_POST["userid"])){

    $user = $db->getRow("select * from users where userid='$_POST[userid]' and password='$_POST[password]' and status=1 ");
      if(count($user)>1){

        $_SESSION["first"] = "yes";
        $_SESSION["admin"]["uid"] = $user["id"];
        $_SESSION["admin"]["name"] = $user["name"];
        $_SESSION["admin"]["role"] = $user["role"];
        $_SESSION["admin"]["school_id"] = $user["school_id"];
        $_SESSION["admin"]["school_name"] = $user["school_name"];

          // redirect("./index.php");
          header( "location:index" );

      } else {
          $_SESSION["msg"] = "Invalid credentials";
      }
  }

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <link rel="stylesheet" href="assets/css/style.css?t=<?php echo time(); ?>">

    <title>Login</title>
</head>
<body class="login-page">
    
    <div class="container-fluid">

        <div class="row">
            <div class="col-md-12 login-top-div">
                <h2>SAVARNA  <span style="color:gold">ATTENDANCE</span> SYSTEM</h2>
            </div>
        </div>
    
    </div>

    <div class="container">

        <div class="row">
            
            <div class="col-md-8 p-5">
                <div class="feature-div">
                    <h3>ATTENDANCE ERP FEATURES</h3>
                    <ul class="listfront1">
                        <li>Student Registration Module</li>
                        <li>Fee Collection module</li>
                        <li>Marksheet Module</li>
                        <li>Examination Module</li>
                        <li>Transfer Certificate Module</li>
                        <li>Student Alert Module</li>
                        <li>Identity Card Module</li>
                        <li>Staff Registration Module</li>
                        <li>Staff Salary Module</li>
                        <li>Attendence Module</li>
                        <li>Account Module</li>
                        <li>Library Module</li>
                    </ul>

                    <ul class="listfront2">
                        <li>Calender Management Module</li>
                        <li>Exam TimeTable Module</li>
                        <li>Class TimeTable Module</li>
                        <li>Transport Module</li>
                        <li>Hostel Module</li>
                        <li>Data Management Module</li>
                        <li>SMS Alert Module</li>
                        <li>Voice Calling Module</li>
                        <li>Report Section Module</li>
                        <li>Schedule &amp; Reminder Module</li>
                        <li>CBSE Exam Pattern Module</li>
                        <li>BirthDay Module</li>
                    </ul>
                </div>
            </div>
            <div class="col-md-4 p-5">
                <form method="post" class="login-form">
                    <h3>Login Form</h3>
                    <div class="form-group mb-4">
                        <label class="mb-2">Userid</label>
                        <input class="form-control" type="text" name="userid" placeholder="Enter User id">
                    </div>

                    <div class="form-group mb-5">
                        <label>Password</label>
                        <input class="form-control" type="password" name="password" placeholder="Enter Password">
                    </div>

                    <?php if($_SESSION["msg"]){ ?>
                    <div id="error" style="color:red;text-align:center;"><?php echo $_SESSION["msg"]; ?></div>
                    <?php unset($_SESSION["msg"]); } ?>

                    <div class="form-group text-center">
                        <input class="btn btn-success text-white btn-lg w-100" type="submit" value="Login" name="login">
                    </div>

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

</body>
</html>