Ejemplo n.º 1
0
/**
* @desc Almacena los datos de un foro
*/
function bx_save_forum($edit = 0)
{
    global $xoopsSecurity, $xoopsModuleConfig, $xoopsConfig;
    $q = $edit ? 'action=edit' : 'action=new';
    $prefix = 1;
    foreach ($_POST as $k => $v) {
        if (substr($k, 0, 5) == 'perm_') {
            $permissions[substr($k, 5)] = $v;
        } else {
            ${$k} = $v;
        }
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'action') {
            continue;
        }
        $q = '&' . $k . '=' . $v;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('forums.php?' . $q, __('Session token expired', 'bxpress'), 1);
        die;
    }
    if ($edit) {
        $id = rmc_server_var($_REQUEST, 'id', 0);
        if ($id <= 0) {
            redirectMsg('forums.php', __('Specified id is not valid!', 'bxpress'), 1);
            die;
        }
        $forum = new bXForum($id);
        if ($forum->isNew()) {
            redirectMsg('forums.php', __('Specified forum does not exists!', 'bxpress'), 1);
            die;
        }
    } else {
        $forum = new bXForum();
    }
    $forum->setName($name);
    $forum->setDescription($desc);
    if (!$edit) {
        $forum->setTopics(0);
        $forum->setPosts(0);
        $forum->setPostId(0);
        $forum->setSubforums(0);
    }
    $forum->setCategory($cat);
    $forum->setActive($active);
    $forum->setSignature($sig);
    $forum->setPrefix($prefix);
    $forum->setHotThreshold($hot_threshold);
    $forum->setOrder($order);
    $forum->setAttachments($attachments);
    $forum->setMaxSize($attach_maxkb);
    $forum->setExtensions(explode('|', $attach_ext));
    $forum->setFriendName(TextCleaner::getInstance()->sweetstring($name));
    $forum->setPermissions($permissions);
    if ($forum->save()) {
        if ($parent > 0) {
            $pf = new bXForum($parent);
            if (!$pf->isNew()) {
                $pf->setSubforums($pf->subforums() + 1);
                $pf->save();
            }
        }
        if (!$edit) {
            //Redireccionamos a ventana de selección de moderadores
            redirectMsg('forums.php?action=moderators&id=' . $forum->id(), __('Forum saved successfully! Redirecting to moderators assignment...', 'bxpress'), 0);
        } else {
            redirectMsg('forums.php', __('Changes saved successfully!', 'bxpress'), 0);
        }
    } else {
        redirectMsg('forums.php?' . $q, __('Forum could not be saved!', 'bxpress') . $forum->errors(), 1);
    }
}