<?php
define('IN_PHPMPS', true);
define('PHPMPS_ROOT', str_replace('com/comuser.php', '', str_replace('\\', '/', __FILE__)));
require PHPMPS_ROOT . 'include/common.php';
require PHPMPS_ROOT . 'include/json.class.php';
$act = $_REQUEST['act'] ? trim($_REQUEST['act']) : 'login';

switch($act)
{
	case 'login':
		if(!empty($_userid)) {
			showmsg("你已经登录了", "../member.php");
		}
		$verf = get_one_ver();
		$refer = trim(htmlspecialchars_deep($_SERVER['HTTP_REFERER']));
		$seo['title'] = $CFG[webname]." - 商家管理平台登录";
		$here_arr[] = array('name'=>'商家管理平台登录');
	    $here = get_here($here_arr);
		include template('comlogin');
	break;

	case 'act_login':
		if(!submitcheck('submit')) showmsg('提交错误');
		$keycode = $_POST['comkey'] ? htmlspecialchars_deep(trim($_POST['comkey'])) : '';
		$username = $_POST['username'] ? htmlspecialchars_deep(trim($_POST['username'])) : '';
		$password = $_POST['password'] ? trim($_POST['password']) : '';
		$md5_password = MD5($password);
		$keycode = MD5($keycode);
        $answer    = $_POST['answer'] ? intval($_POST['answer']) : '';
		if(empty($keycode))showmsg("店铺编码不能为空");
		if(empty($username))showmsg("帐号不能为空");
		if(empty($password))showmsg("密码不能为空");
		if($answer!=$_SESSION['milistvip_math'])showmsg("您的验证码输入错误！");
				
		/* 判断是否商户，如果商户则提示 */
        $coms = com_info("userid",$keycode,4);
		if(!empty($coms)){
			$userinfo = member_info($coms['userid']);
			if($userinfo['username']==$username && $userinfo['password']==$md5_password){
			   if(login($username,$md5_password)) {				
			      showmsg("登陆成功", '../member.php');
		       }else{
			      showmsg("登录失败",'comuser.php?act=login');
		       }
			}else{
			   showmsg("登录失败",'comuser.php?act=login');
			}
		}else{
			showmsg('帐号错误，请返回重新输入!');
		}
	break;

}
?>