dirroot.'/lib/uploadlib.php'); class qformat_coursetestmanager extends qformat_default { function provide_import() { return true; } function importpreprocess($category) { $this->category = $category; // Important return true; } function importprocess($filename) { global $CFG, $USER, $strimportquestions,$form,$question_category,$category,$COURSE, $hostname, $mdapath, $mdbpath; if ((PHP_OS == "Linux") and isset($hostname)) { $hostname = trim($hostname); // test the ODBC socket server connection // if failure, unset hostname and set hostname_access_error $question_categories = $this->getquestioncategories($mdbpath, $mdapath, $hostname); if (!$question_categories) { $hostname_access_error = $hostname . " "; unset($hostname); } else { $hostname_access_error = 0; } } if ((PHP_OS == "Linux") and !isset($hostname)) { // copy the file to a semi-permanent location if (! $basedir = make_upload_directory("$COURSE->id")) { error("The site administrator needs to fix the file permissions for the data directory"); } if (!isset($hostname_access_error)) { $bname=basename($filename); $cleanfilename = clean_filename($bname); if ($cleanfilename) { $newfile = "$basedir/$cleanfilename"; if (move_uploaded_file($filename, $newfile)) { chmod($newfile, 0666); clam_log_upload($newfile,$COURSE); } else { notify(get_string("uploadproblem", "", $filename)); } } $filename = $newfile; } print_heading_with_help($strimportquestions, "import", "quiz"); print_simple_box_start("center"); if ($hostname_access_error) { notify("couldn't connect to ODBC Socket Server on " . $hostname_access_error); } echo "
"; print_simple_box_end(); print_footer($COURSE); exit; } // we get here if running windows or after connect to ODBC socket server on linux // // this generates the page to choose categories of questions to import // if (!isset($question_category)) { if (PHP_OS == "WINNT") { // copy the file to a semi-permanent location if (! $basedir = make_upload_directory("$COURSE->id")) { error("The site administrator needs to fix the file permissions for the data directory"); } $bname=basename($filename); $cleanfilename = clean_filename($bname); if ($cleanfilename) { $newfile = "$basedir/$cleanfilename"; if (move_uploaded_file($filename, $newfile)) { chmod($newfile, 0666); clam_log_upload($newfile,$COURSE); } else { notify(get_string("uploadproblem", "", $filename)); } } $filename = $newfile; } // end of file copy // don't have to do this on linux, since it's alreay been done in the test above if (PHP_OS == "WINNT") { $question_categories = $this->getquestioncategories($filename); } // print the intermediary form if (!$categories = question_category_options($COURSE->id, true)) { error("No categories!"); } print_heading_with_help($strimportquestions, "import", "quiz"); print_simple_box_start("center"); echo ""; print_simple_box_end(); print_footer($COURSE); exit; } // // this is the main import section // notify("Importing questions"); if (PHP_OS == "Linux") { $hostname = trim($hostname); $records = $this->getquestions($mdbpath,$question_category,$mdapath, $hostname); } else { $records = $this->getquestions($filename,$question_category); } foreach ($records as $qrec) { $question = $this->defaultquestion(); if ($qrec[9] != "") { $question->image = $qrec[9]; } // 0 Selected // 1 PracticeTestOK? // 2 QuestionText // 3 QuestionType // 4 Option1Text // 5 Option2Text // 6 Option3Text // 7 Option4Text // 8 CorrectAnswer // 9 Graphic // 10 Module // 11 ChapterNumber // 12 PageNumber $ref = "Answer can be found in chapter ". $qrec[11] . ", page " . $qrec[12] . "."; switch ($qrec[3]) { case 1: $question->qtype = MULTICHOICE; // MULTICHOICE, SHORTANSWER, TRUEFALSE // echo "";echo htmlspecialchars($qrec[2]); echo ""; $question->questiontext = addslashes(trim($qrec[2])); // echo "
";echo $question->questiontext; echo ""; $question->name = preg_replace("/
";echo $question->questiontext; echo ""; $question->name = preg_replace("/
$count. ".stripslashes($question->questiontext)."
"; $question->category = $this->category->id; $question->stamp = make_unique_id_code(); // Set the unique code (not to be changed) $question->createdby = $USER->id; $question->timecreated = time(); if (!$question->id = insert_record("question", $question)) { error("Could not insert new question!"); } $this->questionids[] = $question->id; // Now to save all the answers and type-specific options $result = save_question_options($question); if (!empty($result->error)) { notify($result->error); $this->deletedatabase($filename); return false; } if (!empty($result->notice)) { notify($result->notice); $this->deletedatabase($filename); return true; } // Give the question a unique version stamp determined by question_hash() set_field('question', 'version', question_hash($question), 'id', $question->id); } $this->deletedatabase($filename); return true; } function importpostprocess() { return true; } function deletedatabase($filename) { if (! $this->fulldelete($filename)) { echo "\n";
$qResult = HtmlSpecialChars($qResult);
echo $qResult;
echo "\n";
*/
xml_parser_free($xml_parser);
// $sResult = HtmlSpecialChars($qResult);
//echo("");
// echo($sResult);
// echo("");
return $result;
}
}
function connect_win($filename) {
global $CFG, $systemdb;
// first, verify the location of System.mda
if (!isset($systemdb)) {
$systemdb=$this->findfile("System.mda");
}
if (! $systemdb) {
$this->err("The system database System.mda cannot be found. Check that you've uploaded it to the course.",$dsn);
die;
}
$ldb = &ADONewConnection('access');
$dsn="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=".$systemdb.";DBQ=".$filename.";UID=Assess;PWD=VBMango;";
$dbconnected = $ldb->Connect($dsn);
if (! $dbconnected) {
$this->err("Moodle could not connect to the database.",$dsn);
die;
}
return $ldb;
}
function err($message, $dsn) {
echo "";
echo "Error: $message
"; echo "ODBC File DSN: $dsn
";
echo "