📄 format.php
字号:
// 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 "<br />Error: Could not delete: $filename"; return false; } return true; } function getquestions($filename, $category, $mdapath="", $hostname="") { if (($category == "allcategories") or ($category == "")) { $sql = "SELECT * FROM TBQuestions"; } else { $sql = "SELECT * FROM TBQuestions where module = '".$category."'"; } if (PHP_OS == "WINNT") { $ldb =& $this->connect_win($filename); $qset = $ldb->Execute("$sql"); if ( !$qset->EOF ) { $records = $qset->GetAssoc(true); } else { $this->err("There were no records in the database.",$dsn); $ldb->Close(); return false; } $ldb->Close(); } else { // if PHP_OS == WINNT // we have a linux installation $result = $this->query_linux($sql,$filename, $mdapath,$hostname); if ( count($result) > 0 ) { // get rid of the ID field in the first column. for($i=0;$i<count($result);$i++) { foreach (array_keys($result[$i]) as $j) { $records[$i][$j-1] = $result[$i][$j]; } } } else { $this->err("There were no records in the database.",$dsn); $ldb->Close(); return false; } // xml test and connect } // PHP_OS TEST return $records; } function getquestioncategories($filename, $mdapath="", $hostname="") { global $CFG, $result; $sql = "SELECT Distinct module FROM TBQuestions"; if (PHP_OS == "WINNT") { $ldb =& $this->connect_win($filename); $qset = $ldb->Execute("$sql"); if ( !$qset->EOF ) { $records = $qset->GetArray(true); foreach ($records as $record) { $categories[$record[0]] = $record[0]; } } else { // if recordcount $this->err("There were no records in the database.",$dsn); $ldb->Close(); return false; } $ldb->Close(); } else { // if PHP_OS == WINNT // we have a linux installation $result = $this->query_linux($sql, $filename, $mdapath, $hostname); for($i=0;$i<count($result);$i++) { $categories[$result[$i][0]] = $result[$i][0]; } } // PHP_OS TEST return $categories; } function query_linux($sql, $mdbpath, $mdapath, $hostname) { global $result; include_once("odbcsocketserver.class.php"); // set up socket server object to connect to remote host $oTest = new ODBCSocketServer; //Set the Hostname, port, and connection string $oTest->sHostName = $hostname; $oTest->nPort = 9628;// $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=C:\CTM\System.mda;DBQ=C:\CTM\of2K3\ctm.mdb;UID=Assess;PWD=VBMango;"; $oTest->sConnectionString="DRIVER=Microsoft Access Driver (*.mdb);SystemDB=". $mdapath.";DBQ=".$mdbpath.";UID=Assess;PWD=VBMango;"; // send and receive XML communication $qResult = $oTest->ExecSQL($sql); // set up XML parser to read the results $xml_parser = xml_parser_create("US-ASCII"); xml_set_element_handler($xml_parser, "quiz_xmlstart", "quiz_xmlend"); xml_set_character_data_handler($xml_parser, "quiz_xmldata"); // parse the XML and get back the result set array if (!xml_parse($xml_parser, $qResult)) { $this->err("XML error: ".xml_error_string(xml_get_error_code($xml_parser)) ." at line ".xml_get_current_line_number($xml_parser),$oTest->sConnectionString); return false; } else {// echo("Successful XML parse. "); // prepare the array for use in the pull-down/* echo "<br />count of rows is ". count ($result); echo "<pre>\n"; $qResult = HtmlSpecialChars($qResult); echo $qResult; echo "\n</pre>";*/ xml_parser_free($xml_parser);// $sResult = HtmlSpecialChars($qResult); //echo("<pre>");// echo($sResult);// echo("</pre>"); 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 "<font color=\"#990000\">"; echo "<p>Error: $message</p>"; echo "<p>ODBC File DSN: $dsn<br />"; echo "</font>"; } function fulldelete($location) { if (is_dir($location)) { $currdir = opendir($location); while (false !== ($file = readdir($currdir))) { if ($file <> ".." && $file <> ".") { $fullfile = $location."/".$file; if (is_dir($fullfile)) { if (!fulldelete($fullfile)) { return false; } } else { if (!unlink($fullfile)) { return false; } } } } closedir($currdir); if (! rmdir($location)) { return false; } } else { if (!unlink($location)) { return false; } } return true; } function findfile($filename) { global $CFG; $dirs = $this->getcoursedirs(); $dirs[] = $CFG->dirroot."\mod\quiz\format"; foreach ($dirs as $dir) { $file = $dir . "\System.mda"; // look for System.mda if (is_file($file)) return $file; } return false; } function getcoursedirs() { global $CFG; // for every course in the system, find the root of the data directory $courses = get_records_sql("select distinct id,fullname from ".$CFG->prefix."course"); $dirs = array(); if ($courses) { foreach ($courses as $course) { $dir = $CFG->dataroot . "/" . $course->id; if (is_dir($dir)) { $dirs[] = $dir; } } } return $dirs; }} // END OF CLASS //Handler for starting elements function quiz_xmlstart($parser, $name, $attribs) { global $result,$row, $col, $incolumn; $name = strtolower($name); switch ($name) { case "row": $col=0;break; case "column": $incolumn = 1;break; case "error": break; case "result": $row = 0; break; } // switch } //handler for the end of elements function quiz_xmlend($parser, $name) { global $result, $row, $col, $incolumn; $name = strtolower($name); switch ($name) { case "row": $row++;break; case "column": $incolumn = 0; $col++; break; case "error": break; case "result": break; } // switch } // function //handler for character data function quiz_xmldata($parser, $data) { global $result, $row, $col, $incolumn; if ($incolumn) { $result[$row][$col] = $result[$row][$col] . $data; } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -