Too many bugs, not enough time!
[moodle.git] / mod / resource / details.php
blob108e2bce6995f50f2893c7cb2c8e1bbbfa557be7
1 <?PHP // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
6 require_login();
8 $usehtmleditor = can_use_html_editor();
10 if ($form = data_submitted($destination)) {
12 if (! $course = get_record("course", "id", $form->course)) {
13 error("This course doesn't exist");
16 require_login($course->id);
18 if (!isteacher($course->id)) {
19 error("You can't modify this course!");
22 $stredit = get_string("edit");
23 $strediting = get_string("editingaresource", "resource");
24 $strname = get_string("name");
25 $strtypename = $RESOURCE_TYPE["$form->type"];
26 $strexample = get_string("example", "resource");
27 $strresources = get_string("modulenameplural", "resource");
29 print_header("$course->shortname: $strediting", "$course->shortname: $strediting",
30 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
31 <a href=\"index.php?id=$course->id\">$strresources</a> -> $form->name ($stredit)");
33 if (!$form->name or !$form->type or !$form->summary) {
34 error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
37 $form->alltext = "";
38 if ($form->instance) {
39 $form->alltext = get_field("resource", "alltext", "id", "$form->instance");
42 print_simple_box_start("center", "", "$THEME->cellheading");
44 echo "<form name=theform method=post action=\"$form->destination\">";
45 echo "<table cellpadding=5 align=center>";
46 echo "<tr><td align=right nowrap><p><b>$strname:</b></p></td><td><p>$form->name</p></a></td></tr>";
49 switch ($form->type) {
50 case REFERENCE:
51 $strexamplereference = get_string("examplereference", "resource");
53 <tr valign="top">
54 <td align="right" nowrap>
55 <p><b><?php echo $strtypename?>:</b></p>
56 </td>
57 <td>
58 <textarea name="reference" rows=3 cols=50 wrap="virtual"><?php p($form->reference) ?></textarea>
59 </td>
60 </tr>
61 <tr valign="top">
62 <td align="right" nowrap>
63 <p><b>(<?php echo $strexample?>)</b></p>
64 </td>
65 <td>
66 <p><?php echo $strexamplereference?></p>
67 </td>
68 </tr>
70 <?php
71 break;
73 case WEBPAGE:
74 $strexampleurl = get_string("exampleurl", "resource");
75 $strsearch = get_string("search");
76 if (empty($form->reference)) {
77 $form->reference = $CFG->resource_defaulturl;
80 <tr valign="top">
81 <td align="right" nowrap>
82 <p><b><?php echo $strtypename?>:</b></p>
83 </td>
84 <td>
85 <input name="reference" size="80" value="<?php p($form->reference) ?>">
86 <?php
87 echo "<input type=button name=searchbutton value=\"$strsearch ...\" ".
88 "onClick=\"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');\">\n";
90 </td>
91 </tr>
92 <tr valign="top">
93 <td align="right" nowrap>&nbsp;
94 </td>
95 <td>
96 <p><?php echo "($strexample) $strexampleurl" ?></p>
97 </td>
98 </tr>
100 <?php
101 break;
103 case WEBLINK:
105 $strexampleurl = get_string("exampleurl", "resource");
106 $strnewwindow = get_string("newwindow", "resource");
107 $strnewwindowopen = get_string("newwindowopen", "resource");
108 $strsearch = get_string("search");
110 if (empty($form->reference)) {
111 $form->reference = $CFG->resource_defaulturl;
114 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
115 $stringname = "str$optionname";
116 $$stringname = get_string("new$optionname", "resource");
117 $window->$optionname = "";
118 $jsoption[] = "\"$optionname\"";
120 $alljsoptions = implode(",", $jsoption);
122 if ($form->instance) { // Re-editing
123 if (!$form->alltext) {
124 $newwindow = ""; // Disable the new window
125 } else {
126 $newwindow = "checked";
127 $rawoptions = explode(',', $form->alltext);
128 foreach ($rawoptions as $rawoption) {
129 $option = explode('=', trim($rawoption));
130 $optionname = $option[0];
131 $optionvalue = $option[1];
132 if ($optionname == "height" or $optionname == "width") {
133 $window->$optionname = $optionvalue;
134 } else if ($optionvalue) {
135 $window->$optionname = "checked";
139 } else {
140 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
141 $defaultvalue = "resource_popup$optionname";
142 $window->$optionname = $CFG->$defaultvalue;
144 $newwindow = $CFG->resource_popup;
147 echo $alloptions;
151 <tr valign="top">
152 <td align="right" nowrap>
153 <p><b><?php p($strtypename) ?>:</b></p>
154 </td>
155 <td>
156 <input name="reference" size="80" value="<?php p($form->reference) ?>">
157 <?php
158 echo "<input type=button name=searchbutton value=\"$strsearch ...\" ".
159 "onClick=\"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');\">\n";
161 </td>
162 </tr>
163 <tr valign="top">
164 <td align="right" nowrap>&nbsp;
165 </td>
166 <td>
167 <p><font size="-1"><?php echo "($strexample) $strexampleurl" ?></font></p>
168 </td>
169 </tr>
170 <tr valign="top">
171 <td align="right" nowrap>
172 <p><b><?php p($strnewwindow) ?></b></p>
173 </td>
174 <td>
175 <script>
176 var subitems = [<?php echo $alljsoptions; ?>];
177 </script>
178 <input name="setnewwindow" type=hidden value=1>
179 <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?>
180 onclick="return lockoptions('theform','newwindow', subitems)">
181 <?php p($strnewwindowopen) ?>
182 <ul>
183 <?php
184 foreach ($window as $name => $value) {
185 if ($name == "height" or $name == "width") {
186 continue;
188 echo "<input name=\"h$name\" type=hidden value=0>";
189 echo "<input name=\"$name\" type=checkbox value=1 ".$window->$name.">";
190 $stringname = "str$name";
191 echo $$stringname."<br />";
195 <input name="hwidth" type=hidden value=0>
196 <input name="width" type=text size=4 value="<?php p($window->width) ?>">
197 <?php p($strwidth) ?><br />
199 <input name="hheight" type=hidden value=0>
200 <input name="height" type=text size=4 value="<?php p($window->height) ?>">
201 <?php p($strheight) ?><br />
202 <?php
203 if (!$newwindow) {
204 echo "<script>";
205 echo "lockoptions('theform','newwindow', subitems);";
206 echo "</script>";
209 </ul>
210 </p>
211 </td>
212 </tr>
214 <?php
215 break;
217 case UPLOADEDFILE:
218 $strfilename = get_string("filename", "resource");
219 $strnote = get_string("note", "resource");
220 $strchooseafile = get_string("chooseafile", "resource");
221 $strnewwindow = get_string("newwindow", "resource");
222 $strnewwindowopen = get_string("newwindowopen", "resource");
224 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
225 $stringname = "str$optionname";
226 $$stringname = get_string("new$optionname", "resource");
227 $window->$optionname = "";
228 $jsoption[] = "\"$optionname\"";
230 $alljsoptions = implode(",", $jsoption);
232 if ($form->instance) { // Re-editing
233 if (!$form->alltext) {
234 $newwindow = ""; // Disable the new window
235 } else {
236 $newwindow = "checked";
237 $rawoptions = explode(',', $form->alltext);
238 foreach ($rawoptions as $rawoption) {
239 $option = explode('=', trim($rawoption));
240 $optionname = $option[0];
241 $optionvalue = $option[1];
242 if ($optionname == "height" or $optionname == "width") {
243 $window->$optionname = $optionvalue;
244 } else if ($optionvalue) {
245 $window->$optionname = "checked";
249 } else {
250 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
251 $defaultvalue = "resource_popup$optionname";
252 $window->$optionname = $CFG->$defaultvalue;
254 $newwindow = $CFG->resource_popup;
257 echo $alloptions;
261 <tr valign="top">
262 <td align="right" nowrap>
263 <p><b><?php echo $strfilename?>:</b></p>
264 </td>
265 <td>
266 <?php
267 echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\">&nbsp;";
268 button_to_popup_window ("/mod/resource/coursefiles.php?id=$course->id",
269 "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
271 </td>
272 </tr>
273 <tr valign="top">
274 <td align="right" nowrap>
275 <p><b><?php p($strnewwindow) ?></b></p>
276 </td>
277 <td>
278 <script>
279 var subitems = [<?php echo $alljsoptions; ?>];
280 </script>
281 <input name="setnewwindow" type=hidden value=1>
282 <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?>
283 onclick="return lockoptions('theform','newwindow', subitems)">
284 <?php p($strnewwindowopen) ?>
285 <ul>
286 <?php
287 foreach ($window as $name => $value) {
288 if ($name == "height" or $name == "width") {
289 continue;
291 echo "<input name=\"h$name\" type=hidden value=0>";
292 echo "<input name=\"$name\" type=checkbox value=1 ".$window->$name.">";
293 $stringname = "str$name";
294 echo $$stringname."<br />";
298 <input name="hwidth" type=hidden value=0>
299 <input name="width" type=text size=4 value="<?php p($window->width) ?>">
300 <?php p($strwidth) ?><br />
302 <input name="hheight" type=hidden value=0>
303 <input name="height" type=text size=4 value="<?php p($window->height) ?>">
304 <?php p($strheight) ?><br />
305 <?php
306 if (!$newwindow) {
307 echo "<script>";
308 echo "lockoptions('theform','newwindow', subitems);";
309 echo "</script>";
312 </ul>
313 </p>
314 </td>
315 </tr>
317 <?php
318 break;
321 case PROGRAM:
322 $strexampleurl = get_string("exampleurl", "resource");
324 <tr valign="top">
325 <td align="right" nowrap>
326 <p><b><?php echo $strtypename?>:</b></p>
327 </td>
328 <td>
329 <input name="reference" size="100" value="<?php p($form->reference) ?>">
330 </td>
331 </tr>
332 <tr valign="top">
333 <td align="right" nowrap>&nbsp;
334 </td>
335 <td>
336 <p><?php echo "($strexample) $strexampleurl" ?></p>
337 </td>
338 </tr>
340 <?php
341 break;
344 case PLAINTEXT:
345 $strfulltext = get_string("fulltext", "resource");
347 <tr valign="top">
348 <td align="right" nowrap>
349 <p><b><?php echo $strfulltext?>:</b></p><br />
350 <font size="1">
351 <?php helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br />
352 <?php helpbutton("text", get_string("helptext"), "moodle", true, true) ?> <br />
353 <?php emoticonhelpbutton("theform", "alltext") ?> <br />
354 </font>
355 </td>
356 <td>
357 <textarea name="alltext" rows=20 cols=50 wrap="virtual"><?php p($form->alltext) ?></textarea>
358 </td>
359 </tr>
360 <?php
361 break;
363 case WIKITEXT:
364 $strfulltext = get_string("fulltext", "resource");
366 <tr valign="top">
367 <td align="right" nowrap="true">
368 <p><b><?php echo $strfulltext?>:</b></p><br />
369 <font size="1">
370 <?php helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br />
371 <?php helpbutton("wiki", get_string("helpwiki"), "moodle", true, true) ?> <br />
372 </font>
373 </td>
374 <td>
375 <textarea name="alltext" rows="20" cols="50" wrap="virtual"><?php p($form->alltext) ?></textarea>
376 </td>
377 </tr>
378 <?php
379 break;
381 case HTML:
382 $strhtmlfragment = get_string("htmlfragment", "resource");
384 <tr valign="top">
385 <td align="right" nowrap>
386 <p><b><?php echo $strhtmlfragment?>:</b></p><br />
387 <font size="1">
388 <?php helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br />
389 <?php if ($usehtmleditor) {
390 helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
391 } else {
392 helpbutton("html", get_string("helphtml"), "moodle", true, true);
393 } ?> <br />
394 </font>
395 </td>
396 <td>
397 <?php print_textarea($usehtmleditor, 20, 50, 680, 400, "alltext", $form->alltext); ?>
398 </td>
399 </tr>
400 <?php
401 break;
403 default:
404 error(get_string("notypechosen", "resource"), $_SERVER["HTTP_REFERER"]);
405 break;
409 </table>
410 <input type="hidden" name=summary value="<?php p($form->summary) ?>">
411 <input type="hidden" name=type value="<?php p($form->type) ?>">
412 <input type="hidden" name=name value="<?php p($form->name) ?>">
414 <input type="hidden" name=course value="<?php p($form->course) ?>">
415 <input type="hidden" name=coursemodule value="<?php p($form->coursemodule) ?>">
416 <input type="hidden" name=section value="<?php p($form->section) ?>">
417 <input type="hidden" name=module value="<?php p($form->module) ?>">
418 <input type="hidden" name=modulename value="<?php p($form->modulename) ?>">
419 <input type="hidden" name=instance value="<?php p($form->instance) ?>">
420 <input type="hidden" name=mode value="<?php p($form->mode) ?>">
421 <center>
422 <input type="submit" value="<?php print_string("savechanges") ?>">
423 <input type="submit" name=cancel value="<?php print_string("cancel") ?>">
424 </center>
425 </form>
426 <?php
427 if ($usehtmleditor and $form->type == HTML) {
428 use_html_editor();
430 print_simple_box_end();
431 print_footer($course);
433 } else {
434 error("This script was called incorrectly");