From 1367cb8d6bb92742a87949a43a01a44ee471916e Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 18 Jul 2006 13:33:45 +0000 Subject: [PATCH] SC#277. Merged from MOODLE_16_STABLE. --- lang/en_utf8/quiz.php | 2 +- question/export.php | 5 ++--- question/format.php | 16 +++++++++------- question/format/qti2/format.php | 27 ++++++++++----------------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 52fbdb5e4d..9c1998cc25 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -131,7 +131,7 @@ $string['description'] = 'Description'; $string['discrimination'] = 'Discrim. Index'; $string['displayoptions'] = 'Display options'; $string['download'] = 'Click to download the exported category file'; -$string['downloadextra'] = '(file is also stored in the course files in the /quiz folder)'; +$string['downloadextra'] = '(file is also stored in the course files in the /backupdata/quiz folder)'; $string['duplicateresponse'] = 'This submission has been ignored because you gave an equivalent answer earlier.'; $string['eachattemptbuildsonthelast'] = 'Each attempt builds on the last'; $string['editcategories'] = 'Edit categories'; diff --git a/question/export.php b/question/export.php index 70bc39a870..a6893390cb 100644 --- a/question/export.php +++ b/question/export.php @@ -112,13 +112,12 @@ // link to download the finished file $file_ext = $qformat->export_file_extension(); $download_str = get_string( 'download', 'quiz' ); - $quizexportdir = get_string( 'exportfilename', 'quiz' ); $downloadextra_str = get_string( 'downloadextra','quiz' ); if ($CFG->slasharguments) { - $efile = "{$CFG->wwwroot}/file.php/$course->id/$quizexportdir/$exportfilename".$file_ext."?forcedownload=1"; + $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1"; } else { - $efile = "{$CFG->wwwroot}/file.php?file=/$course->id/$quizexportdir/$exportfilename".$file_ext."&forcedownload=1"; + $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1"; } echo "

$download_str

"; echo "

$downloadextra_str

"; diff --git a/question/format.php b/question/format.php index 6191333ed7..230959833d 100644 --- a/question/format.php +++ b/question/format.php @@ -272,14 +272,10 @@ class qformat_default { global $CFG; // create a directory for the exports (if not already existing) - $dirname = get_string("exportfilename","quiz"); - $courseid = $this->course->id; - $path = $CFG->dataroot.'/'.$courseid.'/'.$dirname; - if (!is_dir($path)) { - if (!mkdir($path, $CFG->directorypermissions)) { - error( get_string('cannotcreatepath','quiz',$path) ); - } + if (! $export_dir = make_upload_directory($this->question_get_export_dir())) { + error( get_string('cannotcreatepath','quiz',$export_dir) ); } + $path = $CFG->dataroot.'/'.$this->question_get_export_dir(); // get the questions (from database) in this category // only get q's with no parents (no cloze subquestions specifically) @@ -347,6 +343,12 @@ class qformat_default { return NULL; } + function question_get_export_dir() { + $dirname = get_string("exportfilename","quiz"); + $path = $this->course->id.'/backupdata/'.$dirname; // backupdata is protected directory + return $path; + } + } ?> diff --git a/question/format/qti2/format.php b/question/format/qti2/format.php index ade71ebd8d..6c5c2e0ee5 100644 --- a/question/format/qti2/format.php +++ b/question/format/qti2/format.php @@ -235,24 +235,14 @@ function handle_questions_media(&$questions, $path, $courseid) { function exportprocess($filename) { global $CFG; + $courseid = $this->course->id; // create a directory for the exports (if not already existing) - $dirname = get_string("exportfilename","quiz"); - $courseid = $this->course->id; - $path = $CFG->dataroot.'/'.$courseid.'/'.$dirname; - if (!is_dir($path)) { - if (!mkdir($path, $CFG->directorypermissions)) { - error("Cannot create path: $path"); - } + if (!$export_dir = make_upload_directory($this->question_get_export_dir().'/'.$filename)) { + error( get_string('cannotcreatepath','quiz',$export_dir) ); } - // create directory for this particular IMS export, if not already existing - $path = $path."/".$filename; - if (!is_dir($path)) { - if (!mkdir($path, $CFG->directorypermissions)) { - error("Cannot create path: $path"); - } - } - + $path = $CFG->dataroot.'/'.$this->question_get_export_dir().'/'.$filename; + // get the questions (from database) in this category // $questions = get_records("question","category",$this->category->id); $questions = get_questions_category( $this->category ); @@ -281,6 +271,9 @@ function handle_questions_media(&$questions, $path, $courseid) { $smarty->error_reporting = 99; $expout = $smarty->fetch('imsmanifest.tpl'); $filepath = $path.'/imsmanifest.xml'; + if (empty($expout)) { + error("Unkown error - empty imsmanifest.xml"); + } if (!$fh=fopen($filepath,"w")) { error("Cannot open for writing: $filepath"); } @@ -313,7 +306,7 @@ function handle_questions_media(&$questions, $path, $courseid) { zip_files( array($path), "$path.zip" ); // remove the temporary directory - delDirContents( $path ); + remove_dir( $path ); return true; } @@ -688,7 +681,7 @@ function xml_entitize(&$collection) { } } $smarty = new Smarty; - $smarty->template_dir = "{$CFG->dirroot}/mod/quiz/format/qti2/templates"; + $smarty->template_dir = "{$CFG->dirroot}/question/format/qti2/templates"; $smarty->compile_dir = "$path"; return $smarty; } -- 2.39.5