adding some strings
[moodle-linuxchix.git] / question / format / xhtml / format.php
blob2ae9029c13b5ac8bb2b6bbd2f2169035fba04956
1 <?php
2 // Based on default.php, included by ../import.php
3 /**
4 * @package questionbank
5 * @subpackage importexport
6 */
7 class qformat_xhtml extends qformat_default {
9 function provide_export() {
10 return true;
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') {
27 return '';
30 // initial string;
31 $expout = "";
32 $id = $question->id;
34 // add comment and div tags
35 $expout .= "<!-- question: $id name: $question->name -->\n";
36 $expout .= "<div class=\"question\">\n";
38 // add header
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) {
49 case TRUEFALSE:
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";
55 $expout .= "</ul>\n";
56 break;
57 case MULTICHOICE:
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";
64 else {
65 $expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"$ans_text\" />$ans_text</li>\n";
68 $expout .= "</ul>\n";
69 break;
70 case SHORTANSWER:
71 $expout .= "<ul class=\"shortanswer\">\n";
72 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
73 $expout .= "</ul>\n";
74 break;
75 case NUMERICAL:
76 $expout .= "<ul class=\"numerical\">\n";
77 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n";
78 $expout .= "</ul>\n";
79 break;
80 case MATCH:
81 $expout .= "<ul class=\"match\">\n";
83 // build answer list
84 $ans_list = array();
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";
97 // finally display
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";
104 break;
105 case DESCRIPTION:
106 break;
107 case MULTIANSWER:
108 $expout .= "<!-- CLOZE type is not supported -->\n";
109 break;
110 default:
111 notify("No handler for qtype $question->qtype for GIFT export" );
113 // close off div
114 $expout .= "</div>\n\n\n";
115 return $expout;
119 function presave_process( $content ) {
120 // override method to allow us to add xhtml headers and footers
122 global $CFG;
124 // get css bit
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";
131 $xp .= "<head>\n";
132 $xp .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n";
133 $xp .= "<title>Moodle Quiz XHTML Export</title>\n";
134 $xp .= $css;
135 $xp .= "</head>\n";
136 $xp .= "<body>\n";
137 $xp .= "<form action=\"...REPLACE ME...\" method=\"post\">\n\n";
138 $xp .= $content;
139 $xp .= "<p class=\"submit\">\n";
140 $xp .= " <input type=\"submit\" />\n";
141 $xp .= "</p>\n";
142 $xp .= "</form>\n";
143 $xp .= "</body>\n";
144 $xp .= "</html>\n";
146 return $xp;
149 function export_file_extension() {
150 return ".html";