From 73b7b195ed928359c9f40c8701d3ed342be9193c Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Thu, 28 Aug 2008 13:49:25 +0000 Subject: [PATCH] MDL-16198 Blackboard V6+ can now handle the .dat file directly as an option to the .zip file Some changes needed to recover the original filename. Merged from STABLE_19 --- question/format.php | 10 ++++++++++ question/format/blackboard_six/format.php | 10 ++++++++++ question/import.php | 3 +++ question/import_form.php | 10 ++++++++++ 4 files changed, 33 insertions(+) diff --git a/question/format.php b/question/format.php index 5448a6bbe5..b5066ce8de 100644 --- a/question/format.php +++ b/question/format.php @@ -15,6 +15,7 @@ class qformat_default { var $questions = array(); var $course = NULL; var $filename = ''; + var $realfilename = ''; var $matchgrades = 'error'; var $catfromfile = 0; var $contextfromfile = 0; @@ -87,6 +88,15 @@ class qformat_default { function setFilename( $filename ) { $this->filename = $filename; } + + /** + * set the "real" filename + * (this is what the user typed, regardless of wha happened next) + * @param string realfilename name of file as typed by user + */ + function setRealfilename( $realfilename ) { + $this->realfilename = $realfilename; + } /** * set matchgrades diff --git a/question/format/blackboard_six/format.php b/question/format/blackboard_six/format.php index 14be8c3a11..0ae5c5b02e 100644 --- a/question/format/blackboard_six/format.php +++ b/question/format/blackboard_six/format.php @@ -152,6 +152,16 @@ class qformat_blackboard_six extends qformat_default { function readdata($filename) { /// Returns complete file with an array, one item per line global $CFG; + + // if the extension is .dat we just return that, + // if .zip we unzip the file and get the data + $ext = substr($this->realfilename, strpos($this->realfilename,'.'), strlen($this->realfilename)-1); + if ($ext=='.dat') { + if (!is_readable($filename)) { + error("File is not readable"); + } + return file($filename); + } $unique_code = time(); $temp_dir = $CFG->dataroot."/temp/bbquiz_import/".$unique_code; diff --git a/question/import.php b/question/import.php index 9eedd4d1d3..67c265a58c 100644 --- a/question/import.php +++ b/question/import.php @@ -92,6 +92,7 @@ // or one from the filesarea. if (!empty($form->choosefile)) { $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}"; + $realfilename = $form->choosefile; if (file_exists($importfile)) { $fileisgood = true; } else { @@ -99,6 +100,7 @@ } } else { // must be upload file + $realfilename = $import_form->get_importfile_realname(); if (!$importfile = $import_form->get_importfile_name()) { print_error('uploadproblem', 'moodle'); }else { @@ -124,6 +126,7 @@ $qformat->setContexts($contexts->having_one_edit_tab_cap('import')); $qformat->setCourse($COURSE); $qformat->setFilename($importfile); + $qformat->setRealfilename($realfilename); $qformat->setMatchgrades($form->matchgrades); $qformat->setCatfromfile(!empty($form->catfromfile)); $qformat->setContextfromfile(!empty($form->contextfromfile)); diff --git a/question/import_form.php b/question/import_form.php index f20dcd4897..309e688da7 100644 --- a/question/import_form.php +++ b/question/import_form.php @@ -83,5 +83,15 @@ class question_import_form extends moodleform { return NULL; } } + + function get_importfile_name(){ + if ($this->is_submitted() and $this->is_validated()) { + // return the temporary filename to process + // TODO change this to use the files API properly. + return $_FILES['newfile']['name']; + }else{ + return NULL; + } + } } ?> -- 2.39.5