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
var $questions = array();
var $course = NULL;
var $filename = '';
+ var $realfilename = '';
var $matchgrades = 'error';
var $catfromfile = 0;
var $contextfromfile = 0;
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
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;
// 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 {
}
} else {
// must be upload file
+ $realfilename = $import_form->get_importfile_realname();
if (!$importfile = $import_form->get_importfile_name()) {
print_error('uploadproblem', 'moodle');
}else {
$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));
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;
+ }
+ }
}
?>