total_number_of_items; } /** * Get course data to display * @param int $from * @param int $number_of_items * @param int $column * @param string $direction * * @return array */ function get_course_data($from, $number_of_items, $column, $direction) { $course_table = Database::get_main_table(TABLE_MAIN_COURSE); $sql = "SELECT code AS col0, title AS col1, code AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6, code AS col7, visibility AS col8, directory as col9, visual_code FROM $course_table course"; if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1 ) { $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (course.id = url_rel_course.c_id)"; } if (isset ($_GET['keyword'])) { $keyword = Database::escape_string("%".trim($_GET['keyword'])."%"); $sql .= " WHERE ( title LIKE '".$keyword."' OR code LIKE '".$keyword."' OR visual_code LIKE '".$keyword."' ) "; } elseif (isset($_GET['keyword_code'])) { $keyword_code = Database::escape_string("%".$_GET['keyword_code']."%"); $keyword_title = Database::escape_string("%".$_GET['keyword_title']."%"); $keyword_category = Database::escape_string("%".$_GET['keyword_category']."%"); $keyword_language = Database::escape_string("%".$_GET['keyword_language']."%"); $keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%"); $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']); $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']); $sql .= " WHERE (code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND title LIKE '".$keyword_title."' AND category_code LIKE '".$keyword_category."' AND course_language LIKE '".$keyword_language."' AND visibility LIKE '".$keyword_visibility."' AND subscribe LIKE '".$keyword_subscribe."' AND unsubscribe LIKE '".$keyword_unsubscribe."'"; } // Adding the filter to see the user's only of the current access_url. if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1 ) { $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id(); } $sql .= " ORDER BY col$column $direction "; $sql .= " LIMIT $from, $number_of_items"; $res = Database::query($sql); $courses = array(); $languages = api_get_languages_to_array(); while ($course = Database::fetch_array($res)) { // Place colour icons in front of courses. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null; $course[1] = get_course_visibility_icon($course[8]).''.$course[1].' '.$show_visual_code; $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); $language = isset($languages[$course[3]]) ? $languages[$course[3]] : $course[3]; $course_rem = array( $course[0], $course[1], $course[2], $language, $course[4], $course[5], $course[6], $course[7], ); $courses[] = $course_rem; } return $courses; } /** * Get course data to display filtered by session name * @param int $from * @param int $number_of_items * @param int $column * @param string $direction * @return array */ function get_course_data_by_session($from, $number_of_items, $column, $direction) { $course_table = Database::get_main_table(TABLE_MAIN_COURSE); $session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $session = Database::get_main_table(TABLE_MAIN_SESSION); $sql = "SELECT c.code AS col0, c.title AS col1, c.code AS col2, c.course_language AS col3, c.category_code AS col4, c.subscribe AS col5, c.unsubscribe AS col6, c.code AS col7, c.visibility AS col8, c.directory as col9, c.visual_code FROM $course_table c INNER JOIN $session_rel_course r ON c.id = r.c_id INNER JOIN $session s ON r.session_id = s.id "; if (isset($_GET['session_id']) && !empty($_GET['session_id'])) { $sessionId = intval($_GET['session_id']); $sql.= " WHERE s.id = ".$sessionId; } $sql .= " ORDER BY col$column $direction "; $sql .= " LIMIT $from,$number_of_items"; $res = Database::query($sql); $courses = array (); while ($course = Database::fetch_array($res)) { // Place colour icons in front of courses. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null; $course[1] = get_course_visibility_icon($course[8]).''.$course[1].' '.$show_visual_code; $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No'); $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]); $courses[] = $course_rem; } return $courses; } /** * Filter to display the edit-buttons */ function modify_courses_filter($code) { $icourse = api_get_course_info($code); $path = api_get_path(WEB_CODE_PATH); return ''. Display::return_icon('synthese_view.gif', get_lang('Info')).' '. //''. //Display::return_icon('course_home.gif', get_lang('CourseHomepage')).' '. // This is not the preferable way to go to the homepage. ''. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).' '. ''. Display::return_icon('statistics.gif', get_lang('Tracking')).' '. ''. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).' '. ''. Display::return_icon('backup.gif', get_lang('CreateBackup')).' '. ''. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).''; } /** * Return an icon representing the visibility of the course */ function get_course_visibility_icon($v) { $style = 'margin-bottom:0;margin-right:5px;'; switch($v) { case 0: return Display::return_icon('bullet_red.png', get_lang('CourseVisibilityClosed'), array('style' => $style)); break; case 1: return Display::return_icon('bullet_orange.png', get_lang('Private'), array('style' => $style)); break; case 2: return Display::return_icon('bullet_green.png', get_lang('OpenToThePlatform'), array('style' => $style)); break; case 3: return Display::return_icon('bullet_blue.png', get_lang('OpenToTheWorld'), array('style' => $style)); break; case 4: return Display::return_icon('bullet_grey.png', get_lang('CourseVisibilityHidden'), array('style' => $style)); break; default: return ''; } } if (isset ($_POST['action'])) { switch ($_POST['action']) { // Delete selected courses case 'delete_courses': $course_codes = $_POST['course']; if (count($course_codes) > 0) { foreach ($course_codes as $course_code) { CourseManager::delete_course($course_code); $obj_cat = new Category(); $obj_cat->update_category_delete($course_code); } } break; } } $content = ''; $message = ''; $actions = ''; if (isset ($_GET['search']) && $_GET['search'] === 'advanced') { // Get all course categories $interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'), 'name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList')); $tool_name = get_lang('SearchACourse'); //api_display_tool_title($tool_name); $form = new FormValidator('advanced_course_search', 'get'); $form->addElement('header', $tool_name); $form->addText('keyword_code', get_lang('CourseCode'), false); $form->addText('keyword_title', get_lang('Title'), false); // Category code $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category'; $form->addElement( 'select_ajax', 'keyword_category', get_lang('CourseFaculty'), null, array( 'url' => $url ) ); $el = $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage')); $el->addOption(get_lang('All'), '%'); $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD); $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM); $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED); $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED); $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN); $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%'); $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1); $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0); $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%'); $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1); $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0); $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%'); $form->addButtonSearch(get_lang('SearchCourse')); $defaults['keyword_language'] = '%'; $defaults['keyword_visibility'] = '%'; $defaults['keyword_subscribe'] = '%'; $defaults['keyword_unsubscribe'] = '%'; $form->setDefaults($defaults); $content .= $form->returnForm(); } else { $interbreadcrumb[] = array ('url' => Container::getRouter()->generate('administration'), "name" => get_lang('PlatformAdmin')); $tool_name = get_lang('CourseList'); if (isset($_GET['delete_course'])) { CourseManager::delete_course($_GET['delete_course']); $obj_cat = new Category(); $obj_cat->update_category_delete($_GET['delete_course']); } // Create a search-box $form = new FormValidator('search_simple', 'get', '', '', array(), FormValidator::LAYOUT_INLINE); $form->addElement('text', 'keyword', null, array('id' => 'course-search-keyword')); $form->addButtonSearch(get_lang('SearchCourse')); $advanced = ' '.get_lang('AdvancedSearch').''; // Create a filter by session $sessionFilter = new FormValidator('course_filter', 'get', '', '', array(), FormValidator::LAYOUT_INLINE); $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session'; $sessionSelect = $sessionFilter->addElement( 'select_ajax', 'session_name', get_lang('SearchCourseBySession'), null, array('url' => $url) ); if (!empty($sessionId)) { $sessionInfo = SessionManager::fetch($sessionId); $sessionSelect->addOption($sessionInfo['name'], $sessionInfo['id'], ['selected' => 'selected']); } $courseListUrl = api_get_self(); $actions .= '