<?php

global $user;
$id = abs(intval($_GET['id']));
$arr = array();
$result = $db->query("select * from " . PF . "user where id='$id'");
if ($row = $db->fetch_array($result))
{
    $arr['name'] = htmlspecialchars($row['name']);
    $arr['reg_time'] = showtime($row['reg_time']);
    $arr['sex'] = $row['sex'];
    $arr['team'] = $row['team'];
    $arr['email'] = htmlspecialchars($row['email']);
    $arr['posts'] = $row['posts'];
} else
{
    yun_error('用户不存在');
}
if (IS_POST)
{
    $arr2 = array();
    $arr2['team'] = intval($_POST['team']);
    if (strlen($_POST['pass']) > 0)
    {
        strlen($_POST['pass']) < 5 && yun_error('密码不能少于5位', 'yun_onfocus("pass");');
        $arr2['pass'] = md5(md5($_POST['pass']));
    }
    ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,3}$", $_POST['email']) or
        yun_error('邮箱格式不正确', 'yun_onfocus("email");');
    $result = $db->query("select * from " . PF . "user where email='" . addslashes($_POST['email']) .
        "' && id<>'$id'");
    $db->num_rows($result) && yun_error('邮箱已存在', 'yun_onfocus("email");');
    $arr2['email'] = $_POST['email'];
    $arr2['posts'] = abs(intval($_POST['posts']));
    $arr2['sex'] = $_POST['sex'] ? 1 : 0;
    foreach ($arr2 as $k => $v)
    {
        $arr2[$k] = $k . '=\'' . addslashes($v) . '\'';
    }
    if ($db->query("update " . PF . "user set " . implode(',', $arr2) . " where id='$id'"))
    {
        yun_succeed('修改成功', 'refresh', true);
    } else
    {
        yun_error('修改失败');
    }
}
arg($arr, $id);

?>