From: tjhunt <tjhunt>
Date: Tue, 20 May 2008 17:09:40 +0000 (+0000)
Subject: MDL-14928 - Adding random questions from a category with an apostrophe in the name... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=949c59ace0f0f2a4e63bb1bdd7133dd84114048e;p=moodle.git

MDL-14928 - Adding random questions from a category with an apostrophe in the name does not work. Stupid bloody addslashes. Roll on dmllib 2.0.
---

diff --git a/question/category_class.php b/question/category_class.php
index 0469f2e5b2..732f38eb76 100644
--- a/question/category_class.php
+++ b/question/category_class.php
@@ -416,9 +416,9 @@ class question_category_object {
         //never move category where it is the default
         if (1 != count_records_sql("SELECT count(*) FROM {$CFG->prefix}question_categories c1, {$CFG->prefix}question_categories c2 WHERE c2.id = $updateid AND c1.contextid = c2.contextid")){
             // If the question name has changed, rename any random questions in that category.
-            if ($oldcat->name != $cat->name) {
+            if (addslashes($oldcat->name) != $cat->name) {
                 $randomqname = $QTYPES[RANDOM]->question_name($cat);
-                set_field('question', 'name', $randomqname, 'category', $cat->id, 'qtype', RANDOM);
+                set_field('question', 'name', addslashes($randomqname), 'category', $cat->id, 'qtype', RANDOM);
                 // Ignore errors here. It is not a big deal if the questions are not renamed.
             }
 
diff --git a/question/type/random/questiontype.php b/question/type/random/questiontype.php
index 239e43d28d..75ab2da7b4 100644
--- a/question/type/random/questiontype.php
+++ b/question/type/random/questiontype.php
@@ -57,7 +57,7 @@ class random_qtype extends default_questiontype {
             print_error('cannotretrieveqcat', 'question');
         }
         $question->name = $this->question_name($category);
-        if (!set_field('question', 'name', $question->name, 'id', $question->id)) {
+        if (!set_field('question', 'name', addslashes($question->name), 'id', $question->id)) {
             print_error('cannotupdaterandomqname', 'question');
         }
         return $question;