'index.php', 'name' => get_lang('PlatformAdmin')); $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); } 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; $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 code FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course ON course.code = session_rel_course.course_code 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 $enreg_course) { $exists = false; foreach($existingCourses as $existingCourse) { if($enreg_course == $existingCourse['course_code']) { $exists=true; } } if(!$exists) { $enreg_course = Database::escape_string($enreg_course); $sql_delete = "DELETE FROM $tbl_session_rel_course_rel_user WHERE id_user='".$id_user."' AND course_code='".$enreg_course."' AND id_session=$id_session"; Database::query($sql_delete); if (Database::affected_rows()) { //update session rel course table $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE id_session='$id_session' AND course_code='$enreg_course'"; Database::query($sql_update); } } } foreach($existingCourses as $existingCourse) { //$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code, id_coach) VALUES('$id_session','$enreg_course','$id_coach')"; if(!in_array($existingCourse['code'], $CourseList)){ $existingCourse = Database::escape_string($existingCourse['code']); $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$existingCourse','$id_user')"; Database::query($sql_insert); if(Database::affected_rows()) { //update session rel course table $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE id_session='$id_session' AND course_code='$existingCourse'"; 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 ''.$tool_name.': '.$session_info['name'].' - '.$user_info['complete_name'].''; $nosessionCourses = $sessionCourses = array(); // actual user $sql = "SELECT 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 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['code']; } foreach($CoursesAll as $course) { if (in_array($course['code'], $course_temp)) { $nosessionCourses[$course['code']] = $course ; } else { $sessionCourses[$course['code']] = $course ; } } unset($Courses); ?>
:   :








'.get_lang('EditSessionCourses').''; ?>