registerFunction(['search_courses', 'AddCourseToSession', 'search_courses']);
// Setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
// setting breadcrumbs
$interbreadcrumb[] = [
'url' => 'session_list.php',
'name' => get_lang('SessionList'),
];
$interbreadcrumb[] = [
'url' => "resume_session.php?id_session=$sessionId",
'name' => get_lang('SessionOverview'),
];
// Database Table Definitions
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
// setting the name of the tool
$tool_name = get_lang('SubscribeCoursesToSession');
$add_type = 'multiple';
if (isset($_GET['add_type']) && $_GET['add_type'] != '') {
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
$xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = '';
$CourseList = $SessionList = [];
$courses = $sessions = [];
if (isset($_POST['formSent']) && $_POST['formSent']) {
$courseList = $_POST['SessionCoursesList'];
$copyEvaluation = isset($_POST['copy_evaluation']);
$copyCourseTeachersAsCoach = isset($_POST['import_teachers_as_course_coach']);
SessionManager::add_courses_to_session(
$sessionId,
$courseList,
true,
$copyEvaluation,
$copyCourseTeachersAsCoach
);
Display::addFlash(Display::return_message(get_lang('Updated')));
$url = api_get_path(WEB_CODE_PATH).'session/';
if (isset($add)) {
header('Location: '.$url.'add_users_to_session.php?id_session='.$sessionId.'&add=true');
} else {
header('Location: '.$url.'resume_session.php?id_session='.$sessionId);
}
exit;
}
// Display the header
Display::display_header($tool_name);
if ($add_type === 'multiple') {
$link_add_type_unique = ''.
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'';
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').' ';
} else {
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').' ';
$link_add_type_multiple = ''.
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'';
}
// the form header
$session_info = SessionManager::fetch($sessionId);
echo '
';
echo $link_add_type_unique.$link_add_type_multiple;
echo '
';
$ajax_search = $add_type === 'unique' ? true : false;
$nosessionCourses = $sessionCourses = [];
if ($ajax_search) {
$sql = "SELECT course.id, code, title, visual_code, session_id
FROM $tbl_course course
INNER JOIN $tbl_session_rel_course session_rel_course
ON
course.id = session_rel_course.c_id AND
session_rel_course.session_id = $sessionId
ORDER BY ".(count($courses) ? "(code IN (".implode(',', $courses).")) DESC," : '')." title";
if (api_is_multiple_url_enabled()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT course.id, code, title, visual_code, session_id
FROM $tbl_course course
INNER JOIN $tbl_session_rel_course session_rel_course
ON course.id = session_rel_course.c_id AND session_rel_course.session_id = $sessionId
INNER JOIN $tbl_course_rel_access_url url_course
ON (url_course.c_id = course.id)
WHERE access_url_id = $access_url_id
ORDER BY ".(count($courses) ? " (code IN(".implode(',', $courses).")) DESC," : '')." title";
}
}
$result = Database::query($sql);
$Courses = Database::store_result($result);
foreach ($Courses as $course) {
$sessionCourses[$course['id']] = $course;
}
} else {
$sql = "SELECT course.id, code, title, visual_code, session_id
FROM $tbl_course course
LEFT JOIN $tbl_session_rel_course session_rel_course
ON
course.id = session_rel_course.c_id AND
session_rel_course.session_id = $sessionId
ORDER BY ".(count($courses) ? "(code IN(".implode(',', $courses).")) DESC," : '')." title";
if (api_is_multiple_url_enabled()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT course.id, code, title, visual_code, session_id
FROM $tbl_course course
LEFT JOIN $tbl_session_rel_course session_rel_course
ON
course.id = session_rel_course.c_id AND
session_rel_course.session_id = $sessionId
INNER JOIN $tbl_course_rel_access_url url_course
ON (url_course.c_id = course.id)
WHERE access_url_id = $access_url_id
ORDER BY ".(count($courses) ? "(code IN(".implode(',', $courses).")) DESC," : '')." title";
}
}
$result = Database::query($sql);
$Courses = Database::store_result($result);
foreach ($Courses as $course) {
if ($course['session_id'] == $sessionId) {
$sessionCourses[$course['id']] = $course;
} else {
$nosessionCourses[$course['id']] = $course;
}
}
}
if (!api_is_platform_admin() && api_is_teacher()) {
$coursesFromTeacher = CourseManager::getCoursesFollowedByUser(
api_get_user_id(),
COURSEMANAGER
);
foreach ($nosessionCourses as &$course) {
if (in_array($course['code'], array_keys($coursesFromTeacher))) {
continue;
} else {
unset($nosessionCourses[$course['id']]);
}
}
}
unset($Courses);
?>