<?
/*
* ===========================================*
* 项目: Ourplus网站流量统计分析系统*
* 版本: Bate1*
* 开发: 看海*
* ===========================================*
* Copyright (c) 2004 - 2005*
* 主页: http://stat.ourplus.com*
* 信箱: fantasysisky@hotmail.com*
* 版权信息: 本软体为共享软体(shareware)提供个人网站免费使用，
                作者看海 (stat.ourplus.com) 保留全部权力，受相关法律和国际
				公约保护，请勿非法修改、转载、散播，或用于其他赢利行为，
				并请勿删除版权声明。*
* ===========================================*
*/
	session_start();
	include_once './include.inc/config.inc.php';
	include_once './include.inc/global.inc.php';
	include_once './include.inc/tpl.inc.php';
	include_once './include.inc/function.php';

	if( isset( $_GET[logout] ) )
	{
		unset( $_SESSION[SESSION_MANAGER] );
		unset( $_SESSION[SESSION_USERID] );

		if( $_POST[manager] == '' || $_POST[password] == '' )
		{
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				location='./';
			//-->
			</SCRIPT>
			";
		}
		exit;
	}
	else if( isset( $_POST[manager] ) )
	{
		Initialize( $_POST, array( 'manager'=>'strval', 'password'=>'strval' ) );

		$_POST[manager] = trim( $_POST[manager] );

		if( $_POST[manager] == '' || $_POST[password] == '' )
		{
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				alert( '用户名和密码不能为空!' );
				history.back();
			//-->
			</SCRIPT>
			";
			exit;
		}
		
		include_once './include.inc/conn.db.inc.php';
		$Res = mysql_query( " select id, manager, password from $TableList[users] where manager = '$_POST[manager]' " );
		$Tmp = mysql_fetch_array( $Res, MYSQL_ASSOC );

		if( md5( $_POST[password] ) == $Tmp[password] )
		{
			$_SESSION[SESSION_MANAGER] = $Tmp[manager];
			$_SESSION[SESSION_USERID] = $Tmp[id];
			mysql_query( " update $TableList[users] set logincount = logincount+1, lastlogin = " . time() . " where manager = '$_POST[manager]' " );
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				location='main.php';
			//-->
			</SCRIPT>
			";
			exit;
		}
		else
		{
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				alert( '用户名或者密码错误!' );
				history.back();
			//-->
			</SCRIPT>
			";
			exit;
		}
	}
	else
	{
		$Tpl->assign( 'Main', $Tpl->fetch( 'login.html' ) );

		$Tpl->assign( 'Title', '登录 - Ourplus Counter' );
		$Tpl->assign( 'NowView', '登录' );
		_out( $Tpl->fetch( 'main.html' )  );
	}
?>