'session_list.php', 'name' => get_lang('SessionList')); $interbreadcrumb[] = array( 'url' => 'resume_session.php?id_session='.$id_session, 'name' => get_lang('SessionOverview'), ); // Database Table Definitions $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $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('EditSessionCoursesByUser'); $id_user = intval($_GET['id_user']); if (empty($id_user) || empty($id_session)) { header('Location: resume_session.php?id_session='.$id_session); } if (!api_is_platform_admin()) { $sql = 'SELECT session_admin_id FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session; $rs = Database::query($sql); if (Database::result($rs, 0, 0) != $_user['user_id']) { api_not_allowed(true); } } $formSent = 0; $CourseList = $SessionList = array(); $courses = $sessions = array(); $noPHP_SELF = true; if (isset($_POST['formSent']) && $_POST['formSent']) { $formSent = $_POST['formSent']; $CourseList = isset($_POST['SessionCoursesList']) ? ($_POST['SessionCoursesList']) : null; if (!is_array($CourseList)) { $CourseList = array(); } $sql = "SELECT DISTINCT course.id FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course ON course.id = session_rel_course.c_id INNER JOIN $tbl_session_rel_course_rel_user as srcru ON (srcru.session_id = session_rel_course.session_id) WHERE user_id = $id_user AND session_rel_course.session_id = $id_session"; $rs = Database::query($sql); $existingCourses = Database::store_result($rs); if (empty($CourseList) && empty($existingCourses)) { Display::addFlash(Display::return_message(get_lang('NoCoursesForThisSession'), 'warning')); header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user); exit; } if (count($CourseList) == count($existingCourses)) { Display::addFlash(Display::return_message(get_lang('MaybeYouWantToDeleteThisUserFromSession'))); header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user); exit; } foreach ($CourseList as $enreg_course) { $exists = false; foreach ($existingCourses as $existingCourse) { if ($enreg_course == $existingCourse['id']) { $exists = true; } } if (!$exists) { $enreg_course = Database::escape_string($enreg_course); $sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE user_id = '".$id_user."' AND c_id='".$enreg_course."' AND session_id=$id_session"; $result = Database::query($sql); if (Database::affected_rows($result)) { //update session rel course table $sql = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE session_id='$id_session' AND c_id = '$enreg_course'"; Database::query($sql); } } } foreach ($existingCourses as $existingCourse) { if (!in_array($existingCourse['id'], $CourseList)) { $existingCourse = Database::escape_string($existingCourse['id']); $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user (session_id,c_id,user_id) VALUES ('$id_session','$existingCourse','$id_user')"; $result = Database::query($sql); if (Database::affected_rows($result)) { //update session rel course table $sql = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE session_id='$id_session' AND c_id = '$existingCourse'"; Database::query($sql); } } } Display::addFlash(Display::return_message(get_lang('CoursesUpdated'))); header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user); exit; } Display::display_header($tool_name); // the form header $session_info = SessionManager::fetch($id_session); $user_info = api_get_user_info($id_user); echo ''; $nosessionCourses = $sessionCourses = array(); // actual user $sql = "SELECT course.id, code, title, visual_code, srcru.session_id FROM $tbl_course course INNER JOIN $tbl_session_rel_course_rel_user as srcru ON course.id = srcru.c_id WHERE srcru.user_id = $id_user AND session_id = $id_session"; //all $sql_all = "SELECT course.id, code, title, visual_code, src.session_id FROM $tbl_course course INNER JOIN $tbl_session_rel_course as src ON course.id = src.c_id AND session_id = $id_session"; $result = Database::query($sql); $Courses = Database::store_result($result); $result = Database::query($sql_all); $CoursesAll = Database::store_result($result); $course_temp = array(); foreach ($Courses as $course) { $course_temp[] = $course['id']; } foreach ($CoursesAll as $course) { if (in_array($course['id'], $course_temp)) { $nosessionCourses[$course['id']] = $course; } else { $sessionCourses[$course['id']] = $course; } } unset($Courses); ?>