'index.php', 'name' => get_lang('Sessions')); $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList')); $interbreadcrumb[] = array('url' => 'resume_session.php?id_session='.Security::remove_XSS($_GET['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); exit; } $formSent=0; $errorMsg=$firstLetterCourse=$firstLetterSession=''; $CourseList=$SessionList=array(); $courses=$sessions=array(); $noPHP_SELF=true; if ($_POST['formSent']) { $formSent = $_POST['formSent']; $CourseList = $_POST['SessionCoursesList']; 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.id_session = session_rel_course.id_session) WHERE id_user = $id_user and session_rel_course.id_session = $id_session"; $rs = Database::query($sql); $existingCourses = Database::store_result($rs); if (count($CourseList) == count($existingCourses)) { header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('MaybeYouWantToDeleteThisUserFromSession')); exit; } foreach ($CourseList as $courseId) { $exists = false; foreach($existingCourses as $existingCourse) { if ($enreg_course == $existingCourse['id']) { $exists=true; } } if (!$exists) { $courseId = Database::escape_string($courseId); $sql_delete = "DELETE FROM $tbl_session_rel_course_rel_user WHERE id_user='".$id_user."' AND c_id ='".$courseId."' AND id_session = $id_session"; $result = Database::query($sql_delete); if (Database::affected_rows($result)) { //update session rel course table $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE id_session='$id_session' AND c_id = '$courseId'"; Database::query($sql_update); } } } foreach ($existingCourses as $existingCourse) { if(!in_array($existingCourse['id'], $CourseList)) { $courseId = Database::escape_string($existingCourse['id']); $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,c_id,id_user) VALUES('$id_session','$courseId','$id_user')"; $result = Database::query($sql_insert); if (Database::affected_rows($result)) { //update session rel course table $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE id_session='$id_session' AND c_id='$courseId'"; Database::query($sql_update); } } } header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('CoursesUpdated')); exit; } // display the dokeos header Display::display_header($tool_name); if (!empty($_GET['msg'])) { Display::display_normal_message(urldecode($_GET['msg'])); } // 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, course.code, title, visual_code, srcru.id_session FROM $tbl_course course inner JOIN $tbl_session_rel_course_rel_user as srcru ON course.code = srcru.course_code WHERE srcru.id_user = $id_user AND id_session = $id_session"; //all $sql_all="SELECT course.id, code, title, visual_code, src.id_session " . "FROM $tbl_course course inner JOIN $tbl_session_rel_course as src " . "ON course.code = src.course_code AND id_session = $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); ?>