api_not_allowed(); } $return_message = set_notification($_GET['content'], $_GET['id']); Display::display_confirmation_message($return_message, false); } get_whats_new(); $whatsnew_post_info = Session::read('whatsnew_post_info'); /* TRACKING */ Event::event_access_tool(TOOL_FORUM); /* RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS note: we do this here just after het handling of the actions to be sure that we already incorporate the latest changes */ // Step 1: We store all the forum categories in an array $forum_categories. $forumCategories = get_forum_categories(); // Step 2: We find all the forums (only the visible ones if it is a student). // display group forum in general forum tool depending to configuration option $setting = api_get_setting('display_groups_forum_in_general_tool'); $forum_list = get_forums('', '', $setting == 'true'); $user_id = api_get_user_id(); /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */ // The groups of the user. $groups_of_user = array(); $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id); // All groups in the course (and sorting them as the // id of the group = the key of the array). if (!api_is_anonymous()) { $all_groups = GroupManager::get_group_list(); if (is_array($all_groups)) { foreach ($all_groups as $group) {
/** * Create a group * @param string $name The name for this group * @param int $tutor The user-id of the group's tutor * @param int $places How many people can subscribe to the new group */ public static function create_group($name, $category_id, $tutor, $places) { $_course = api_get_course_info(); $table_group = Database::get_course_table(TABLE_GROUP); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $currentCourseRepository = $_course['path']; $category = self::get_category($category_id); $places = intval($places); if ($places == 0) { //if the amount of users per group is not filled in, use the setting from the category $places = $category['max_student']; } else { if ($places > $category['max_student'] && $category['max_student'] != 0) { $places = $category['max_student']; } } $sql = "INSERT INTO " . $table_group . " SET\n c_id = {$course_id} ,\n category_id='" . Database::escape_string($category_id) . "',\n max_student = '" . $places . "',\n doc_state = '" . $category['doc_state'] . "',\n calendar_state = '" . $category['calendar_state'] . "',\n work_state = '" . $category['work_state'] . "',\n announcements_state = '" . $category['announcements_state'] . "',\n forum_state = '" . $category['forum_state'] . "',\n wiki_state = '" . $category['wiki_state'] . "',\n chat_state = '" . $category['chat_state'] . "',\n self_registration_allowed = '" . $category['self_reg_allowed'] . "',\n self_unregistration_allowed = '" . $category['self_unreg_allowed'] . "',\n session_id='" . Database::escape_string($session_id) . "'"; Database::query($sql); $lastId = Database::insert_id(); if ($lastId) { $desired_dir_name = '/' . api_replace_dangerous_char($name, 'strict') . '_groupdocs'; $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document'; $unique_name = FileManager::create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, NULL, $my_path, $desired_dir_name); /* Stores the directory path into the group table */ $sql = "UPDATE " . $table_group . " SET name = '" . Database::escape_string($name) . "', secret_directory = '" . $unique_name . "'\n WHERE c_id = {$course_id} AND iid ='" . $lastId . "'"; Database::query($sql); // create a forum if needed if ($category['forum_state'] >= 0) { require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php'; $forum_categories = get_forum_categories(); $values = array(); $values['forum_title'] = $name; $values['group_id'] = $lastId; $counter = 0; foreach ($forum_categories as $key => $value) { if ($counter == 0) { $forum_category_id = $key; } $counter++; } // A sanity check. if (empty($forum_category_id)) { $forum_category_id = 0; } $values['forum_category'] = $forum_category_id; $values['allow_anonymous_group']['allow_anonymous'] = 0; $values['students_can_edit_group']['students_can_edit'] = 0; $values['approval_direct_group']['approval_direct'] = 0; $values['allow_attachments_group']['allow_attachments'] = 1; $values['allow_new_threads_group']['allow_new_threads'] = 1; $values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view'); $values['group_forum'] = $lastId; if ($category['forum_state'] == '1') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'public'; } elseif ($category['forum_state'] == '2') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'private'; } elseif ($category['forum_state'] == '0') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable'; } store_forum($values); } } return $lastId; }
handle_forum_and_forumcategories(); } // Notification if ($action_forums == 'notify' && isset($_GET['content']) && isset($_GET['id'])) { $return_message = set_notification($_GET['content'], $_GET['id']); Display::display_confirmation_message($return_message, false); } if ($action_forums != 'add') { /* RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS Note: We do this here just after het handling of the actions to be sure that we already incorporate the latest changes. */ // Step 1: We store all the forum categories in an array $forum_categories. $forum_categories = array(); $forum_category = get_forum_categories($_GET['forumcategory']); // Step 2: We find all the forums. $forum_list = array(); $forum_list = get_forums(); /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */ // The groups of the user. $groups_of_user = array(); $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']); // All groups in the course (and sorting them as the id of the group = the key of the array. $all_groups = GroupManager::get_group_list(); if (is_array($all_groups)) { foreach ($all_groups as $group) { $all_groups[$group['id']] = $group; } } /* CLEAN GROUP ID FOR AJAXFILEMANAGER */
/** * Create a group * @param string $name The name for this group * @param int $category_id * @param int $tutor The user-id of the group's tutor * @param int $places How many people can subscribe to the new group */ public static function create_group($name, $category_id, $tutor, $places) { $courseObj = api_get_user_course_entity(); $_course = api_get_course_info(); $session_id = api_get_session_id(); $currentCourseRepository = $_course['path']; $category = self::get_category($category_id); $places = intval($places); if ($category) { if ($places == 0) { //if the amount of users per group is not filled in, use the setting from the category $places = $category['max_student']; } else { if ($places > $category['max_student'] && $category['max_student'] != 0) { $places = $category['max_student']; } } $docState = $category['doc_state']; $calendarState = $category['calendar_state']; $workState = $category['work_state']; $anonuncementState = $category['announcements_state']; $forumState = $category['forum_state']; $wikiState = $category['wiki_state']; $chatState = $category['chat_state']; $selfRegAllowed = $category['self_reg_allowed']; $selfUnregAllowed = $category['self_unreg_allowed']; } else { $docState = self::TOOL_PRIVATE; $calendarState = self::TOOL_PRIVATE; $workState = self::TOOL_PRIVATE; $anonuncementState = self::TOOL_PRIVATE; $forumState = self::TOOL_PRIVATE; $wikiState = self::TOOL_PRIVATE; $chatState = self::TOOL_PRIVATE; $selfRegAllowed = 0; $selfUnregAllowed = 0; } $group = new CGroupInfo(); $group->setName($name)->setStatus(1)->setDescription('')->setMaxStudent($places)->setAnnouncementsState($anonuncementState)->setDocState($docState)->setCalendarState($calendarState)->setChatState($chatState)->setForumState($forumState)->setWikiState($wikiState)->setWorkState($workState)->setSelfUnregistrationAllowed($selfUnregAllowed)->setSelfRegistrationAllowed($selfRegAllowed)->setSessionId($session_id)->setCourse($courseObj)->setCategoryId($category_id)->setDescription(''); $em = Database::getManager(); $em->persist($group); $em->flush(); $lastId = $group->getIid(); if ($lastId) { $desired_dir_name = '/' . api_replace_dangerous_char($name) . '_groupdocs'; $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document'; $newFolderData = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null, 1); $unique_name = $newFolderData['path']; $group->setId($lastId); $group->setSecretDirectory($unique_name); $group->setName($name); $em->merge($group); $em->flush(); // create a forum if needed if ($forumState >= 0) { require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php'; $forum_categories = get_forum_categories(); if (empty($forum_categories)) { $categoryParam = array('forum_category_title' => get_lang('GroupForums')); store_forumcategory($categoryParam); $forum_categories = get_forum_categories(); } $counter = 0; foreach ($forum_categories as $key => $value) { if ($counter == 0) { $forum_category_id = $key; } $counter++; } // A sanity check. if (empty($forum_category_id)) { $forum_category_id = 0; } $values = array(); $values['forum_title'] = $name; $values['group_id'] = $lastId; $values['forum_category'] = $forum_category_id; $values['allow_anonymous_group']['allow_anonymous'] = 0; $values['students_can_edit_group']['students_can_edit'] = 0; $values['approval_direct_group']['approval_direct'] = 0; $values['allow_attachments_group']['allow_attachments'] = 1; $values['allow_new_threads_group']['allow_new_threads'] = 1; $values['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view'); $values['group_forum'] = $lastId; if ($forumState == '1') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'public'; } elseif ($forumState == '2') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'private'; } elseif ($forumState == '0') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable'; } store_forum($values); } } return $lastId; }
/** * Display the search results * @param string * @return void display the results * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium * @version march 2008, dokeos 1.8.5 */ function display_forum_search_results($search_term) { $table_threads = Database::get_course_table(TABLE_FORUM_THREAD); $table_posts = Database::get_course_table(TABLE_FORUM_POST); $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); // Defining the search strings as an array. if (strstr($search_term, '+')) { $search_terms = explode('+', $search_term); } else { $search_terms[] = $search_term; } // Search restriction. foreach ($search_terms as $value) { $search_restriction[] = "\n (posts.post_title LIKE '%" . Database::escape_string(trim($value)) . "%'\n OR posts.post_text LIKE '%" . Database::escape_string(trim($value)) . "%')"; } $sql = "SELECT posts.*\n FROM {$table_posts} posts, {$table_threads} threads, {$table_item_property} item_property\n WHERE\n posts.c_id = {$course_id}\n AND item_property.c_id = {$course_id}\n AND posts.thread_id = threads.thread_id\n AND item_property.ref = threads.thread_id\n AND item_property.visibility = 1\n AND item_property.session_id = {$session_id}\n AND posts.visible = 1\n AND item_property.tool = '" . TOOL_FORUM_THREAD . "'\n AND " . implode(' AND ', $search_restriction) . "\n GROUP BY posts.post_id"; // Getting all the information of the forum categories. $forum_categories_list = get_forum_categories(); // Getting all the information of the forums. $forum_list = get_forums(); $result = Database::query($sql); $search_results = []; while ($row = Database::fetch_array($result, 'ASSOC')) { $display_result = false; /* We only show it when 1. forum category is visible 2. forum is visible 3. thread is visible (to do) 4. post is visible */ if (!api_is_allowed_to_edit(null, true)) { if ($forum_categories_list[$forum_list[$row['forum_id']]['forum_category']]['visibility'] == '1' and $forum_list[$row['forum_id']]['visibility'] == '1' and $row['visible'] == '1') { $display_result = true; } } else { $display_result = true; } if ($display_result) { $search_results_item = '<li><a href="viewforumcategory.php?' . api_get_cidreq() . '&forumcategory=' . $forum_list[$row['forum_id']]['forum_category'] . '&search=' . urlencode($search_term) . '">' . prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']) . '</a> > '; $search_results_item .= '<a href="viewforum.php?' . api_get_cidreq() . '&forum=' . $row['forum_id'] . '&search=' . urlencode($search_term) . '">' . prepare4display($forum_list[$row['forum_id']]['forum_title']) . '</a> > '; //$search_results_item .= '<a href="">THREAD</a> > '; $search_results_item .= '<a href="viewthread.php?' . api_get_cidreq() . '&forum=' . $row['forum_id'] . '&thread=' . $row['thread_id'] . '&search=' . urlencode($search_term) . '">' . prepare4display($row['post_title']) . '</a>'; $search_results_item .= '<br />'; if (api_strlen($row['post_title']) > 200) { $search_results_item .= prepare4display(api_substr(strip_tags($row['post_title']), 0, 200)) . '...'; } else { $search_results_item .= prepare4display($row['post_title']); } $search_results_item .= '</li>'; $search_results[] = $search_results_item; } } echo '<legend>' . count($search_results) . ' ' . get_lang('ForumSearchResults') . '</legend>'; echo '<ol>'; if ($search_results) { echo implode($search_results); } echo '</ol>'; }
} $return_message = set_notification($_GET['content'], $_GET['id']); Display::display_confirmation_message($return_message, false); } get_whats_new(); $whatsnew_post_info = array(); $whatsnew_post_info = $_SESSION['whatsnew_post_info']; /* TRACKING */ event_access_tool(TOOL_FORUM); /* RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS note: we do this here just after het handling of the actions to be sure that we already incorporate the latest changes */ // Step 1: We store all the forum categories in an array $forum_categories. $forum_categories_list = get_forum_categories(); // Step 2: We find all the forums (only the visible ones if it is a student). $forum_list = array(); $forum_list = get_forums(); $user_id = api_get_user_id(); /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */ // The groups of the user. $groups_of_user = array(); $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id); // All groups in the course (and sorting them as the id of the group = the key of the array). if (!api_is_anonymous()) { $all_groups = GroupManager::get_group_list(); if (is_array($all_groups)) { foreach ($all_groups as $group) { $all_groups[$group['id']] = $group; }
/** * Display the search results * @param string * @return void display the results * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium * @version march 2008, dokeos 1.8.5 */ function display_forum_search_results($search_term) { global $origin; $table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY); $table_forums = Database::get_course_table(TABLE_FORUM); $table_threads = Database::get_course_table(TABLE_FORUM_THREAD); $table_posts = Database::get_course_table(TABLE_FORUM_POST); $gradebook = Security::remove_XSS($_GET['gradebook']); $course_id = api_get_course_int_id(); // Defining the search strings as an array. if (strstr($search_term, '+')) { $search_terms = explode('+', $search_term); } else { $search_terms[] = $search_term; } // Search restriction. foreach ($search_terms as $key => $value) { $search_restriction[] = "(posts.post_title LIKE '%" . Database::escape_string(trim($value)) . "%'\n OR posts.post_text LIKE '%" . Database::escape_string(trim($value)) . "%')"; } $sql = "SELECT * FROM {$table_posts} posts\n WHERE c_id = {$course_id} AND " . implode(' AND ', $search_restriction) . "\n GROUP BY posts.post_id"; // Getting all the information of the forum categories. $forum_categories_list = get_forum_categories(); // Getting all the information of the forums. $forum_list = get_forums(); $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $display_result = false; /* We only show it when 1. forum cateogory is visible 2. forum is visible 3. thread is visible (to do) 4. post is visible */ if (!api_is_allowed_to_edit(null, true)) { if ($forum_categories_list[$row['forum_id']['forum_category']]['visibility'] == '1' and $forum_list[$row['forum_id']]['visibility'] == '1' and $row['visible'] == '1') { $display_result = true; } } else { $display_result = true; } if ($display_result) { $search_results_item = '<li><a href="viewforumcategory.php?forumcategory=' . $forum_list[$row['forum_id']]['forum_category'] . '&origin=' . $origin . '&search=' . urlencode($search_term) . '">' . prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']) . '</a> > '; $search_results_item .= '<a href="viewforum.php?forum=' . $row['forum_id'] . '&origin=' . $origin . '&search=' . urlencode($search_term) . '">' . prepare4display($forum_list[$row['forum_id']]['forum_title']) . '</a> > '; //$search_results_item .= '<a href="">THREAD</a> > '; $search_results_item .= '<a href="viewthread.php?forum=' . $row['forum_id'] . '&gradebook=' . $gradebook . '&origin=' . $origin . '&thread=' . $row['thread_id'] . '&search=' . urlencode($search_term) . '">' . prepare4display($row['post_title']) . '</a>'; $search_results_item .= '<br />'; if (api_strlen($row['post_title']) > 200) { $search_results_item .= prepare4display(api_substr(strip_tags($row['post_title']), 0, 200)) . '...'; } else { $search_results_item .= prepare4display($row['post_title']); } $search_results_item .= '</li>'; $search_results[] = $search_results_item; } } echo '<legend>' . count($search_results) . ' ' . get_lang('ForumSearchResults') . '</legend>'; echo '<ol>'; if ($search_results) { echo implode($search_results); } echo '</ol>'; }