<?php
    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
    require_once(dirname(__FILE__) . '/../../global.php');
    require_once "handle/service/AdminService.php";
    require_once "handle/util/AMSUtil.php";

    $adminService = new AdminService();

    $action = AMSUtil::get_http_parameter("action");
    $dialog = AMSUtil::get_http_parameter("dialog");
    
    if($action == "login")
    {
        $uname = AMSUtil::get_http_parameter("uname");
        $pwd = AMSUtil::get_http_parameter("pwd");

        $check_login = $adminService->check_admin($uname, $pwd);
		

        if ($check_login)
        {
            session_start();
            $_SESSION["admin"] = $uname;
            echo "<script>window.location.href = '/admin.html'</script>";
            return ;
        }
        else
        {
            echo "<script>window.location.href = '/error.php?mesg=用户名或密码不正确,登录失败!'</script>";
            return ;
        }
    }
    else if($action == "modify_pwd")
    {
        $uname = AMSUtil::get_http_parameter("uname");
        $pwd = AMSUtil::get_http_parameter("pwd");
        $new_pwd = AMSUtil::get_http_parameter("new_pwd");

        $flag = $adminService->modify_pwd($uname,$pwd,$new_pwd);
        if ($flag)
        {
            echo "<script>alert('修改密码成功!');window.location.href = '/admin_info.html'</script>";
            return ;
        }
        else
        {
            echo "<script>window.location.href = '/error.php?mesg=修改密码失败,请核实原用户名和密码是否正确!'</script>";
            return ;
        }

    }