/**
 * This function handles all the forum and forum categories actions. This is a wrapper for the
 * forum and forum categories. All this code code could go into the section where this function is
 * called but this make the code there cleaner.
 * @param int $lp_id Learning path Id
 *
 * @return void
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Juan Carlos Raña Trabado (return to lp_id)
 * @version may 2011, Chamilo 1.8.8
 */
function handle_forum_and_forumcategories($lp_id = null)
{
    $action_forum_cat = isset($_GET['action']) ? $_GET['action'] : '';
    $get_content = isset($_GET['content']) ? $_GET['content'] : '';
    $post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
    $post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
    $get_id = isset($_GET['id']) ? intval($_GET['id']) : '';
    $forum_categories_list = get_forum_categories();
    //Verify if forum category exists
    if (empty($forum_categories_list)) {
        $get_content = 'forumcategory';
    }
    // Adding a forum category
    if ($action_forum_cat == 'add' && $get_content == 'forumcategory' || $post_submit_cat) {
        show_add_forumcategory_form(array(), $lp_id);
        //$lp_id when is called from learning path
    }
    // Adding a forum
    if (($action_forum_cat == 'add' || $action_forum_cat == 'edit') && $get_content == 'forum' || $post_submit_forum) {
        if ($action_forum_cat == 'edit' && $get_id || $post_submit_forum) {
            $inputvalues = get_forums($get_id);
        } else {
            $inputvalues = array();
        }
        show_add_forum_form($inputvalues, $lp_id);
    }
    // Edit a forum category
    if ($action_forum_cat == 'edit' && $get_content == 'forumcategory' || isset($_POST['SubmitEditForumCategory']) ? true : false) {
        $forum_category = get_forum_categories($get_id);
        show_edit_forumcategory_form($forum_category);
    }
    // Delete a forum category
    if ($action_forum_cat == 'delete') {
        $id_forum = intval($get_id);
        $list_threads = get_threads($id_forum);
        for ($i = 0; $i < count($list_threads); $i++) {
            deleteForumCategoryThread('thread', $list_threads[$i]['thread_id']);
            $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, intval($list_threads[$i]['thread_id']), api_get_session_id());
            if ($link_info !== false) {
                GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
            }
        }
        $return_message = deleteForumCategoryThread($get_content, $get_id);
        Display::display_confirmation_message($return_message, false);
    }
    // Change visibility of a forum or a forum category.
    if ($action_forum_cat == 'invisible' || $action_forum_cat == 'visible') {
        $return_message = change_visibility($get_content, $get_id, $action_forum_cat);
        Display::display_confirmation_message($return_message, false);
    }
    // Change lock status of a forum or a forum category.
    if ($action_forum_cat == 'lock' || $action_forum_cat == 'unlock') {
        $return_message = change_lock_status($get_content, $get_id, $action_forum_cat);
        Display::display_confirmation_message($return_message, false);
    }
    // Move a forum or a forum category.
    if ($action_forum_cat == 'move' && isset($_GET['direction'])) {
        $return_message = move_up_down($get_content, $_GET['direction'], $get_id);
        Display::display_confirmation_message($return_message, false);
    }
}
Beispiel #2
0
    Display::display_header('');
}
/* Actions */
// Change visibility of a forum or a forum category.
if (($my_action == 'invisible' || $my_action == 'visible') && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
}
// Locking and unlocking.
if (($my_action == 'lock' || $my_action == 'unlock') && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
}
// Deleting.
if ($my_action == 'delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
    if ($locked == false) {
        $message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
        // Delete link
        $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, intval($_GET['id']), api_get_session_id());
        $link_id = $link_info->getId();
        if ($link_info) {
            GradebookUtils::remove_resource_from_course_gradebook($link_id);
        }
    }
}
// Moving.
if ($my_action == 'move' && isset($_GET['thread']) && api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true)) {
    $message = move_thread_form();
}
// Notification.
if ($my_action == 'notify' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_session_edit(false, true)) {
    $return_message = set_notification($_GET['content'], $_GET['id']);