From 6eb52091d83ffe6ab341eef22e689edb6c5162bf Mon Sep 17 00:00:00 2001 From: Carlos Vargas Date: Thu, 11 Feb 2010 14:04:43 -0500 Subject: [PATCH] In a special course, upon entering, the students must subscribe to the course CT#600 --- main/course_home/course_home.php | 10 ++++++++++ main/inc/lib/course.lib.php | 15 +++++++++++++++ user_portal.php | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/main/course_home/course_home.php b/main/course_home/course_home.php index 9bfb5cbd41..d91c96c500 100755 --- a/main/course_home/course_home.php +++ b/main/course_home/course_home.php @@ -153,6 +153,16 @@ $_course['official_code'] = $course_code; api_session_unregister('toolgroup'); +$is_speacialcourse = CourseManager::is_special_course($course_code); + +if ($is_speacialcourse==true){ + $autoreg=Security::remove_XSS($_GET['autoreg']); + if ($autoreg==1){ + CourseManager::subscribe_user($user_id, $course_code, $status = STUDENT); + } +} + + /* ----------------------------------------------------------- Is the user allowed here? diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index da39956276..dcb10261c1 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2179,4 +2179,19 @@ class CourseManager { Database::query($insert_sql,__FILE__,__LINE__); } } + public static function is_special_course($course_code){ + $tbl_course_field_value = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); + $tbl_course_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); + + $sql = "SELECT course_code FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf ON " . + " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 AND course_code='$course_code'"; + + $special_course_result = Database::query($sql, __FILE__, __LINE__); + + $affected_rows = Database::affected_rows(); + if (!empty($affected_rows)){ + return true; + } + + } } //end class CourseManager diff --git a/user_portal.php b/user_portal.php index f88fd48998..0b32dd03df 100644 --- a/user_portal.php +++ b/user_portal.php @@ -269,16 +269,16 @@ function display_special_courses ($user_id) { $user_id = intval($user_id); $special_course_list = array(); - $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); - $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_course_field = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD); - $tbl_course_field_value = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); - $tbl_user_course_category = Database :: get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); + $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_course_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); + $tbl_course_field_value = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); + $tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); // get course list auto-register $sql = "SELECT course_code FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf ON " . " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; - + $special_course_result = Database::query($sql, __FILE__, __LINE__); if(Database::num_rows($special_course_result)>0) { $special_course_list = array(); @@ -334,7 +334,7 @@ function display_special_courses ($user_id) { $course_visibility = $course['visibility']; if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) { - $course_title = ''.$course['title'].''; + $course_title = ''.$course['title'].''; } else { $course_title = $course['title']." ".get_lang('CourseClosed'); } @@ -407,9 +407,9 @@ function display_courses($user_id) { function display_courses_in_category($user_category_id) { global $_user; // table definitions - $TABLECOURS=Database::get_main_table(TABLE_MAIN_COURSE); - $TABLECOURSUSER=Database::get_main_table(TABLE_MAIN_COURSE_USER); - $TABLE_USER_COURSE_CATEGORY = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE); + $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $TABLE_USER_COURSE_CATEGORY = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD); $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);