From 028686d65273ebca40eb34a3e04552ab382b514a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 21 Jun 2013 14:49:30 +0200 Subject: [PATCH] Fixing export/import course bugs. --- .../classes/CourseBuilder.class.php | 34 ++++++++----- .../classes/CourseRestorer.class.php | 50 +++++++++---------- .../coursecopy/classes/QuizQuestion.class.php | 3 +- main/coursecopy/create_backup.php | 1 + main/inc/lib/exercise.lib.php | 2 +- main/inc/lib/security.lib.php | 1 - 6 files changed, 49 insertions(+), 42 deletions(-) diff --git a/main/coursecopy/classes/CourseBuilder.class.php b/main/coursecopy/classes/CourseBuilder.class.php index 71578f34c2..62888f3433 100644 --- a/main/coursecopy/classes/CourseBuilder.class.php +++ b/main/coursecopy/classes/CourseBuilder.class.php @@ -153,7 +153,6 @@ class CourseBuilder $this->build_glossary(); $this->build_thematic(); $this->build_attendance();*/ - } //TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently @@ -276,7 +275,8 @@ class CourseBuilder /** * Build the forums */ - function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { + function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) + { $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -294,7 +294,8 @@ class CourseBuilder /** * Build a forum-category */ - function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { + function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) + { $table = Database :: get_course_table(TABLE_FORUM_CATEGORY); $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -310,7 +311,8 @@ class CourseBuilder /** * Build the forum-topics */ - function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) { + function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) + { $table = Database :: get_course_table(TABLE_FORUM_THREAD); $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -328,7 +330,8 @@ class CourseBuilder * Build the forum-posts * TODO: All tree structure of posts should be built, attachments for example. */ - function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false) { + function build_forum_posts($thread_id = null, $forum_id = null, $only_first_post = false) + { $table = Database :: get_course_table(TABLE_FORUM_POST); $course_id = api_get_course_int_id(); $sql = "SELECT * FROM $table WHERE c_id = $course_id "; @@ -348,7 +351,8 @@ class CourseBuilder /** * Build the links */ - function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { + function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) + { $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -393,7 +397,8 @@ class CourseBuilder /** * Build tool intro */ - function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { + function build_tool_intro($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) + { $table = Database :: get_course_table(TABLE_TOOL_INTRO); $course_id = api_get_course_int_id(); $sql = "SELECT * FROM $table WHERE c_id = $course_id "; @@ -407,7 +412,8 @@ class CourseBuilder /** * Build a link category */ - function build_link_category($id, $course_code = '') { + function build_link_category($id, $course_code = '') + { $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -426,7 +432,8 @@ class CourseBuilder /** * Build the Quizzes */ - function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { + function build_quizzes($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) + { $course_info = api_get_course_info($course_code); $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); @@ -477,7 +484,8 @@ class CourseBuilder /** * Build the Quiz-Questions */ - function build_quiz_questions($course_code = null) { + function build_quiz_questions($course_code = null) + { $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -603,7 +611,8 @@ class CourseBuilder /** * Build the orphan questions */ - function build_quiz_orphan_questions() { + function build_quiz_orphan_questions() + { $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION); @@ -642,7 +651,8 @@ class CourseBuilder /** * Build the Surveys */ - function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) { + function build_surveys($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) + { $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $course_id = api_get_course_int_id(); diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 1bafcbcbd4..245cb1ec17 100644 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -1469,7 +1469,7 @@ class CourseRestorer 'c_id' => $this->destination_course_id, 'title' => self::DBUTF8($quiz->title), 'description' => self::DBUTF8($quiz->description), - 'type' => $quiz->type, + 'type' => $quiz->quiz_type, 'random' => $quiz->random, 'active' => $quiz->active, 'sound' => self::DBUTF8($doc), @@ -1506,17 +1506,16 @@ class CourseRestorer $new_id = -1; } - if ($new_id) { + if ($new_id && $new_id != -1) { // Updates the question position $exercise = new Exercise($this->destination_course_id); $exercise->read($new_id); - if ($new_id != -1) { - $exercise->addExerciseToOrderTable(); - } - + $exercise->addExerciseToOrderTable(); $this->course->resources[RESOURCE_QUIZ][$id]->obj->destination_id = $new_id; + $order = 0; + if (!empty($quiz->question_ids)) { foreach ($quiz->question_ids as $index => $question_id) { $qid = $this->restore_quiz_question($question_id); @@ -1582,7 +1581,11 @@ class CourseRestorer $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); // check resources inside html from fckeditor tool and copy correct urls into recipient course - $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path); + $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( + $question->description, + $this->course->code, + $this->course->destination_path + ); $parent_id = 0; @@ -1609,7 +1612,7 @@ class CourseRestorer description = '".self::DBUTF8escapestring($question->description)."', ponderation = '".self::DBUTF8escapestring($question->ponderation)."', position = '".self::DBUTF8escapestring($question->position)."', - type='".self::DBUTF8escapestring($question->type)."', + type='".self::DBUTF8escapestring($question->quiz_type)."', picture='".self::DBUTF8escapestring($question->picture)."', level='".self::DBUTF8escapestring($question->level)."', parent_id ='".$parent_id."', @@ -1735,7 +1738,6 @@ class CourseRestorer $question_option_id = Database::insert($table_options, $item); $new_options[$obj->obj->iid] = $question_option_id; } - //var_dump($new_options, $correct_answers); foreach ($correct_answers as $answer_id => $correct_answer) { $params = array(); $params['correct'] = $new_options[$correct_answer]; @@ -1749,26 +1751,20 @@ class CourseRestorer $cats = array(); foreach ($question->categories as $cat) { $new_category = new Testcategory($cat['category_id']); - /* $new_category = new Testcategory($cat['category_id']); - var_dump($new_category->title, $cat['title']); - if ($new_category && $new_category->title == $cat['title']) { - $cats[] = $cat['category_id']; - } else {*/ - $new_category = $new_category->get_category_by_title($cat['title'], $this->destination_course_id); - if (empty($new_category)) { - //Create a new category in this portal - if ($cat['category_id'] == 0) { - $category_c_id = 0; - } else { - $category_c_id = $this->destination_course_id; - } - $new_cat = new Testcategory(null, $cat['title'], $cat['description'], null, 'simple', $category_c_id); - $new_cat_id = $new_cat->addCategoryInBDD(); - $cats[] = $new_cat_id; + $new_category = $new_category->get_category_by_title($cat['title'], $this->destination_course_id); + if (empty($new_category)) { + //Create a new category in this portal + if ($cat['category_id'] == 0) { + $category_c_id = 0; } else { - $cats[] = $new_category['iid']; + $category_c_id = $this->destination_course_id; } - //} + $new_cat = new Testcategory(null, $cat['title'], $cat['description'], null, 'simple', $category_c_id); + $new_cat_id = $new_cat->addCategoryInBDD(); + $cats[] = $new_cat_id; + } else { + $cats[] = $new_category['iid']; + } } $question = Question::read($new_id, $this->destination_course_id); diff --git a/main/coursecopy/classes/QuizQuestion.class.php b/main/coursecopy/classes/QuizQuestion.class.php index 72b028abb9..62b772e8cc 100644 --- a/main/coursecopy/classes/QuizQuestion.class.php +++ b/main/coursecopy/classes/QuizQuestion.class.php @@ -78,10 +78,11 @@ class QuizQuestion extends Resource function QuizQuestion($id, $question, $description, $ponderation, $type, $position, $picture, $level, $extra, $parent_info, $categories) { parent::Resource($id, RESOURCE_QUIZQUESTION); + $this->question = $question; $this->description = $description; $this->ponderation = $ponderation; - $this->type = $type; + $this->quiz_type = $type; $this->position = $position; $this->picture = $picture; $this->level = $level; diff --git a/main/coursecopy/create_backup.php b/main/coursecopy/create_backup.php index 06b115c190..ee29c32624 100644 --- a/main/coursecopy/create_backup.php +++ b/main/coursecopy/create_backup.php @@ -55,6 +55,7 @@ echo Display::page_header($nameTools); if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) { if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') { $course = CourseSelectForm::get_posted_course(); + } else { $cb = new CourseBuilder(); $course = $cb->build(); diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index a4cc15da94..6f6da7cd80 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -237,7 +237,7 @@ class ExerciseLib } } - $answer = Security::remove_XSS($answer, STUDENT); + $answer = Security::remove_XSS($answer); $s .= Display::input('hidden', 'choice2['.$questionId.']', '0'); $answer_input = null; diff --git a/main/inc/lib/security.lib.php b/main/inc/lib/security.lib.php index 309185670a..61ef823929 100644 --- a/main/inc/lib/security.lib.php +++ b/main/inc/lib/security.lib.php @@ -321,7 +321,6 @@ class Security } } - /** * * Filter content