Example #1
0
function do_edit_save($aid, $params)
{
    $uid = false;
    if (array_key_exists('id', $params)) {
        $uid = $params['id'];
        $pass = trim($params['password']);
        unset($params['password']);
        cf\api\admin\doAction($aid, $params);
        if ($pass) {
            cf\User::setPassword($uid, $pass);
        }
    } else {
        $uid = cf\User::register($params['login'], $params['password'], $params['name'], $params['email'], $params['descr']);
    }
    if (cf\param::exist('roles')) {
        $roles = array_keys(cf\param::get('roles'));
        cf\execQuery('DELETE FROM cf_user_roles WHERE user_id=:uid', array('uid' => $uid));
        $q = cf\createQuery('INSERT INTO cf_user_roles (user_id,role_id) VALUES(:userId,:roleId)');
        $q->setParam('userId', $uid);
        foreach ($roles as $rid) {
            $q->setParam('roleId', $rid);
            $q->execute();
        }
    }
}