$teacherId) { if (0 === $teacherId) { $addNull = 'OR cu.user_id IS NULL '; unset($key); } } $sql .= ' AND ( cu.user_id IN ("'.implode('", "', $teachers).'") '.$addNull.' ) '; } if (false === $getCount) { $sql .= " GROUP BY course.id "; } } if ($getCount) { $res = Database::query($sql); $row = Database::fetch_array($res); if ($row) { return (int) $row['count']; } return 0; } $sql .= " ORDER BY col$column $direction "; $sql .= " LIMIT $from, $number_of_items"; $res = Database::query($sql); $courses = []; $path = api_get_path(WEB_CODE_PATH); $coursePath = api_get_path(WEB_COURSE_PATH); while ($course = Database::fetch_array($res)) { $courseId = $course['id']; $courseCode = $course['code']; // Place colour icons in front of courses. $showVisualCode = $course['visual_code'] != $courseCode ? Display::label($course['visual_code'], 'info') : null; $course[1] = get_course_visibility_icon($course['visibility']).PHP_EOL .Display::url(Security::remove_XSS($course[1]), $coursePath.$course['directory'].'/index.php').PHP_EOL .$showVisualCode; $course[5] = SUBSCRIBE_ALLOWED == $course[5] ? get_lang('Yes') : get_lang('No'); $course[6] = UNSUBSCRIBE_ALLOWED == $course[6] ? get_lang('Yes') : get_lang('No'); $actions = []; $actions[] = Display::url( Display::getMdiIcon('info2', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Info')), "course_information.php?id=$courseId" ); /*$actions[] = Display::url( Display::getMdiIcon('course_home', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('CourseHomepage')), $coursePath.$course['directory'].'/index.php' );*/ $actions[] = Display::url( Display::getMdiIcon('statistics', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Tracking')), $path.'tracking/courseLog.php?'.api_get_cidreq_params($courseId) ); $actions[] = Display::url( Display::getMdiIcon('edit', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')), $path.'admin/course_edit.php?id='.$courseId ); $actions[] = Display::url( Display::getMdiIcon('backup', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Create a backup')), $path.'course_copy/create_backup.php?'.api_get_cidreq_params($courseId) ); $actions[] = Display::url( Display::getMdiIcon('delete', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')), $path.'admin/course_list_admin.php?delete_course='.$courseCode, [ 'onclick' => "javascript: if (!confirm('" .addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."')) return false;", ] ); $course['creation_date'] = api_get_local_time($course['col2']); $lastAccessLocalTime = ''; $lastAccess = Tracking::getLastConnectionDateByCourse($courseId); if ($lastAccess) { $lastAccessLocalTime = api_get_local_time($lastAccess); } $courseItem = [ $course[0], $course[1], $course['creation_date'], $lastAccessLocalTime, ]; if ($addTeacherColumn) { $teacherIdList = array_filter(explode(',', $course['col4'])); $teacherList = []; if (!empty($teacherIdList)) { foreach ($teacherIdList as $teacherId) { $userInfo = api_get_user_info($teacherId); if ($userInfo) { $teacherList[] = $userInfo['complete_name']; } } } $courseItem[] = implode(', ', $teacherList); } $courseItem[] = implode(PHP_EOL, $actions); $courses[] = $courseItem; } return $courses; } /** * Return an icon representing the visibility of the course. * * @param string $visibility * * @return string */ function get_course_visibility_icon($visibility) { $style = 'margin-bottom:0;margin-right:5px;'; switch ($visibility) { case 0: return Display::getMdiIcon(StateIcon::CLOSED_VISIBILITY, 'ch-tool-icon', $style, ICON_SIZE_SMALL, get_lang('Closed - the course is only accessible to the teachers')); break; case 1: return Display::getMdiIcon(StateIcon::PRIVATE_VISIBILITY, 'ch-tool-icon', $style, ICON_SIZE_SMALL, get_lang('Private access (access authorized to group members only)')); break; case 2: return Display::getMdiIcon(StateIcon::OPEN_VISIBILITY, 'ch-tool-icon', $style, ICON_SIZE_SMALL, get_lang('Open - access allowed for users registered on the platform')); break; case 3: return Display::getMdiIcon(StateIcon::PUBLIC_VISIBILITY, 'ch-tool-icon', $style, ICON_SIZE_SMALL, get_lang('Public - access allowed for the whole world')); break; case 4: return Display::getMdiIcon(StateIcon::HIDDEN_VISIBILITY, 'ch-tool-icon', $style, ICON_SIZE_SMALL, get_lang('Hidden - Completely hidden to all users except the administrators')); break; default: return ''; } } if (isset($_POST['action'])) { switch ($_POST['action']) { // Delete selected courses case 'delete_courses': if (!empty($_POST['course'])) { $course_codes = $_POST['course']; if (count($course_codes) > 0) { foreach ($course_codes as $course_code) { CourseManager::delete_course($course_code); } } Display::addFlash(Display::return_message(get_lang('Deleted'))); } break; } } $content = ''; $message = ''; $actions = ''; if (isset($_GET['search']) && 'advanced' === $_GET['search']) { // Get all course categories $interbreadcrumb[] = [ 'url' => 'index.php', 'name' => get_lang('Administration'), ]; $interbreadcrumb[] = [ 'url' => 'course_list_admin.php', 'name' => get_lang('Course list'), ]; $tool_name = get_lang('Search courses'); $form = new FormValidator('advanced_course_search', 'get'); $form->addElement('header', $tool_name); $form->addText('keyword_code', get_lang('Course code'), 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('Category'), null, [ 'url' => $url, ] ); $el = $form->addSelectLanguage('keyword_language', get_lang('Course language')); $el->addOption(get_lang('All'), '%'); if ($addTeacherColumn) { $form->addSelectAjax( 'course_teachers', get_lang('Teachers'), [0 => get_lang('None')], [ 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course', 'id' => 'course_teachers', 'multiple' => 'multiple', ] ); $form->addLabel('', ''); } $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('Search courses')); $defaults['keyword_language'] = '%'; $defaults['keyword_visibility'] = '%'; $defaults['keyword_subscribe'] = '%'; $defaults['keyword_unsubscribe'] = '%'; $form->setDefaults($defaults); $content .= $form->returnForm(); } else { $interbreadcrumb[] = [ 'url' => 'index.php', 'name' => get_lang('PlatformAdmin'), ]; $tool_name = get_lang('CourseList'); if (isset($_GET['delete_course'])) { $result = CourseManager::delete_course($_GET['delete_course']); if ($result) { Display::addFlash(Display::return_message(get_lang('Deleted'))); } } // Create a search-box $form = new FormValidator( 'search_simple', 'get', '', '', [], FormValidator::LAYOUT_INLINE ); $form->addElement( 'text', 'keyword', null, ['id' => 'course-search-keyword', 'aria-label' => get_lang('SearchCourse')] ); $form->addButtonSearch(get_lang('SearchCourse')); $advanced = ' '. get_lang('Advanced search').''; // Create a filter by session $sessionFilter = new FormValidator( 'course_filter', 'get', '', '', [], FormValidator::LAYOUT_INLINE ); $courseListUrl = api_get_self(); $actions1 = Display::url( Display::getMdiIcon(ActionIcon::ADD, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('AddCourse')), api_get_path(WEB_CODE_PATH).'admin/course_add.php' ); if ('true' === api_get_setting('course_validation')) { $actions1 .= Display::url( Display::getMdiIcon('notebook-heart-outline', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('ReviewCourseRequests')), api_get_path(WEB_CODE_PATH).'admin/course_request_review.php' ); } $actions2 = $form->returnForm(); //$actions3 = $sessionFilter->returnForm(); $actions4 = $advanced; $actions = Display::toolbarAction('toolbar', [$actions1, $actions4.$actions2]); // Create a sortable table with the course data $table = new SortableTable( 'course_list_admin', 'get_number_of_courses', 'get_course_data', 1, 20, 'ASC', 'course_list_admin' ); $parameters = []; if (isset($_GET['keyword'])) { $parameters = ['keyword' => Security::remove_XSS($_GET['keyword'])]; } elseif (isset($_GET['keyword_code'])) { $parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']); $parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']); if (isset($_GET['keyword_category'])) { $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']); } $parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']); $parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']); $parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']); $parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']); } if (isset($_GET['course_teachers'])) { $parsed = array_map('intval', $_GET['course_teachers']); $parameters["course_teachers"] = ''; foreach ($parsed as $key => $teacherId) { $parameters["course_teachers[$key]"] = $teacherId; } } $table->set_additional_parameters($parameters); $column = 0; $table->set_header($column++, '', false, 'width="8px"'); $table->set_header($column++, get_lang('Title'), true, null, ['class' => 'title']); $table->set_header($column++, get_lang('Creation date'), true, 'width="70px"'); $table->set_header($column++, get_lang('Latest access in course'), false, 'width="70px"'); //$table->set_header($column++, get_lang('Category')); //$table->set_header($column++, get_lang('SubscriptionAllowed'), true, 'width="60px"'); //$table->set_header($column++, get_lang('UnsubscriptionAllowed'), false, 'width="50px"'); if ($addTeacherColumn) { $table->set_header($column++, get_lang('Teachers'), true); } $table->set_header( $column++, get_lang('Action'), false, null, ['class' => 'td_actions'] ); $table->set_form_actions( ['delete_courses' => get_lang('Delete selected course(s)')], 'course' ); $tab = CourseManager::getCourseListTabs('admin'); $content .= $tab.$table->return_table(); } $htmlHeadXtra[] = ' '; $tpl = new Template($tool_name); $tpl->assign('actions', $actions); $tpl->assign('message', $message); $tpl->assign('content', $content); $tpl->display_one_col_template();