<?php
session_start();
error_reporting(0);
include('includes/config.php');
if($_SESSION['alogin']!=''){
$_SESSION['alogin']='';
}
if(isset($_POST['login']))
{
	$uname = $_POST['username'];
	$password = $_POST['password'];
	$adminTable = ADMIN_TABLE;

	//$sql ="SELECT UserName, Password FROM admin WHERE UserName=:uname and Password=:password";
	$sql ="SELECT * FROM $adminTable WHERE UserName=:uname";
	$query = $dbh -> prepare($sql);
	$query-> bindParam(':uname', $uname, PDO::PARAM_STR);
	//$query-> bindParam(':password', $password, PDO::PARAM_STR);
	$query-> execute();
	$results = $query->fetchAll(PDO::FETCH_OBJ);
	//print_r($results);
	if($query->rowCount() > 0)
	{
	    if (password_verify($_POST['password'], $results[0]->Password)) { 
    		$_SESSION['alogin'] = $_POST['username'];
    		echo "<script type='text/javascript'> document.location = 'latest.php'; </script>";
    		} else{
    		    
    		    echo "<script>alert('Invalid Details');</script>";
    		}
	    }
	}

?>

<!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">
        <title>Admin Login</title>
        <link rel="stylesheet" href="css/bootstrap.min.css" media="screen" >
        <link rel="stylesheet" href="css/font-awesome.min.css" media="screen" >
        <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen" >
        <link rel="stylesheet" href="css/prism/prism.css" media="screen" > <!-- USED FOR DEMO HELP - YOU CAN REMOVE IT -->
        <link rel="stylesheet" href="css/main.css" media="screen" >
        <script src="js/modernizr/modernizr.min.js"></script>
    </head>
    <body class="">
        <div class="main-wrapper">

            <div class="container  h-100">
                <div class="">
 <h1 align="center">Automatic Weather Station System</h1>

                    <div class="row justify-content-center " >
                        <section class="section center-block">
                                        <div class="col-md-12">
                                            <div class="panel">
                                                <div class="panel-heading">
                                                    <div class="panel-title text-center">
                                                        <h4>Admin Login</h4>
                                                    </div>
                                                </div>
                                                <div class="panel-body p-20">

                                                    <div class="section-title">
                                                        <p class="sub-title">Automatic Weather Station System</p>
                                                    </div>

                                                    <form class="form-horizontal" method="post">
                                                    	<div class="form-group">
                                                    		<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
                                                    		<div class="col-sm-10">
                                                    			<input type="text" name="username" class="form-control" id="inputEmail3" placeholder="UserName">
                                                    		</div>
                                                    	</div>
                                                    	<div class="form-group">
                                                    		<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
                                                    		<div class="col-sm-10">
                                                    			<input type="password" name="password" class="form-control" id="inputPassword3" placeholder="Password">
                                                    		</div>
                                                    	</div>
                                                    
                                                        <div class="form-group mt-20">
                                                    		<div class="col-sm-offset-2 col-sm-10">
                                                           
                                                    			<button type="submit" name="login" class="btn btn-success btn-labeled pull-right">Sign in<span class="btn-label btn-label-right"><i class="fa fa-check"></i></span></button>
                                                    		</div>
                                                    	</div>
                                                    </form>

                                            

                                                 
                                                </div>
                                            </div>
                                            <!-- /.panel -->
                                             <p class="text-muted text-center"><small> Managed By <a style="color:green;" href="https://serraxtechnologies.com">SERRAX TECHNOLOGIES </a></small></p>
                                            <p class="text-muted text-center"><small> For Support mail @ <a style="color:green;" href="mailto:support@serrax.in">support@serrax.in </a></small></p>

                                        </div>
                                        <!-- /.col-md-11 -->
                            <!-- /.row -->
                        </section>

                    </div>
                    <!-- /.col-md-6 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /. -->

        </div>
        <!-- /.main-wrapper -->

        <!-- ========== COMMON JS FILES ========== -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/jquery-ui/jquery-ui.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>

        <!-- ========== PAGE JS FILES ========== -->

        <!-- ========== THEME JS ========== -->
        <script src="js/main.js"></script>
        <script>
            // $(function(){
            //     	$.ajax({
            //           type: "GET",
            //           url: 'fetchFtpRecord.php',
            //           success: function(res)
            //           {
            //                  console.log("succee", res);
                           
            //           },
            //             error: function() {
            //                 console.log("unsuccessful");

            //             }
            //      });

            // });
        </script>

        <!-- ========== ADD custom.js FILE BELOW WITH YOUR CHANGES ========== -->
    </body>
</html>
