<?php
include("libs.php");
include(dirname(dirname(__FILE__))."/./configs/config.php");
include(dirname(dirname(__FILE__))."/./configs/db_config.php");
include(dirname(dirname(__FILE__))."/./includes/base.php");
header("Content-Type:text/html;charset=GB2312");
date_default_timezone_set('PRC');
$phpcolor = new mysql();
$phpcolor->open();
if(!isset($_GET['action']))
  jump("login.php?action=login");
if($_GET['action']!="quit" and isset($_COOKIE['core_user_name']))
  jump("login.php?action=quit");
if($_GET['action'] == "submit")
{
  $_POST['username']=html_replace($_POST['username']);
  $phpcolor->table="user";
  $phpcolor->field="username,passwd,rank";
  $phpcolor->where="username = '".$_POST['username']."'";
  $userinfo=$phpcolor->exist(1);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  if(empty($_POST['username']) or empty($_POST['passwd']))
  {
	$neirong="登陆失败，未将登陆信息填写完整";
    $phpcolor->logwrite($neirong,$_POST['username'],$time,1);
    jump("../error.php?id=1");
  }
  if(md5($_POST['passwd']) != $userinfo['passwd'] or $userinfo['rank']!=2)
  {
	$neirong="登陆失败，密码错误(".$_POST['passwd'].")";
    $phpcolor->logwrite($neirong,$_POST['username'],$time,1);
    jump("../error.php?id=2");
  }
  if($core_vlogin==1 && $_POST['verify'] != $_SESSION['auth'])
  {
	$neirong="登陆失败，验证码错误";
    $phpcolor->logwrite($neirong,$_POST['username'],$time,1);
    jump("../error.php?id=1");
  }
  setcookie("core_user_name", $_POST['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,$_POST['username'],$time,1);
  $phpcolor->table="user";
  $phpcolor->field="logintime='".$time."', loginip='".$_SERVER['REMOTE_ADDR']."'";
  $phpcolor->where="username = '".$_POST['username']."'";
  $phpcolor->upgrade();
  jump("index.php");
}
if($_GET['action'] == "quit" or isset($_COOKIE['core_user_name']))
{
  setcookie("core_user_name", "", time()-10000000);
  setcookie("core_user_passwd", "", time()-10000000);
  setcookie("core_user_rank", "", time()-10000000);
  setcookie("core_user_long", "", time()-10000000);
  jump("../index.php");
}
$tpl -> assign("core_vlogin", $core_vlogin);
$tpl -> display("login.htm");
?>

