<?php
include_once("../global.php");
 
if($_POST['submit'] =='sub') {
	if(trim($_POST['admin_name']) =='' ||  trim($_POST['password']) =='') {
	  die(json_encode(array("code" =>'1', "msg" =>"账号和密码不能为空")) ); 
	   
	}
	if($configs['admin_name'] != $_POST['admin_name'] || $configs['admin_pwd']!= $_POST['password']) {
		 die(json_encode(array("code" =>'1', "msg" =>"账号和密码不正确")) ); 
	}
	 $_SESSION['admin_name'] =$configs['admin_name'];
	 $_SESSION['last_time'] = date("Y-m-d H:i:s");
	 die(json_encode(array("code" =>'0', "msg" =>"成功")) ); 
	 
	
	
}

?>
<!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">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Startmin - Bootstrap Admin Theme</title>

        <!-- Bootstrap Core CSS -->
        <link href="./css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="./css/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="./css/startmin.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="./css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>

        <div class="container">
            <div class="row">
                <div class="col-md-4 col-md-offset-4">
                    <div class="login-panel panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title">请先登陆</h3>
                        </div>
                        <div class="panel-body">
                            <form role="form"  id="form1"  name="form1"   >
                                <fieldset>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="E-mail或管理账号" name="admin_name" id='admin_name'  type="text" autofocus>
                                    </div>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="Password" name="password" id='password' type="password" value="">
                                    </div>
                                     <!-- Change this to a button or input when using this as a form -->
                                    <a href="#" id="login"  class="btn btn-lg btn-success btn-block">Login</a>
                                </fieldset>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- jQuery -->
        <script src="./js/jquery.min.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="./js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="./js/metisMenu.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="./js/startmin.js"></script>
        <script>
		$(function () { 
		  $("#login").click(function () {
			  
			 if($("#admin_name").val() =='' || $("#password").val() =='') {
				 alert('账号和密码不能为空 ');
				 return false;
			 }
			 $.post("login.php", {'admin_name':$("#admin_name").val(),'password':$("#password").val(),'submit':'sub'},
				 function(data){
					 if(data.code=='0') {
						 location.href='index.php';
					 } else{
						 alert(data.msg);
					 }
				 }, "json");
   
   
		  });
		});
		</script>

    </body>
</html>
