<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
include_once($conf_basedir."base.inc.php");
checkAuth('4');	//判断登录和权限
$title = "用户管理";

$truename = trim(strip_tags($truename));
$authname = trim(strip_tags($authname));
$newpassword = md5($password);
$valid_flag = intval($valid_flag);
$telno = trim(strip_tags($telno));

$purview = "";
if(is_array($groupid) && !empty($groupid))
{
	$purview_arr = array();

	foreach($groupid as $key=>$value)
	{
		if($value > 0)
		{
			$purview_arr[$key] = $value;
		}
	}

	if(is_array($purview_arr) && !empty($purview_arr))
	{
		$purview = serialize($purview_arr);
	}
}

if($todo == "modify")
{
	$uid = intval($uid);
	
	//检查密码是否修改
	$nowpwd = $dao_sys->getOne("admin_user", " uid = '".$uid."' ", "password");
	$newpassword = $password != $nowpwd ? $newpassword : $nowpwd;

	$sql = "UPDATE admin_user SET truename = '".$truename."', username = '".$username."', password = '".$newpassword."', purview = '".$purview."', status = '".$status."', telno = '".$telno."', message = '".$message."' WHERE uid = '".$uid."'";
	$db_sys->Execute($sql);

	echo js_redirect("auth_manage.php", "修改成功！");
	exit;
}
else
{
	$sql = "INSERT INTO admin_user (`truename`,`username`,`password`,`status`,`telno`,`message`,`purview`) VALUES('".$truename."','".$username."','".$newpassword."','".$status."','".$telno."','".$message."','".$purview."')";
	$db_sys->Execute($sql);

	echo js_redirect("auth_manage.php", "创建成功！");
	exit;
}

//引用模版文件
include_once(Template("header"));
include_once(Template("manage/auth_modify"));
include_once(Template("footer"));
?>