MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / lesson / action / addpage.php
blob1d4130a89e174deffd0dc2136aad692bceaf412e
1 <?php // $Id$
2 /**
3 * Action for adding a question page. Prints an HTML form.
5 * @version $Id$
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package lesson
8 **/
9 $CFG->pagepath = 'mod/lesson/addpage';
11 // first get the preceeding page
12 $pageid = required_param('pageid', PARAM_INT);
13 $qtype = optional_param('qtype', LESSON_MULTICHOICE, PARAM_INT);
15 // set of jump array
16 $jump = array();
17 $jump[0] = get_string("thispage", "lesson");
18 $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson");
19 $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson");
20 $jump[LESSON_EOL] = get_string("endoflesson", "lesson");
21 if(lesson_display_branch_jumps($lesson->id, $pageid)) {
22 $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson");
23 $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson");
25 if(lesson_display_cluster_jump($lesson->id, $pageid)) {
26 $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson");
28 if (!optional_param('firstpage', 0, PARAM_INT)) {
29 $linkadd = "";
30 $apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0);
32 while (true) {
33 if ($apageid) {
34 $title = get_field("lesson_pages", "title", "id", $apageid);
35 $jump[$apageid] = strip_tags(format_string($title,true));
36 $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid);
37 } else {
38 // last page reached
39 break;
42 } else {
43 $linkadd = "&amp;firstpage=1";
46 // give teacher a blank proforma
47 print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson");
49 <form id="form" method="post" action="lesson.php" class="addform">
50 <fieldset class="invisiblefieldset fieldsetfix">
51 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
52 <input type="hidden" name="action" value="insertpage" />
53 <input type="hidden" name="pageid" value="<?php echo $pageid ?>" />
54 <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
55 <?php
56 echo '<b>'.get_string("questiontype", "lesson").":</b> \n";
57 echo helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson")."<br />";
58 lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype,
59 "lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=".$pageid.$linkadd);
61 if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer
62 echo '<p>';
63 if ($qtype == LESSON_SHORTANSWER) {
64 $qoptionstr = get_string('casesensitive', 'lesson');
65 } else {
66 $qoptionstr = get_string('multianswer', 'lesson');
68 echo "<label for=\"qoption\"><strong>$qoptionstr</strong></label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>";
69 helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
70 echo '</p>';
73 <table cellpadding="5" class="generalbox boxaligncenter" border="1">
74 <tr valign="top">
75 <td><b><label for="title"><?php print_string("pagetitle", "lesson"); ?>:</label></b><br />
76 <input type="text" id="title" name="title" size="80" value="" /></td></tr>
77 <?php
78 echo "<tr><td><b>";
79 echo get_string("pagecontents", "lesson").":</b><br />\n";
80 print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
81 if ($usehtmleditor) {
82 use_html_editor("contents");
84 echo "</td></tr>\n";
85 switch ($qtype) {
86 case LESSON_TRUEFALSE :
87 for ($i = 0; $i < 2; $i++) {
88 $iplus1 = $i + 1;
89 echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
90 print_textarea(false, 6, 70, 630, 300, "answer[$i]");
91 echo "</td></tr>\n";
92 echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
93 print_textarea(false, 6, 70, 630, 300, "response[$i]");
94 echo "</td></tr>\n";
95 echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \n";
96 if ($i) {
97 // answers 2, 3, 4... jumpto this page
98 choose_from_menu($jump, "jumpto[$i]", 0, "");
99 } else {
100 // answer 1 jumpto next page
101 choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
103 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
104 if($lesson->custom) {
105 if ($i) {
106 echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\" />";
107 } else {
108 echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\" />";
111 echo "</td></tr>\n";
113 break;
114 case LESSON_ESSAY :
115 echo "<tr><td><b>".get_string("jump", "lesson").":</b> \n";
116 choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, "");
117 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
118 if ($lesson->custom) {
119 echo get_string("score", "lesson").": <input type=\"text\" name=\"score[0]\" value=\"1\" size=\"5\" />";
121 echo "</td></tr>\n";
122 break;
123 case LESSON_MATCHING :
124 for ($i = 0; $i < $lesson->maxanswers+2; $i++) {
125 $icorrected = $i - 1;
126 if ($i == 0) {
127 echo "<tr><td><b>".get_string("correctresponse", "lesson").":</b><br />\n";
128 print_textarea(false, 6, 70, 630, 300, "answer[$i]");
129 echo "</td></tr>\n";
130 } elseif ($i == 1) {
131 echo "<tr><td><b>".get_string("wrongresponse", "lesson").":</b><br />\n";
132 print_textarea(false, 6, 70, 630, 300, "answer[$i]");
133 echo "</td></tr>\n";
134 } else {
135 echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b><br />\n";
136 print_textarea(false, 6, 70, 630, 300, "answer[$i]");
137 echo "</td></tr>\n";
138 echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b><br />\n";
139 print_textarea(false, 6, 70, 630, 300, "response[$i]");
140 echo "</td></tr>\n";
142 if ($i == 2) {
143 echo "<tr><td><b>".get_string("correctanswerjump", "lesson").":</b> \n";
144 choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
145 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
146 if($lesson->custom) {
147 echo get_string("correctanswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\" />";
149 echo "</td></tr>\n";
150 } elseif ($i == 3) {
151 echo "<tr><td><b>".get_string("wronganswerjump", "lesson").":</b> \n";
152 choose_from_menu($jump, "jumpto[$i]", 0, "");
153 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
154 if($lesson->custom) {
155 echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\" />";
157 echo "</td></tr>\n";
160 break;
161 case LESSON_SHORTANSWER :
162 case LESSON_NUMERICAL :
163 case LESSON_MULTICHOICE :
164 // default code
165 for ($i = 0; $i < $lesson->maxanswers; $i++) {
166 $iplus1 = $i + 1;
167 echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
168 print_textarea(false, 6, 70, 630, 300, "answer[$i]");
169 echo "</td></tr>\n";
170 echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
171 print_textarea(false, 6, 70, 630, 300, "response[$i]");
172 echo "</td></tr>\n";
173 echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \n";
174 if ($i) {
175 // answers 2, 3, 4... jumpto this page
176 choose_from_menu($jump, "jumpto[$i]", 0, "");
177 } else {
178 // answer 1 jumpto next page
179 choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
181 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
182 if($lesson->custom) {
183 if ($i) {
184 echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\" />";
185 } else {
186 echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\" />";
189 echo "</td></tr>\n";
191 break;
193 // close table and form
195 </table><br />
196 <input type="submit" value="<?php print_string("addaquestionpage", "lesson") ?>" />
197 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
198 </fieldset>
199 </form>