diff --git a/question/export.php b/question/export.php index e53c088a901..294e12df026 100644 --- a/question/export.php +++ b/question/export.php @@ -2,7 +2,11 @@ /** * Export quiz questions into the given category * +<<<<<<< export.php * @version $Id$ +======= +* @version $Id$ +>>>>>>> 1.22.2.2 * @author Martin Dougiamas, Howard Miller, and many others. * {@link http://moodle.org} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License @@ -12,10 +16,29 @@ require_once("../config.php"); require_once( "editlib.php" ); + // get parameters $categoryid = optional_param('category',0, PARAM_INT); + $cattofile = optional_param('cattofile',0, PARAM_BOOL); $courseid = required_param('courseid',PARAM_INT); - $format = optional_param('format','', PARAM_FILE ); $exportfilename = optional_param('exportfilename','',PARAM_FILE ); + $format = optional_param('format','', PARAM_FILE ); + + + // get display strings + $txt = new object; + $txt->category = get_string('category','quiz'); + $txt->download = get_string('download','quiz'); + $txt->downloadextra = get_string('downloadextra','quiz'); + $txt->exporterror = get_string('exporterror','quiz'); + $txt->exportname = get_string('exportname','quiz'); + $txt->exportquestions = get_string('exportquestions', 'quiz'); + $txt->fileformat = get_string('fileformat','quiz'); + $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)) { error("Course does not exist!"); @@ -36,41 +59,33 @@ } if (! $categorycourse = get_record("course", "id", $category->course)) { - error( get_string('nocategory','quiz') ); + error( $txt->nocategory ); } require_login($course->id, false); + // check role capability $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/question:export', $context); // ensure the files area exists for this course make_upload_directory( "$course->id" ); - $strexportquestions = get_string("exportquestions", "quiz"); - $strquestions = get_string("questions", "quiz"); - - $strquizzes = get_string('modulenameplural', 'quiz'); - $streditingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz"); - - $dirname = get_string("exportfilename","quiz"); - - /// Header: - + /// Header if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { $strupdatemodule = has_capability('moodle/course:manageactivities', $context) - ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz')) + ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename ) : ""; - print_header_simple($strexportquestions, '', - "wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').''. - " -> wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).''. - ' -> '.$strexportquestions, - "", "", true, $strupdatemodule); + print_header_simple($txt->exportquestions, '', + "wwwroot/mod/quiz/index.php?id=$course->id\">$txt->modulenameplural". + " -> wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).''. + ' -> '.$txt->exportquestions, + "", "", true, $strupdatemodule); $currenttab = 'edit'; $mode = 'export'; include($CFG->dirroot.'/mod/quiz/tabs.php'); } else { - print_header_simple($strexportquestions, '', $strexportquestions); + print_header_simple($txt->exportquestions, '', $txt->exportquestions); // print tabs $currenttab = 'export'; include('tabs.php'); @@ -79,14 +94,16 @@ if (!empty($format)) { /// Filename if (!confirm_sesskey()) { - echo( 'Sesskey error' ); + print_error( 'sesskey' ); } if (! is_readable("format/$format/format.php")) { - error('Format not known ('.clean_text($form->format).')'); - } + error( "Format not known ($format)" ); } - require("format.php"); // Parent class + // load parent class for import/export + require("format.php"); + + // and then the class for the selected format require("format/$format/format.php"); $classname = "qformat_$format"; @@ -95,51 +112,53 @@ $qformat->setCategory( $category ); $qformat->setCourse( $course ); $qformat->setFilename( $exportfilename ); + $qformat->setCattofile( $cattofile ); if (! $qformat->exportpreprocess()) { // Do anything before that we need to - error( get_string('exporterror','quiz'), - "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); } if (! $qformat->exportprocess()) { // Process the export data - error( get_string('exporterror','quiz'), - "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); } if (! $qformat->exportpostprocess()) { // In case anything needs to be done after - error( get_string('exporterror','quiz'), - "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); } echo "
$count. ".stripslashes($question->questiontext)."
"; - $expout .= $this->writequestion( $question ) . "\n"; + // export the question displaying message + $count++; + echo "$count. ".stripslashes($question->questiontext)."
"; + $expout .= $this->writequestion( $question ) . "\n"; } // final pre-process on exported data $expout = $this->presave_process( $expout ); - + // write file $filepath = $path."/".$this->filename . $this->export_file_extension(); if (!$fh=fopen($filepath,"w")) { error( get_string('cannotopen','quiz',$filepath) ); } - if (!fwrite($fh, $expout)) { + if (!fwrite($fh, $expout, strlen($expout) )) { error( get_string('cannotwrite','quiz',$filepath) ); } fclose($fh); - return true; } diff --git a/question/format/gift/format.php b/question/format/gift/format.php index ae0dfe46d6b..e719ab84c6a 100755 --- a/question/format/gift/format.php +++ b/question/format/gift/format.php @@ -1,5 +1,5 @@ - qtype) { + case 'category': + // not a real question, used to insert category switch + $expout .= "\$CATEGORY: $question->category\n"; + break; case TRUEFALSE: $trueanswer = $question->options->answers[$question->options->trueanswer]; $falseanswer = $question->options->answers[$question->options->falseanswer]; diff --git a/question/format/xhtml/format.php b/question/format/xhtml/format.php index 77c91751d1a..1a74c21c2fc 100755 --- a/question/format/xhtml/format.php +++ b/question/format/xhtml/format.php @@ -19,6 +19,11 @@ function writequestion( $question ) { // turns question into string // question reflects database fields for general question and specific to type + // if a category switch, just ignore + if ($question-qtype=='category') { + return ''; + } + // initial string; $expout = ""; $id = $question->id; @@ -39,25 +44,25 @@ function writequestion( $question ) { // selection depends on question type switch($question->qtype) { case TRUEFALSE: - $st_true = get_string( 'true','quiz' ); - $st_false = get_string( 'false','quiz' ); - $expout .= "