Esempio n. 1
0
}
switch ($op) {
    case 'post':
        foreach ($_POST as $k => $v) {
            ${$k} = $v;
        }
        if (!$xoopsSecurity->check()) {
            redirect_header('./' . ($create ? 'forum.php?id=' . $forum->id() : 'topic.php?id=' . $topic->id()), 2, __('Session token expired!', 'bxpress'));
            die;
        }
        $myts =& MyTextSanitizer::getInstance();
        if ($create) {
            $topic = new bXTopic();
            $topic->setApproved($forum->isAllowed($xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS, 'approve'));
            $topic->setDate(time());
            $topic->setForum($forum->id());
            $topic->setPoster($xoopsUser ? $xoopsUser->uid() : 0);
            $topic->setPosterName($xoopsUser ? $xoopsUser->uname() : $name);
            $topic->setRating(0);
            $topic->setReplies(0);
            $topic->setStatus(0);
            if ($xoopsUser && $xoopsModuleConfig['sticky']) {
                $csticky = $xoopsUser->isAdmin() || $forum->isModerator($xoopsUser->uid()) || $xoopsUser->posts() > $xoopsModuleConfig['sticky_posts'];
                if ($sticky) {
                    $topic->sticky(isset($sticky) ? $sticky : 0);
                }
            } else {
                $topic->setSticky(0);
            }
            $topic->setTitle($myts->addSlashes($subject));
            $topic->setViews(0);
Esempio n. 2
0
/**
* @desc Mover temas de un foro a otro
*/
function moveTopics()
{
    global $db, $xoopsModuleConfig, $xoopsSecurity, $forum, $xoopsUser, $xoopsOption, $xoopsConfig;
    $topics = isset($_REQUEST['topics']) ? $_REQUEST['topics'] : null;
    $ok = isset($_POST['ok']) ? $_POST['ok'] : 0;
    $moveforum = rmc_server_var($_POST, 'moveforum', 0);
    if (empty($topics) || is_array($topics) && empty($topics)) {
        redirect_header('moderate.php?id=' . $moveforum, 2, __('Select at least a topic to moderate!', 'bxpress'));
        die;
    }
    $topics = !is_array($topics) ? array($topics) : $topics;
    if ($ok) {
        if (!$xoopsSecurity->check()) {
            redirect_header('moderate.php?id=' . $moveforum, 2, __('Session token expired!', 'bxpress'));
            die;
        }
        if ($moveforum <= 0) {
            redirect_header('moderate.php?id=' . $forum->id(), 2, __('Please select the target forum', 'bxpress'));
            die;
        }
        $mf = new bXForum($moveforum);
        if ($mf->isNew()) {
            redirect_header('moderate.php?id=' . $forum->id(), 2, __('Specified forum does not exists!', 'bxpress'));
            die;
        }
        $lastpost = false;
        foreach ($topics as $k) {
            $topic = new bXTopic($k);
            if ($topic->forum() != $forum->id()) {
                continue;
            }
            //Verificamos si el tema contiene el último mensaje del foro
            if (!$lastpost && array_key_exists($forum->lastPostId(), $topic->getPosts(0))) {
                $lastpost = true;
            }
            $topic->setForum($moveforum);
            if ($topic->save()) {
                //Decrementa el número de temas
                $forum->setTopics($forum->topics() - 1 > 0 ? $forum->topics() - 1 : 0);
                $forum->setPosts($forum->posts() - ($topic->replies() + 1) > 0 ? $forum->posts() - ($topic->replies() + 1) : 0);
                $forum->save();
                $mf->setPosts($mf->posts() + ($topic->replies() + 1));
                $mf->addTopic();
                $mf->save();
                //Cambiamos el foro de los mensajes del tema
                if ($topic->getPosts()) {
                    foreach ($topic->getPosts() as $k => $v) {
                        $v->setForum($moveforum);
                        $v->save();
                    }
                }
            }
        }
        //Actualizamos el último mensaje del foro
        if ($lastpost) {
            $post = $forum->getLastPost();
            $forum->setPostId($post);
            $forum->save();
        }
        //Actualizamos el último mensaje del foro al que fue movido el tema
        $post = $mf->getLastPost();
        $post ? $mf->setPostId($post) : '';
        $mf->save();
        redirect_header('moderate.php?id=' . $forum->id(), 1, __('Topics has been relocated!', 'bxpress'));
        die;
    } else {
        global $xoopsTpl;
        $tpl = $xoopsTpl;
        $xoopsOption['template_main'] = "bxpress_moderateforms.html";
        $xoopsOption['module_subpage'] = "moderate";
        include 'header.php';
        bXFunctions::makeHeader();
        $form = new RMForm(__('Move Topics', 'bxpress'), 'frmMove', 'moderate.php');
        $form->addElement(new RMFormHidden('id', $forum->id()));
        $form->addElement(new RMFormHidden('op', 'move'));
        $form->addElement(new RMFormHidden('ok', '1'));
        $i = 0;
        foreach ($topics as $k) {
            $form->addElement(new RMFormHidden('topics[' . $i . ']', $k));
            ++$i;
        }
        $form->addElement(new RMFormSubTitle('&nbsp', 1, ''));
        $form->addElement(new RMFormSubTitle(__('Select the forum where you wish to move selected topics', 'bxpress'), 1, 'even'));
        $ele = new RMFormSelect(__('Forum', 'bxpress'), 'moveforum');
        $ele->addOption(0, '', 1);
        $tbl1 = $db->prefix("bxpress_categories");
        $tbl2 = $db->prefix("bxpress_forums");
        $sql = "SELECT b.*, a.title FROM {$tbl1} a, {$tbl2} b WHERE b.cat=a.id_cat AND b.active='1' AND id_forum<>" . $forum->id() . " ORDER BY a.order, b.order";
        $result = $db->query($sql);
        $categories = array();
        while ($row = $db->fetchArray($result)) {
            $cforum = array('id' => $row['id_forum'], 'name' => $row['name']);
            if (isset($categores[$row['cat']])) {
                $categories[$row['cat']]['forums'][] = $cforum;
            } else {
                $categories[$row['cat']]['title'] = $row['title'];
                $categories[$row['cat']]['forums'][] = $cforum;
            }
        }
        foreach ($categories as $cat) {
            $ele->addOption(0, $cat['title'], 0, true, 'color: #000; font-weight: bold; font-style: italic; border-bottom: 1px solid #c8c8c8;');
            foreach ($cat['forums'] as $cforum) {
                $ele->addOption($cforum['id'], $cforum['name'], 0, false, 'padding-left: 10px;');
            }
        }
        $form->addElement($ele, true, "noselect:0");
        $ele = new RMFormButtonGroup();
        $ele->addButton('sbt', __('Move Topics Now!', 'bxpress'), 'submit');
        $ele->addButton('cancel', __('Cancel', 'bxpress'), 'button', 'onclick="history.go(-1);"');
        $form->addElement($ele);
        $tpl->assign('moderate_form', $form->render());
        include 'footer.php';
    }
}