<?php 
    include ('../controller/session/session-checker.php'); 
?>

<?php
	
	@$langold = $_GET['lang'];

	if($langold == '' || $langold == NULL || $langold == 'undefined')
	{
		$lang = 'english';
	}
	else{
		$lang = $_GET['lang'];
	}

	include ('../lang/'.$lang.'.php'); 
?>
	

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta name="author" content="EduMESS"/>	
	<meta name="description" content="EduMESS (Education Management and E-Learning Software Solution) is a leading school management, automation and elearning solution. Since its launch, EduMESS has grown to become a leader. Our clients say that the simplicity of our interface, ease of use, cost effectiveness and excellent customer care is the reason they prefare EduMESS. We have watched schools move from softwares they are using to EduMESS."/>
	<meta name="keywords" content="Best, School, Management, Best School, Best School Management, Best School Management Software, Free School Management Software, Portal, School Owner, Group of School Owner, Consultants, Brand Promoters | School Portal Generator ">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
      <!-- SITE TITLE -->
    <title>EduMESS | Sign-in</title>
	<link rel="shortcut icon" href="../assets/images/website_images/favicon.png" type="image/x-icon">
	<link rel="icon" href="../assets/images/website_images/favicon.png" type="image/x-icon">
	<link rel="apple-touch-icon" sizes="152x152" href="../assets/images/website_images/favicon.png">
	<link rel="apple-touch-icon" sizes="120x120" href="../assets/images/website_images/favicon.png">
	<link rel="apple-touch-icon" sizes="76x76" href="../assets/images/website_images/favicon.png">
	<link rel="apple-touch-icon" href="./assets/images/website_images/favicon.png">
	<link rel="icon" href="../assets/images/website_images/favicon.png" type="image/x-icon">

    <link href="../css/website_css/registration.css" rel="stylesheet">	

    <!-- Wnoty Css -->
    <link href="../css/website_css/wnoty/wnoty.css" rel="stylesheet">	

	<link href="../assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">	
    <link rel="stylesheet"  href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 

    <style>
    #carouselHero .carousel-item img {  
        object-fit: cover;
        object-position: center;
        overflow: hidden;
        height: 100vh;
    }

    #carouselHero .carousel-item:before {
        content: "";
        background-image:
            linear-gradient(
            to bottom,
            transparent, rgba(0,0,0,0.5)
            );
        display: block;
        position: absolute;
        top: 0;
        width: 100vw;
        height: 100vh;
    }
    .caption{
        position: relative;
        margin-top:58%;
        margin-left: 5%;
        color:white;
        font-size: 12px;
    }

    .caption-logo{
        position: relative;
        padding-top:10px;
        margin-right:80%;
        color:white;
        width:40%;
    }

    .caption-logo img{
        width:40%;
        margin-right:35%;
    }
    .caption2{
        display:none;
    }

    #submit{
        width: 100%;
    }

    @media only screen and (min-width: 280px) and (max-width:914px) {

        .caption2{
            display:initial;
            font-size: 12px;
            text-align: center;
        }
        .center{
            width:100%;
        }

        #submit{
        width: 100%;
        } 
        .lang{
            width: 100%;
        }
    }
    </style>
 </head>
 <body style="overflow-x: hidden;">
      
    <!-- Loader -->
    <!--<div id="gx-overlay">-->
    <!--	<div class="gx-ellipsis">-->
    <!--		<div></div>-->
    <!--		<div></div>-->
    <!--		<div></div>-->
    <!--		<div></div>-->
    <!--	</div>-->
    <!--</div>-->

        <!--======================== HTML CONTENT===================== -->	
        <section id="wrapper" >
         <div class="row" align="center">

            <!-- Carousel Section col-8 -->
            <div class="col-sm-8 col-md-8 col-lg-8 bg-light" id="carousel-hide">
                <div id="carouselHero" class="carousel slide d-none d-sm-block" data-ride="carousel">
                    <div class="carousel-inner">
                        
                        <?php
                            
                            if($LoginBgImage === '' || $LoginBgImage === 0)
                            {
                                
                            }
                            else
                            {
                                echo '<div class="carousel-item active">
                                        <img src="'.$LoginBgImage.'" class="d-block w-100" alt="Image Description">
                                        
                                    </div>';
                            }
                            
                            if($LoginBgImage2 === '' || $LoginBgImage2 === 0)
                            {
                                
                            }
                            else
                            {
                                echo '<div class="carousel-item">
                                        <img src="'.$LoginBgImage2.'" class="d-block w-100" alt="Image Description">
                                        
                                    </div>';
                            }
                            
                            if($LoginBgImage3 === '' || $LoginBgImage3 === 0)
                            {
                                
                            }
                            else
                            {
                                echo '<div class="carousel-item">
                                        <img src="'.$LoginBgImage3.'" class="d-block w-100" alt="Image Description">
                                        
                                    </div>';
                            }
                        ?>
                        
                        <div class="caption-logo">
                            <img class="img-fluid" src="../assets/images/website_images/edumes-blue.png">
                        </div>
                        <div class="caption">
                            <p class="text-left">Version 2.0<br>Copyright © <?php echo date("Y");?> Powered by <a href="edumess.com"> EDUMESS</a>. All rights reserved.</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End Carousel Section col-8 -->

            <!-- Form Section col-4 -->
            <div class="col-sm-4 col-md-4 col-lg-4 p-5 formy" style="margin-top:-15px;">
                <div class="form-control-sm pull-right">
                        <select class="form-control small" style="font-size:12px;" id="changelanguage">
                        <option value="english" selected>English</option>
                        </select>
                </div>
                <div class="row mt-3">
                    <span align="center"><img class="img-fluid" src="<?php echo $InstitutionLogo;?>" style="width:15%;position:relative;top:10px;"><span><p></p>
                </div>
                <div class="row">
                    <p class="col-sm-12 text-uppercase small" style=""><?php echo $SchoolGeneralName;?></p>
                </div>
                <div class="row mt-2 pull-left">
                    <h4 class="col-4">Login</h4>
                </div>
                <div class="alert">
                </div>
                <div class="center email">
            		<input type="email"  
                    autocomplete="off"
                    class="generalinput"
                    id="email"
                    placeholder="<?php echo $website_signup_email;?>/Username">
        			<i class="fa fa-envelope icon"></i>
                </div>
                <div class="email-error">
                </div>
                <div class="center passwordvalidate password">
                    <input type="password"  
                    autocomplete="off" 
                    class="generalinput" 
                    id="password" 
                    placeholder="<?php echo $website_signup_password;?>">
                    <i class="fa fa-lock icon"></i>
                </div>
                <div class="password-error">
                </div>
                
                    <?php
                        $gos = mysqli_query($link,"SELECT * FROM `institution` WHERE CustomUrl = '$main_url'");
                        $gos_fetch = mysqli_fetch_assoc($gos);
                        $gos_count = mysqli_num_rows($gos);

                         $GroupOfSchoolID = $gos_fetch['InstitutionID'];
                        

                        $campus = mysqli_query($link,"SELECT * FROM `campus` WHERE InstitutionID = '$GroupOfSchoolID' ORDER BY CampusName");
                        $campus_fetch = mysqli_fetch_assoc($campus);
                        $campus_count = mysqli_num_rows($campus);

                        if($campus_count == 1)
                        {
                             $CampusName = $campus_fetch['CampusName'];
                             $CampusID = $campus_fetch['CampusID'];
                            echo '<div class="campus"><input type="text" id="campus" hidden value="'.$CampusID.'"></div>';
                        }
                        else
                        {
                            echo '<select class="center text-center" id="campus">';
                            echo'<option class="medium" value="0" selected>---Select Campus--</option>';

                            do{
                                $CampusName = $campus_fetch['CampusName'];
                                $CampusID = $campus_fetch['CampusID'];
    
                                echo'<option class= "medium" value="'.$CampusID.'">'.$CampusName.'</option>';
    
                            }while($campus_fetch = mysqli_fetch_assoc($campus));

                            echo '</select>';
                        }
                        
                    ?>
                
                <div class="campus-error">
                </div>
                <button type="submit"
                    style="background-color:#007bff; cursor:pointer;"
                    id = "submit" 
                    class="btn btn-block btn-lg text-light center submit"><?php echo $website_login_loginbutton; ?>
                </button>
                <div class="row mt-3 d-flex check">
                    <div class="col-xsm-6 col-sm-6 col-md-6 col-lg-6">
                        <input type="checkbox" style="width:1em;" id="md_checkbox_27" class="filled-in chk-col-light-blue" checked /> 
                        <label for="md_checkbox_26"><?php echo $website_loginremember; ?></label>
                    </div>
                    <div class="col-xsm-6 col-sm-6 col-md-6 col-lg-6">
                        <a style="color:#2e5ca2;font-size:12px;" href="../forget-password?lang=<?php echo $lang; ?>"><?php echo 	$website_login_forgetpassword; ?></a>
                    </div>
                </div>
                <div class="caption2 col-xsm-6 col-sm-6 col-md-6 col-lg-6">
                    <p class="text-left ml-3 mt-1" style="color:black">Version 2.0<br>Copyright © 2023 Powered by EDUMESS. All rights reserved.</p>
                </div>
                <!-- <div class="caption2 d-none d-sm-block">
                    <p class="text-left" style="color:black">Version 2.0 <br>Powered by EDUMESS</p>
                </div> -->
            </div>
            <!-- End Form Section col-4 -->
         </div>    
        </section>
     <!--======================== HTML CONTENT===================== -->	
   
        <!--======================== HTML CONTENT===================== -->	
    
        <!-- EXTERNAL SCRIPTS============================================= -->	
        <script src="../assets/plugins/jquery/jquery.min.js"></script>
        <!-- Bootstrap tether Core JavaScript -->
        <script src="../assets/plugins/bootstrap/js/popper.min.js"></script>
        <script src="../assets/plugins/bootstrap/js/bootstrap.min.js"></script>

		 <!--web ui content -->
		<script src="../js/website_js/registration.js"></script>
         <!--web ui content -->

         <!--owl carousel ui content -->
         <script src="../css/website_css/owl/owl.carousel.min.js"></script>

          <!--Notifier UI -->
          <script src="../css/website_css/wnoty/wnoty.js"></script>

		  <!--registration callback -->
		 <script src="../controller/js/website/registrationcall.js"></script>
		  <!--registration callback -->
        
        <script>
            $('body').on('change', '#changelanguage', function () {

                   
                
                var lang = $(this).val();

                localStorage.setItem('lang', lang);

                location.href = '<?php echo $defaultUrl; ?>?lang=' + lang;
            });

            $(document).ready(function () {
                $('#changelanguage').val('<?php echo $lang; ?>');

            });
	    </script>
        <script>
            $('body').on('click','#submit',function(){

                    var email = $('#email').val();
                    var password = $('#password').val();
                    var campus = $('#campus').val();
                    var institution = <?php echo $GroupOfSchoolID;?>;

                    

                    if(email == '')
                    {
                        $(".email").css("outline", "1px solid red");
                        $(".email-error").html('<p class="small text-danger text-left"> Please Input Email or Username</p>');
                        $(".email").focus();
                    }
                    else
                    {
                        $(".email").css("outline", "1px solid green");
                        $(".email-error").html('');

                        if(password == ''){
                            $(".password").css("outline", "1px solid red");
                            $(".password-error").html('<p class="small text-danger text-left"> Please Input your Password</p>');
                            $(".password").focus();
                        }
                        else{
            
                            $(".email").css("outline", "1px solid green");
                            $(".password").css("outline", "1px solid green"); 
                            $(".password-error").html('');

                            if(campus == '' || campus == '0'){

                                $("#campus").css("outline", "1px solid red");
                                $(".campus-error").html('<p class="small text-danger text-left"> Please Select Campus</p>');
                                $("#campus").focus();
                            }
                            else{

                                $(".campus-error").html('');
                                $(".email").css("outline", "1px solid green");
                                $(".password").css("outline", "1px solid green"); 
                                $("#campus").css("outline", "1px solid green"); 
                                $(".campus-error").html('');

                                $(this).prop("disabled", false);
                                $(this).html('Loading... <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');

                                    $.ajax({           
                                        type : 'POST',
                                        url : '../controller/portal_login/process-login.php', 
                                        data :  {'email':email,'password':password,'campus':campus,'institution':institution}, //Pass $id
                                        success : function(data)
                                        {

                                                $('.submit').html('Verifying... <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                $(this).prop("disabled", true);

                                                if(data == 'teacher'){

                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 3000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });
                                                    setTimeout(function() {
                                                        window.location.href = "../teacher/home";
                                                    }, 3000);
                                                    
                                                    localStorage.setItem('current_username', email);
                                                    
                                                }
                                                else if(data == 'student')
                                                {   
                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 3000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });
                                                    
                                                    setTimeout(function() {
                                                        window.location.href = "../student/home/";
                                                    }, 3000);

                                                    localStorage.setItem('current_username', email);

                                                }else if(data.trim() == 'applicant')
                                                {


                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 3000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });
                                                    
                                                    setTimeout(function() {
                                                        window.location.href = "../apply/candidate/";
                                                    }, 3000);

                                                    localStorage.setItem('current_username', email);

                                                }
                                                else if(data == 'parent')
                                                {
                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 5000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });
            
                                                    setTimeout(function() {
                                                        window.location.href = "../parent/home/"
                                                    }, 3000); 

                                                    localStorage.setItem('current_username', email);
                                                }
                                                else if(data == 'admin')
                                                {

                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 3000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });

                                                    setTimeout(function() {
                                                        window.location.href = "../admin/home/";
                                                    }, 3000); 
                                                    
                                                    localStorage.setItem('current_username', email);
                                                }
                                                else if(data == 'schoolhead')
                                                {
                                                    $(this).prop("disabled", true);
                                                    $('.submit').html('Redirecting...<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>');
                                                    
                                                    $.wnoty({
                                                        type: 'success',
                                                        message: 'Hello, you have Successfuly Logged In',
                                                        autohideDelay: 3000, // 5 seconds
                                                        position:'top-right',
                                                        autohide:false
                                                    });
                                                    

                                                    setTimeout(function() {
                                                        window.location.href = "../school-head/home/";
                                                    }, 3000); 

                                                    localStorage.setItem('current_username', email);
                                                }
                                                else{
                                                    $.wnoty({
                                                        type: 'warning',
                                                        message: data,
                                                        autohideDelay: 2000, // 5 seconds
                                                        position:'top-right'
                                                        // autohide:false
                                                    });
                                                    $('.submit').html("Login", false);
                                                }


                                        // $('.alert').html(data);
                                        }
                                    });
                            }
                            
                        }
                    }
            
            });
        </script>

  </body>
</html>