diff --git a/lib/questionlib.php b/lib/questionlib.php index ccbc2c74eeb..0ea1b4c0c0e 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -555,6 +555,25 @@ function question_delete_course($course, $feedback=true) { return true; } +function questionbank_navigation_tabs(&$row, $context, $courseid) { + global $CFG; + if (has_capability('moodle/question:manage', $context)) { + $row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$courseid", get_string('questions', 'quiz'), get_string('editquestions', "quiz")); + } + + if (has_capability('moodle/question:managecategory', $context)) { + $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$courseid", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); + } + + if (has_capability('moodle/question:import', $context)) { + $row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?course=$courseid", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); + } + + if (has_capability('moodle/question:export', $context)) { + $row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$courseid", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); + } +} + /** * Private function to factor common code out of get_question_options(). * diff --git a/mod/quiz/tabs.php b/mod/quiz/tabs.php index 4d0f70c4ae7..8494c670de0 100644 --- a/mod/quiz/tabs.php +++ b/mod/quiz/tabs.php @@ -83,26 +83,10 @@ $strquizzes = get_string('modulenameplural', 'quiz'); $strquiz = get_string('modulename', 'quiz'); - $streditingquestions = get_string('editquestions', "quiz"); $streditingquiz = get_string("editinga", "moodle", $strquiz); $strupdate = get_string('updatethis', 'moodle', $strquiz); $row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", $strquiz, $streditingquiz); - - if (has_capability('moodle/question:manage', $context)) { - $row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$course->id", get_string('questions', 'quiz'), $streditingquestions); - } - - if (has_capability('moodle/question:managecategory', $context)) { - $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); - } - - if (has_capability('moodle/question:import', $context)) { - $row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); - } - - if (has_capability('moodle/question:export', $context)) { - $row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); - } + questionbank_navigation_tabs($row, $context, $course->id); $tabs[] = $row; } diff --git a/question/category_class.php b/question/category_class.php index e8815be290f..49ce7af4a68 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -189,7 +189,7 @@ class question_category_object { // wrap the table in a form and output it echo '
'; - echo '
'; + echo '
'; echo "sesskey\" />"; echo ''; echo ''; diff --git a/question/export.php b/question/export.php index 13d9575998a..f81d2952473 100644 --- a/question/export.php +++ b/question/export.php @@ -19,7 +19,7 @@ $exportfilename = optional_param('exportfilename','',PARAM_FILE ); $format = optional_param('format','', PARAM_FILE ); - + // get display strings $txt = new object; $txt->category = get_string('category','quiz'); @@ -32,32 +32,31 @@ $txt->exportcategory = get_string('exportcategory','quiz'); $txt->modulename = get_string('modulename','quiz'); $txt->modulenameplural = get_string('modulenameplural','quiz'); - $txt->nocategory = get_string('nocategory','quiz'); $txt->tofile = get_string('tofile','quiz'); - if (! $course = get_record("course", "id", $courseid)) { + if (!$course = get_record("course", "id", $courseid)) { error("Course does not exist!"); } - $showcatmenu = false; if ($categoryid) { // update category in session variable $SESSION->questioncat = $categoryid; } else { // try to get category from modform - $showcatmenu = true; // will ensure that user can choose category if (isset($SESSION->questioncat)) { $categoryid = $SESSION->questioncat; } } - $category = get_default_question_category($courseid); - - if (! $categorycourse = get_record("course", "id", $category->course)) { - error( $txt->nocategory ); + if (!$category = get_record("question_categories", "id", $categoryid)) { + $category = get_default_question_category($courseid); + } + + if (!$categorycourse = get_record("course", "id", $category->course)) { + print_error('nocategory','quiz'); } require_login($course->id, false); - + // check role capability $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/question:export', $context); @@ -95,8 +94,8 @@ error( "Format not known ($format)" ); } // load parent class for import/export - require("format.php"); - + require("format.php"); + // and then the class for the selected format require("format/$format/format.php"); @@ -148,55 +147,49 @@ } print_heading_with_help($txt->exportquestions, 'export', 'quiz'); - print_simple_box_start('center'); -?> + print_simple_box_start('center'); +?> -
- - - +
+ + + - - - - - - - - - - - - - -
category; ?>: - '.question_category_coursename($category).'  '; ?> - - id, true, false, $category->id); - } - echo $txt->tofile; ?> - - exportcategory, 'quiz'); ?> -
fileformat; ?>: - exportquestions, 'quiz'); ?> -
exportname; ?>: - -
- -  
-
- + id, true, false, $category->id); + echo $txt->tofile; ?> + + exportcategory, 'quiz'); ?> + + + + fileformat; ?>: + + exportquestions, 'quiz'); ?> + + + + exportname; ?>: + + + + + + + + +   + + +
+ diff --git a/question/import.php b/question/import.php index 6a5900f5a1a..76947665cfe 100644 --- a/question/import.php +++ b/question/import.php @@ -43,7 +43,6 @@ $txt->matchgradesnearest = get_string('matchgradesnearest','quiz'); $txt->modulename = get_string('modulename','quiz'); $txt->modulenameplural = get_string('modulenameplural','quiz'); - $txt->nocategory = get_string('nocategory','quiz'); $txt->onlyteachersimport = get_string('onlyteachersimport','quiz'); $txt->questions = get_string("questions", "quiz"); $txt->quizzes = get_string('modulenameplural', 'quiz'); @@ -60,18 +59,17 @@ if ($categoryid) { // update category in session variable $SESSION->questioncat = $categoryid; } else { // try to get category from modform - $showcatmenu = true; // will ensure that user can choose category if (isset($SESSION->questioncat)) { $categoryid = $SESSION->questioncat; } } - if (! $category = get_record("question_categories", "id", $categoryid)) { + if (!$category = get_record("question_categories", "id", $categoryid)) { // if no valid category was given, use the default category if ($courseid) { $category = get_default_question_category($courseid); } else { - error( $txt->nocategory ); + print_error('nocategory','quiz'); } } @@ -79,13 +77,14 @@ $courseid = $category->course; } - if (! $course = get_record("course", "id", $courseid)) { + if (!$course = get_record("course", "id", $courseid)) { error("Invalid course!"); } require_login($course->id, false); - require_capability('moodle/question:import', get_context_instance(CONTEXT_COURSE, $course->id)); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + require_capability('moodle/question:import', $context); // ensure the files area exists for this course make_upload_directory( "$course->id" ); @@ -96,7 +95,7 @@ //========== if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { - $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) + $strupdatemodule = has_capability('moodle/course:manageactivities', $context) ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename) : ""; print_header_simple($txt->importquestions, '', @@ -209,7 +208,7 @@ ?>
-
+
diff --git a/question/showbank.php b/question/showbank.php index 02ff828732d..d234e983da3 100644 --- a/question/showbank.php +++ b/question/showbank.php @@ -141,8 +141,8 @@ redirect("edit.php?courseid=$course->id"); } - if (isset($_REQUEST['cat'])) { /// coming from category selection drop-down menu - $SESSION->questioncat = required_param('cat', PARAM_INT); + if ($categoryid = optional_param('cat', 0, PARAM_INT)) { /// coming from category selection drop-down menu + $SESSION->questioncat = $categoryid; $page = 0; $SESSION->questionpage = 0; } diff --git a/question/tabs.php b/question/tabs.php index e34c0de2327..7aafe850bf7 100644 --- a/question/tabs.php +++ b/question/tabs.php @@ -16,16 +16,11 @@ } $tabs = array(); - $row = array(); $inactive = array(); - - $row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$course->id", get_string('questions', 'quiz'), get_string('editquizquestions', 'quiz')); - $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); - $row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); - $row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); - + $row = array(); + questionbank_navigation_tabs($row, $context, $course->id); $tabs[] = $row; - print_tabs($tabs, $currenttab, $inactive); + print_tabs($tabs, $currenttab, array()); ?>