<?php
include(dirname(__FILE__)."/./includes/libs.php");
include(dirname(__FILE__)."/./configs/config.php");
include(dirname(__FILE__)."/./configs/db_config.php");
include(dirname(__FILE__)."/./includes/base.php");
header("Content-Type:text/html;charset=GB2312");
date_default_timezone_set('PRC');
$phpcolor = new mysql();
$phpcolor->open();
if($_GET['action']=="login")
{
  $_POST['username']=html_replace($_POST['username']);
  $phpcolor->table="user";
  $phpcolor->field="username,passwd,rank";
  $phpcolor->where="username = '".$_POST['username']."' and state != '0' and state != '3' and rank = '2'";
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  if($_POST['username']=="" || $_POST['passwd']=="")
    jump("close.php");
  if(!$userinfo=$phpcolor->exist(1))
    jump("close.php");
  if(md5($_POST['passwd']) != $userinfo['passwd'])
  {
	$neirong="登陆失败：密码错误(".$_POST['passwd'].")";
    $phpcolor->logwrite($neirong,$userinfo['username'],$time,1);
    jump("close.php");
  }
  $cookieurl=str_replace("http://www.","",$core_url);
  $cookieurl=str_replace("/","",$cookieurl);
  setcookie("core_user_name", $userinfo['username'], time()+$core_time*3600+3600,"/",$cookieurl);
  setcookie("core_user_passwd", md5($userinfo['passwd'].$core_scode), time()+$core_time*3600+3600,"/",$cookieurl);
  setcookie("core_user_rank", $userinfo['rank'], time()+$core_time*3600+3600,"/",$cookieurl);
  setcookie("core_user_long", "0", time()+$core_time*3600+3600,"/",$cookieurl);
  setcookie("core_user_name", $userinfo['username'], time()+$core_time*3600+3600);
  setcookie("core_user_passwd", md5($userinfo['passwd'].$core_scode), time()+$core_time*3600+3600);
  setcookie("core_user_rank", $userinfo['rank'], time()+$core_time*3600+3600);
  setcookie("core_user_long", "0", time()+$core_time*3600+3600);
  $neirong="登陆成功，在前台登陆";
  $phpcolor->logwrite($neirong,$userinfo["username"],$time,1);
  $phpcolor->field="logintime='".$time."', loginip='".$_SERVER['REMOTE_ADDR']."'";
  $phpcolor->where="username = '".$userinfo['username']."'";
  $phpcolor->upgrade();
  jump("index.php");
}
$core_closes=$core_bartype;
if($_GET['action']=="shop")
{
  $core_closed="商城关闭中，请返回首页。";
  $core_closes="商城";
}
$tpl -> assign("core_barname", $core_barname);
$tpl -> assign("core_closed", $core_closed);
$tpl -> assign("core_closes", $core_closes);
$tpl -> display("$core_style/close.htm");
?>