<?php
/**
* FILE_NAME : user.php
*
* @copyright Copyright (c) 2012-2013 www.shuangyulin.com
* @author 双鱼林 Design
* @package 用户管理
* @subpackage
* @version QQ:287307421或254540457
*/

define('IN_WEB', TRUE);
	
require_once( str_replace('\\', '/', dirname(__FILE__)). '/include/global.php');

/* act操作项的初始化 */
if (empty($_REQUEST['act'])) {
    $_REQUEST['act'] = 'show';
} else {
    $_REQUEST['act'] = trim($_REQUEST['act']);
}

/*------------------------------------------------------ */
//-- 用户列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'show')
{
	$sql = $query = $userlist = '';
	
	$sql = "SELECT * FROM {$dbprefix}members";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query))
	{
		$row['regtime'] = formatdate($_CFG['format_type'],$row['regtime']);
		$row['lastlogin'] = formatdate($_CFG['format_type'],$row['lastlogin']);
		$userlist[] = $row;
	}
//	print_r($singlist);
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("userlist", $userlist);
	
	$smarty->display("user.html");
}

/*------------------------------------------------------ */
//-- 增加用户
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->display("user_add.html");
}

/*------------------------------------------------------ */
//-- 增加用户成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'addok')
{
	$user = $_REQUEST['user'];
	$sql = $query = '';
	
	/*--  插入信息  --*/
	$sql = "INSERT INTO {$dbprefix}members (uid,username,password,regtime,lastlogin,email)
			VALUE ('','".$user['username']."','".$user['password']."','".$timestamp."','".$timestamp."','".$user['email']."')";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("用户添加成功","user.php?act=show");
	} else {
		showmsg("用户添加失败","user.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 编辑用户信息
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
	$uid = $_REQUEST['uid'];
	
	$sql = $query = $row = '';
	
	/*--  查询信息  --*/
	$sql = "SELECT * FROM {$dbprefix}members WHERE uid = $uid";
	$query = $DB->query($sql);
	$list = $DB->fetch_array($query);
	
//	print_r($list);
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("uid",$list['uid']);
	
	$smarty->display("user_edit.html");
}

/*------------------------------------------------------ */
//-- 编辑用户成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'editok')
{
	$user = $_REQUEST['user'];
	$sql = $query = '';
	
	/*--  修改信息  --*/
	if ($user['username'] != '') {
		$sql = "UPDATE {$dbprefix}members SET username = '".$user['username']."' WHERE uid = '".$user['uid']."'";
		$query = $DB->query($sql);
		
		if (!$query) {
			showmsg("用户名修改失败");
		}
	}
	
	if ($user['password'] != '') {
		$sql = "UPDATE {$dbprefix}members SET password = '".$user['password']."' WHERE uid = '".$user['uid']."'";
		$query = $DB->query($sql);
		
		if (!$query) {
			showmsg("用户密码修改失败");
		}
	}
	
	if ($user['email'] != '') {
		$sql = "UPDATE {$dbprefix}members SET email = '".$user['email']."' WHERE uid = '".$user['uid']."'";
		$query = $DB->query($sql);
		
		if (!$query) {
			showmsg("用户Email修改失败");
		}
	}
	
	showmsg("用户信息没有被修改","user.php?act=show");
}

/*------------------------------------------------------ */
//-- 删除用户
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove')
{
	$uid = $_REQUEST['uid'];
	$sql = $query = '';
	
	/*--  删除信息  --*/
	$sql = "DELETE FROM {$dbprefix}members WHERE uid = $uid";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("用户删除成功","user.php?act=show");
	} else {
		showmsg("用户删除失败","user.php?act=show");
	}
}
?>