From 512c20a42705b9b1c91b4c3dca8593f0b10b35e1 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 27 Feb 2015 11:43:48 +0100 Subject: [PATCH] Remove unused code. (virtual course) --- main/admin/course_virtual.php | 390 ---------------------------------- main/inc/lib/course.lib.php | 89 +------- 2 files changed, 4 insertions(+), 475 deletions(-) delete mode 100755 main/admin/course_virtual.php diff --git a/main/admin/course_virtual.php b/main/admin/course_virtual.php deleted file mode 100755 index e68078d3ad..0000000000 --- a/main/admin/course_virtual.php +++ /dev/null @@ -1,390 +0,0 @@ - 'index.php',"name" => get_lang('PlatformAdmin')); - -Display::display_header($tool_name); - -/* -============================================================================== - DISPLAY FUNCTIONS -============================================================================== -*/ - -function make_strong($text) -{ - return "" . $text . ""; -} - - -/** -* Return a list of language directories. -* @todo function does not belong here, move to code library, -* also see infocours.php and index.php which contain a similar function -*/ -function get_language_folder_list($dirname) -{ - if($dirname[strlen($dirname)-1]!='/') $dirname.='/'; - $handle=opendir($dirname); - while ($entries = readdir($handle)) - { - if ($entries=='.' || $entries=='..' || $entries=='CVS') continue; - if (is_dir($dirname.$entries)) - { - $language_list[] = $entries; - } - } - closedir($handle); - return $language_list; -} - -/** -* Displays a select element (drop down menu) so the user can select -* the course language. -* @todo function does not belong here, move to (display?) library, -* @todo language display used apparently no longer existing array, converted to english for now. -* but we should switch to display the real language names. -*/ -function display_language_select($element_name) -{ - global $platformLanguage; - - //get language list - $dirname = api_get_path(SYS_PATH)."main/lang/"; - $language_list = get_language_folder_list($dirname); - sort($language_list); - - //build array with strings to display - foreach ($language_list as $this_language) - { - $language_to_display[$this_language] = $this_language; - } - - //sort alphabetically - //warning: key,value association needs to be maintained --> asort instead of sort - asort($language_to_display); - - $user_selected_language = $_SESSION["user_language_choice"]; - if (! isset($user_selected_language) ) $user_selected_language = $platformLanguage; - - //display - echo ""; -} - -/** -* This code creates a select form element to let the user -* choose a real course to link to. -* -* We display the course code, but internally store the course id. -*/ -function display_real_course_code_select($element_name) -{ - $real_course_list = CourseManager::get_real_course_list(); - - echo "\n"; -} - - -function display_create_virtual_course_form() -{ - global $charset; - - $category_table = Database::get_main_table(TABLE_MAIN_CATEGORY); - - $message = make_strong(get_lang('AdminCreateVirtualCourse')) . "
" . get_lang('AdminCreateVirtualCourseExplanation') . "
This feature is in development phase, bug reports welcome."; - ?> -

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- "; - echo ""; - echo "
".get_lang('Ex') ; - ?> -
- "; - - $sql_query = "SELECT code, name - FROM $category_table - WHERE auth_course_child ='TRUE' - ORDER BY tree_pos"; - $category_result = Database::query($sql_query); - - while ($current_category = Database::fetch_array($category_result)) - { - echo "\n"; - } - ?> - -
-
- -
" . get_lang('Max'); - ?> -
- - - "; - ?> -
- - - -
- - -
-
-
  • ".get_lang('CreateVirtualCourse')."
  • "; - $message .= "
  • ".get_lang('DisplayListVirtualCourses')."
  • "; - echo $message; -} - -function display_virtual_course_list() -{ - $course_list = CourseManager::get_virtual_course_list(); - if (! is_array($course_list) ) - { - //there are no virtual courses - echo "".get_lang('ThereAreNoVirtualCourses').""; - return; - } - - $column_header[] = array(get_lang('Title'),true); - $column_header[] = array(get_lang('Code'),true); - $column_header[] = array(get_lang('VisualCode'),true); - $column_header[] = array(get_lang('LinkedCourseTitle'),true); - $column_header[] = array(get_lang('LinkedCourseCode'),true); - $table_data = array(); - for($i = 0; $i < count($course_list); $i++) - { - $course_list[$i] = Database::generate_abstract_course_field_names($course_list[$i]); - $target_course_code = $course_list[$i]["target_course_code"]; - $real_course_info = Database::get_course_info($target_course_code); - - $row = array(); - $row[] = $course_list[$i]["title"]; - $row[] = $course_list[$i]["system_code"]; - $row[] = $course_list[$i]["visual_code"]; - $row[] = $real_course_info["title"]; - $row[]= $real_course_info["system_code"]; - $table_data[] = $row; - } - Display::display_sortable_table($column_header,$table_data,array(),array(),array('action'=>$_GET['action'])); -} - - -/* -============================================================================== - TOOL LOGIC FUNCTIONS -============================================================================== -*/ - -/** -* Checks all parameters needed to create a virtual course. -* If they are all set, the virtual course creation procedure is called. -* Call this function instead of create_virtual_course -*/ -function attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category) -{ - //better: create parameter list, check the entire list, when false display errormessage - CourseManager::check_parameter_or_fail($real_course_code, "Unspecified parameter: real course id."); - CourseManager::check_parameter_or_fail($course_title, "Unspecified parameter: course title."); - CourseManager::check_parameter_or_fail($wanted_course_code, "Unspecified parameter: wanted course code."); - CourseManager::check_parameter_or_fail($course_language, "Unspecified parameter: course language."); - CourseManager::check_parameter_or_fail($course_category, "Unspecified parameter: course category."); - - $message = get_lang('AttemptedCreationVirtualCourse') . "
    "; - $message .= get_lang('CourseTitle') . " " . $course_title . "
    "; - $message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "
    "; - $message .= get_lang('CourseLanguage') . " " . $course_language . "
    "; - $message .= get_lang('CourseFaculty') . " " . $course_category . "
    "; - $message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "
    "; - - Display::display_normal_message($message); - - $creation_success = CourseManager::create_virtual_course( $real_course_code, $course_title, $wanted_course_code, $course_language, $course_category ); - - if ($creation_success) - { - Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') ); - return true; - } - return false; -} - -/* -============================================================================== - MAIN CODE -============================================================================== -*/ - -$action = $_GET["action"]; -$attempt_create_virtual_course = $_POST["submit_create_virtual_course"]; - -//api_display_tool_title($tool_name); - -if ( isset($attempt_create_virtual_course) && $attempt_create_virtual_course ) -{ - $real_course_code = $_POST[REAL_COURSE_SELECT_FORM_NAME]; - $course_title = $_POST[COURSE_TITLE_FORM_NAME]; - $wanted_course_code = $_POST[WANTED_COURSE_CODE_FORM_NAME]; - $course_language = $_POST[LANGUAGE_SELECT_FORM_NAME]; - $course_category = $_POST[COURSE_CATEGORY_FORM_NAME]; - - $message = get_lang('AttemptedCreationVirtualCourse') . "
    "; - $message .= get_lang('CourseTitle') . " " . $course_title . "
    "; - $message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "
    "; - $message .= get_lang('CourseLanguage') . " " . $course_language . "
    "; - $message .= get_lang('CourseFaculty') . " " . $course_category . "
    "; - $message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "
    "; - - Display::display_normal_message($message); - - $creation_success = CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category); - - if ($creation_success) - { - Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') ); - } - else - { - //should display error message - } - echo "
    "; -} - - -display_main_options(); - -switch($action) -{ - case CREATE_VIRTUAL_COURSE_OPTION: - display_create_virtual_course_form(); - break; - case DISPLAY_VIRTUAL_COURSE_LIST_OPTION: - display_virtual_course_list(); - break; -} - -/* -============================================================================== - FOOTER -============================================================================== -*/ -Display::display_footer(); -?> diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 3275a7b4bb..c8c90e7212 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -997,7 +997,7 @@ class CourseManager } $real_course_id = $course_info['system_code']; - $real_course_info = Database::get_course_info($real_course_id); + $real_course_info = api_get_course_info($real_course_id); $real_course_name = $real_course_info['title']; $real_course_visual_code = $real_course_info['visual_code']; $real_course_real_code = Database::escape_string($course_info['system_code']); @@ -2099,87 +2099,6 @@ class CourseManager return $group_list; } - /** - * Checks all parameters needed to create a virtual course. - * If they are all set, the virtual course creation procedure is called. - * - * Call this function instead of create_virtual_course - * @param string Course code - * @param string Course title - * @param string Wanted course code - * @param string Course language - * @param string Course category - * @return bool True on success, false on error - * @deprecated virtual course feature is not supported - */ - public static function attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category) { - //better: create parameter list, check the entire list, when false display errormessage - self::check_parameter_or_fail($real_course_code, 'Unspecified parameter: real course id.'); - self::check_parameter_or_fail($course_title, 'Unspecified parameter: course title.'); - self::check_parameter_or_fail($wanted_course_code, 'Unspecified parameter: wanted course code.'); - self::check_parameter_or_fail($course_language, 'Unspecified parameter: course language.'); - self::check_parameter_or_fail($course_category, 'Unspecified parameter: course category.'); - - return self::create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category); - } - - /** - * This function creates a virtual course. - * It assumes all parameters have been checked and are not empty. - * It checks wether a course with the $wanted_course_code already exists. - * - * Users of this library should consider this function private, - * please call attempt_create_virtual_course instead of this one. - * - * note: The virtual course 'owner' id (the first course admin) is set to the CURRENT user id. - * @param string Course code - * @param string Course title - * @param string Wanted course code - * @param string Course language - * @param string Course category - * @return true if the course creation succeeded, false otherwise - * @todo research: expiration date of a course - * @deprecated virtual course feature is not supported - */ - public static function create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category) { - global $firstExpirationDelay; - - $user_id = api_get_user_id(); - $real_course_info = Database::get_course_info($real_course_code); - $real_course_code = $real_course_info['system_code']; - - //check: virtual course creation fails if another course has the same - //code, real or fake. - if (self::course_code_exists($wanted_course_code)) { - Display::display_error_message($wanted_course_code.' - '.get_lang('CourseCodeAlreadyExists')); - return false; - } - - //add data to course table, course_rel_user - $course_sys_code = $wanted_course_code; - $course_screen_code = $wanted_course_code; - $course_repository = $real_course_info['directory']; - $course_db_name = $real_course_info['db_name']; - $responsible_teacher = $real_course_info['tutor_name']; - $faculty_shortname = $course_category; - // $course_title = $course_title; - // $course_language = $course_language; - $teacher_id = $user_id; - - //HACK ---------------------------------------------------------------- - $expiration_date = time() + $firstExpirationDelay; - //END HACK ------------------------------------------------------------ - - AddCourse::register_course($course_sys_code, $course_screen_code, $course_repository, $course_db_name, $responsible_teacher, $faculty_shortname, $course_title, $course_language, $teacher_id, $expiration_date); - - //above was the normal course creation table update call, - //now one more thing: fill in the target_course_code field - Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_COURSE)." SET target_course_code = '$real_course_code' - WHERE code = '".Database::escape_string($course_sys_code)."' LIMIT 1 "); - - return true; - } - /** * Delete a course * This function deletes a whole course-area from the platform. When the @@ -2634,7 +2553,7 @@ class CourseManager $codes = array(); $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $tbl_user_course_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $special_course_list = self::get_special_course_list(); $with_special_courses = $without_special_courses = ''; @@ -3677,7 +3596,7 @@ class CourseManager } // Step 1: We get all the categories of the user - $tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $sql = "SELECT id, title FROM $tucc WHERE user_id='".$user_id."' ORDER BY sort ASC"; $result = Database::query($sql); $html = null; @@ -3874,7 +3793,7 @@ class CourseManager { global $_user; $output = array(); - $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $sql = "SELECT * FROM ".$table_category." WHERE user_id='".intval($_user['user_id'])."'"; $result = Database::query($sql); while ($row = Database::fetch_array($result)) {