예제 #1
0
/**
* @desc Eliminar temas
*/
function deleteTopics()
{
    global $db, $xoopsModuleConfig, $bxpress, $forum, $xoopsUser, $xoopsSecurity;
    $ok = isset($_POST['ok']) ? $_POST['ok'] : 0;
    $topics = isset($_REQUEST['topics']) ? $_REQUEST['topics'] : null;
    if (empty($topics) || is_array($topics) && empty($topics)) {
        redirect_header('moderate.php?id=' . $forum->id(), 2, __('Select at least one topic to delete!', 'bxpress'));
        die;
    }
    $topics = !is_array($topics) ? array($topics) : $topics;
    $lastpost = false;
    if (!$xoopsSecurity->check()) {
        redirect_header('moderate.php?id=' . $forum->id(), 2, __('Session token expired!', 'bxpress'));
        die;
    }
    foreach ($topics as $k) {
        $topic = new bXTopic($k);
        if ($topic->isNew()) {
            continue;
        }
        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->delete();
    }
    //Actualizamos el último mensaje del foro
    if ($lastpost) {
        $forum = new bXForum($forum->id());
        $post = $forum->getLastPost();
        $forum->setPostId($post);
        $forum->save();
    }
    redirect_header('moderate.php?id=' . $forum->id(), 1, __('Action completed!', 'bxpress'));
}