<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id lis.inc.php 2 2008-08-24 11:39 $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

if(!$dosubmit) {

    if(!is_numeric($uid) || $uid < 1) cpmsg('UID不正确。');
    if($admin->admintype != 1) cpmsg('权限不足。');
    $tplname = 'job.edituser';
    $uid = @intval($uid);
    $member = $db->get_one("SELECT username,email,point,coin,flowers,groupid FROM {$dbpre}members a WHERE uid='$uid'");
    if(!$member) cpmsg('用户不存在。');

    $groups = $db->get_all("SELECT * FROM {$dbpre}usergroups ORDER BY groupid");
    foreach($groups as $group) {
        $selected = $group['groupid']==$member['groupid'] ? ' selected="selected"' : '';
        $group_opt .= '<option value="'.$group['groupid'].'"'.$selected.'>'.$group['groupname'].'</option>'."\n";
    }

    include cptpl('edit', MOD_ROOT.'./admin/templates/');

} else {

    $update = array();

    if(!is_numeric($uid) || $uid < 1) cpmsg('UID不正确。');
    if($admin->admintype != 1) cpmsg('权限不足。','admincp.php?action=logout');

    $memberupdate['groupid'] = @intval($memberupdate['groupid']);
    $memberupdate['groupid'] = $memberupdate['groupid']<1 ? 10 : $memberupdate['groupid'];
    $update[] = "groupid='{$memberupdate['groupid']}'";

    if(!isemail($memberupdate['email'])) {
        cpmsg('E-mail格式不正确，请返回修改。');
    }

    $update[] = "email='{$memberupdate['email']}'";

    if(!is_numeric($memberupdate['point'])||$memberupdate['point']<0) {
        cpmsg('积分格式不正确，请返回修改。');
    }
    $update[] = "point='{$memberupdate['point']}'";
    if(!is_numeric($memberupdate['coin'])||$memberupdate['coin']<0) {
        cpmsg('金币格式不正确，请返回修改。');
    }
    $update[] = "coin='{$memberupdate['coin']}'";
    if(!is_numeric($memberupdate['flowers'])||$memberupdate['flowers']<0) {
        cpmsg('鲜花量不正确，请返回修改。');
    }

    $update[] = "flowers='{$memberupdate['flowers']}'";

    if($memberupdate['password']) {
        if(strlen($memberupdate['password']) < 6) {
            cpmsg('密码不能小于6位数，请返回修改。');
        } elseif($memberupdate['password'] != $memberupdate['repassword']) {
            cpmsg('2次输入的密码不一致，请返回修改。');
        } else {
            $update[] = "password='".md5($memberupdate['password'])."'";
        }
    }
    if($update && is_array($update)) {
        $update = implode(", ", $update);
        $db->query("UPDATE {$dbpre}members SET $update WHERE uid='$uid'");
    }

    cpmsg('用户更新完毕。',"admincp.php?action=$action&file=list");
}
?>