2 // Based on default.php, included by ../import.php
4 * @package questionbank
5 * @subpackage importexport
7 class qformat_xhtml
extends qformat_default
{
9 function provide_export() {
13 function repchar( $text ) {
14 // escapes 'reserved' characters # = ~ { ) and removes new lines
15 $reserved = array( '#','=','~','{','}',"\n","\r" );
16 $escaped = array( '\#','\=','\~','\{','\}',' ','' );
18 return str_replace( $reserved, $escaped, $text );
21 function writequestion( $question ) {
22 // turns question into string
23 // question reflects database fields for general question and specific to type
25 // if a category switch, just ignore
26 if ($question-qtype
=='category') {
34 // add comment and div tags
35 $expout .= "<!-- question: $id name: $question->name -->\n";
36 $expout .= "<div class=\"question\">\n";
39 $expout .= "<h3>$question->name</h3>\n";
41 // format and add question text
42 $questiontext = $question->questiontext
;
43 $format = $question->questiontextformat
;
44 $formatted_text = format_text( $questiontext, $format );
45 $expout .= "<p class=\"questiontext\">$formatted_text</p>\n";
47 // selection depends on question type
48 switch($question->qtype
) {
50 $st_true = get_string( 'true','quiz' );
51 $st_false = get_string( 'false','quiz' );
52 $expout .= "<ul class=\"truefalse\">\n";
53 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_true\" />$st_true</li>\n";
54 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_false\" />$st_false</li>\n";
58 $expout .= "<ul class=\"multichoice\">\n";
59 foreach($question->options
->answers
as $answer) {
60 $ans_text = $this->repchar( $answer->answer
);
61 if ($question->options
->single
) {
62 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$ans_text\" />$ans_text</li>\n";
65 $expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"$ans_text\" />$ans_text</li>\n";
71 $expout .= "<ul class=\"shortanswer\">\n";
72 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
76 $expout .= "<ul class=\"numerical\">\n";
77 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
81 $expout .= "<ul class=\"match\">\n";
85 foreach($question->options
->subquestions
as $subquestion) {
86 $ans_list[] = $this->repchar( $subquestion->answertext
);
88 shuffle( $ans_list ); // random display order
90 // build drop down for answers
91 $dropdown = "<select name=\"quest_$id\">\n";
92 foreach($ans_list as $ans) {
93 $dropdown .= "<option value=\"$ans\">$ans</option>\n";
95 $dropdown .= "</select>\n";
98 foreach($question->options
->subquestions
as $subquestion) {
99 $quest_text = $this->repchar( $subquestion->questiontext
);
100 $expout .= " <li>$quest_text</li>\n";
101 $expout .= $dropdown;
103 $expout .= "</ul>\n";
108 $expout .= "<!-- CLOZE type is not supported -->\n";
111 notify("No handler for qtype $question->qtype for GIFT export" );
114 $expout .= "</div>\n\n\n";
119 function presave_process( $content ) {
120 // override method to allow us to add xhtml headers and footers
125 $css_lines = file( "$CFG->dirroot/question/format/xhtml/xhtml.css" );
126 $css = implode( ' ',$css_lines );
128 $xp = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
129 $xp .= " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
130 $xp .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
132 $xp .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n";
133 $xp .= "<title>Moodle Quiz XHTML Export</title>\n";
137 $xp .= "<form action=\"...REPLACE ME...\" method=\"post\">\n\n";
139 $xp .= "<p class=\"submit\">\n";
140 $xp .= " <input type=\"submit\" />\n";
149 function export_file_extension() {