From 978284623531ce8cb4560e7d011b6028b39367d6 Mon Sep 17 00:00:00 2001
From: thepurpleblob <thepurpleblob>
Date: Thu, 26 Jul 2007 10:56:13 +0000
Subject: [PATCH] MDL-9123: Check that the selected category is allowed.

Merged from STABLE_18
---
 question/import.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/question/import.php b/question/import.php
index 476f524a3d..782f0e6403 100644
--- a/question/import.php
+++ b/question/import.php
@@ -62,10 +62,14 @@
         print_error('nocategory','quiz');
     }
 
-    if (!$courseid) { // need to get the course from the chosen category
-        $courseid = $category->course;
+    // check category is valid (against THIS courseid, before we change it)
+    $validcats = question_category_options( $courseid, true, true );
+    if (!array_key_exists( $categoryid, $validcats )) {
+        print_error( 'invalidcategory', 'quiz' );
     }
 
+    $courseid = $category->course;
+
     if (!$course = get_record("course", "id", $courseid)) {
         error("Invalid course!");
     }
-- 
2.39.5