<?php
session_start();
include '../admin/includes/database.php';
include '../admin/includes/functions.php';
$login= new Functions();

$student_url = $login->student_url();

if(!empty($_POST['regno'])){
    $regno = ($_POST['regno']);

    //perform validations for email
    if(!$login->regnoCheck($regno)){
           echo "<script>
              toastr['error']('Double check your details. We don\'t think your regno is correct.');
        </script>";

    }else{
        // All checks passed, process login
        $status = 'on';
        $sql = "SELECT * FROM student WHERE registerNO =:regno AND status =:on";
        $login->query($sql);
        $login->bind(":regno", $_POST['regno']);
        $login->bind(":on", $status);
        try{
            $result = $login->fetchSingle();
            $username = $result->username;
            $_SESSION['student'] = $username;

         echo "<script>
              toastr['success']('Login Successful. Redirecting to Account Dashboard...');
        </script> <meta http-equiv='refresh' content='3; $student_url'>";

           echo  "<div class='text-center'>
                <div class='spinner-border text-info' role'status'>
                    <span class='sr-only'>Working...</span>
                </div>
                </div>";

        }catch (PDOException $err){

            echo $err =  "<script>
              toastr['error'](' An internal error occurred');
        </script>";

        }

    }
}else{

  echo "<script>
              toastr['error']('Please enter your Reg. No.');
        </script>";
}



