<?
/*
* ===========================================*
* 项目: 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 'session.php';

	include_once './include.inc/conn.db.inc.php';
	include_once './include.inc/global.inc.php';
	include_once './include.inc/tpl.inc.php';
	include_once './include.inc/function.php';

	Initialize( $_POST, array( 'oldpassword'=>'strval', 'action'=>'strval', 'manager'=>'strval', 'password'=>'strval', 'repassword'=>'strval', 'sitename'=>'strval', 'site'=>'strval', 'sitetype'=>'strval', 'sitedes'=>'strval', 'email'=>'strval', 'qq'=>'strval', 'msn'=>'strval', 'register'=>'strval' ) );

	if( $_POST[action] == 'save' )
	{
		$Res = mysql_query( " select manager, password from $TableList[users] " );
		$Tmp = mysql_fetch_array( $Res, MYSQL_ASSOC );

		if( $_POST[oldpassword] == $Tmp[password] || md5( $_POST[oldpassword] ) == $Tmp[password] )
		{
		}
		else
		{
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				alert( '您输入的原密码不正确!' );
				history.back();
			//-->
			</SCRIPT>
			";
			exit;
		}

		if( $_POST[sitename] == '' )
		{
			$Error = true;
			$ErrMsg .= "站点名字不能为空\\n";
		}

		if( $_POST[site] == '' )
		{
			$Error = true;
			$ErrMsg .= "站点网址不能为空\\n";
		}

		if( $_POST[email] == '' )
		{
			$Error = true;
			$ErrMsg .= "Email地址不能为空\\n";
		}

		if( $Error )
		{
			echo "<SCRIPT LANGUAGE=\"JavaScript\">
			<!--
				alert( '您填写的信息出现以下错误      \\n========================\\n$ErrMsg' );
				history.back();
			//-->
			</SCRIPT>";
			exit;
		}


		$UpdateStr = " site = '$_POST[site]', sitename = '$_POST[sitename]', sitedes = '$_POST[sitedes]', sitetype = '$_POST[sitetype]', email = '$_POST[email]', qq = '$_POST[qq]', msn = '$_POST[msn]'";

		if( $_POST[password] != '' && $_POST[password] == $_POST[repassword] )
		{
			$UpdateStr .= " , password = '" . md5( $_POST[password] ) . "'";
		}

		$Sql = " update $TableList[users] set " . $UpdateStr . " ";
		mysql_query( $Sql );
		echo "<SCRIPT LANGUAGE=\"JavaScript\">
		<!--
			location='main.php';
		//-->
		</SCRIPT>";
		exit;
	}

	$Res = mysql_query( " select * from $TableList[users] " );
	$UserData = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'UserData', $UserData );

	$Tpl->assign( 'Main', $Tpl->fetch( 'profile.html' ) );

	$Tpl->assign( 'Title', '修改资料 - Ourplus Counter' );
	$Tpl->assign( 'NowView', '修改资料' );
	$Tpl->assign( 'QuickLink', "<a href=\"main.php\">返回</a>" );

	_out( $Tpl->fetch( 'main.html' )  );
?>