<?php 
require "Run.php";
	if($_GET['backurl']==''||$_GET['backurl']==NULL){
		$backurl="http://".HTTP_HOST."/index.php?cid=".$_GET['cid'];
	}else{
		$backurl = 'http://'.B($_GET['backurl'],'decode');
	}
    if($_GET['action']=='login'){
	$cfgValue -> intoOne(
		array(
			$wapid.'_check' => 'ok'
			)
		);
		if($cfgValue->getValue($wapid.'_check') == 'ok')
		{
			if($_SESSION['check'] != $_POST['check'] || $_SESSION['check'] == NULL)
			{
				ehtml('验证码错误!请重新输入');
				exit();
			}
		}
		$mysql = new D('user');
		$select = $mysql->where(array('name'=>$_POST['name'],'site_u'=>WAPID))->find();
		if($select)
		{
			if(MD5($_POST['pass']) == $select['pass'])
			{
				$_SESSION[MD5(HTTP_HOST)] = $select['sid']."-".$userinfo['ver']."-".$userinfo['css'];
				echo head('登录网站');
				echo topNav('登录成功',"<a href=\"".$backurl."\">返回</a>","<a href=\"http://".HTTP_HOST."/index.php?\">首页</a>");
				$tpl = new dd_Tpl;
				$tpl->tpl_path(root_path . '/DdTpl/comdir');
				$tpl->display('loginok');
				
			}
			else
			{
			echo ehtml("账号或密码错误");
			exit();
			}
		}
		else
		{
			ehtml('用户名写错啦，或者您不是本站的注册用户哦，请您检查一下您的用户名，或者<a href="reg.php?">注册</a>帐号吧');
			exit();
		}
	}else{
		echo head('登录网站');
		if(LOGIN != 1 || $_GET['act'] == 'qh'){	
		$tpl = new dd_Tpl;
		$tpl->tpl_path(root_path . '/DdTpl/comdir');
		$tpl->display('login');
		}else{
			echo '<div class="title">用户登录</div><div class="login"><table ALIGN="center"><tr><td><img src='.$head.' style="height:80px;width:80px;"></td><td>['.$nc.']<br>['.$xid.']</td></tr></table><div class="button"><form method="GET" action="login.php?cid='.$_GET['cid'].'"><input value="qh" name="act" type="hidden"><input value="马上切换" type="submit" ></form></div><a href="waplogout.php?">退出当前帐号</a> <a href="reg.php?">注册新帐号</a></div><div class="mylink"><a href="index.php?">网站首页</a></div>';
		}
	}
echo footer(1);