3 require_once("../../config.php");
4 require_once("lib.php");
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"]);
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
) {
51 $strexamplereference = get_string("examplereference", "resource");
54 <td align
="right" nowrap
>
55 <p
><b
><?php
echo $strtypename?
>:</b
></p
>
58 <textarea name
="reference" rows
=3 cols
=50 wrap
="virtual"><?php
p($form->reference
) ?
></textarea
>
62 <td align
="right" nowrap
>
63 <p
><b
>(<?php
echo $strexample?
>)</b
></p
>
66 <p
><?php
echo $strexamplereference?
></p
>
74 $strexampleurl = get_string("exampleurl", "resource");
75 $strsearch = get_string("search");
76 if (empty($form->reference
)) {
77 $form->reference
= $CFG->resource_defaulturl
;
81 <td align
="right" nowrap
>
82 <p
><b
><?php
echo $strtypename?
>:</b
></p
>
85 <input name
="reference" size
="80" value
="<?php p($form->reference) ?>">
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";
93 <td align
="right" nowrap
> 
;
96 <p
><?php
echo "($strexample) $strexampleurl" ?
></p
>
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
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";
140 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
141 $defaultvalue = "resource_popup$optionname";
142 $window->$optionname = $CFG->$defaultvalue;
144 $newwindow = $CFG->resource_popup
;
152 <td align
="right" nowrap
>
153 <p
><b
><?php
p($strtypename) ?
>:</b
></p
>
156 <input name
="reference" size
="80" value
="<?php p($form->reference) ?>">
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";
164 <td align
="right" nowrap
> 
;
167 <p
><font size
="-1"><?php
echo "($strexample) $strexampleurl" ?
></font
></p
>
171 <td align
="right" nowrap
>
172 <p
><b
><?php
p($strnewwindow) ?
></b
></p
>
176 var subitems
= [<?php
echo $alljsoptions; ?
>];
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) ?
>
184 foreach ($window as $name => $value) {
185 if ($name == "height" or $name == "width") {
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
/>
205 echo "lockoptions('theform','newwindow', subitems);";
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
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";
250 foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
251 $defaultvalue = "resource_popup$optionname";
252 $window->$optionname = $CFG->$defaultvalue;
254 $newwindow = $CFG->resource_popup
;
262 <td align
="right" nowrap
>
263 <p
><b
><?php
echo $strfilename?
>:</b
></p
>
267 echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\"> ";
268 button_to_popup_window ("/mod/resource/coursefiles.php?id=$course->id",
269 "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
274 <td align
="right" nowrap
>
275 <p
><b
><?php
p($strnewwindow) ?
></b
></p
>
279 var subitems
= [<?php
echo $alljsoptions; ?
>];
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) ?
>
287 foreach ($window as $name => $value) {
288 if ($name == "height" or $name == "width") {
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
/>
308 echo "lockoptions('theform','newwindow', subitems);";
322 $strexampleurl = get_string("exampleurl", "resource");
325 <td align
="right" nowrap
>
326 <p
><b
><?php
echo $strtypename?
>:</b
></p
>
329 <input name
="reference" size
="100" value
="<?php p($form->reference) ?>">
333 <td align
="right" nowrap
> 
;
336 <p
><?php
echo "($strexample) $strexampleurl" ?
></p
>
345 $strfulltext = get_string("fulltext", "resource");
348 <td align
="right" nowrap
>
349 <p
><b
><?php
echo $strfulltext?
>:</b
></p
><br
/>
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
/>
357 <textarea name
="alltext" rows
=20 cols
=50 wrap
="virtual"><?php
p($form->alltext
) ?
></textarea
>
364 $strfulltext = get_string("fulltext", "resource");
367 <td align
="right" nowrap
="true">
368 <p
><b
><?php
echo $strfulltext?
>:</b
></p
><br
/>
370 <?php
helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?
><br
/>
371 <?php
helpbutton("wiki", get_string("helpwiki"), "moodle", true, true) ?
> <br
/>
375 <textarea name
="alltext" rows
="20" cols
="50" wrap
="virtual"><?php
p($form->alltext
) ?
></textarea
>
382 $strhtmlfragment = get_string("htmlfragment", "resource");
385 <td align
="right" nowrap
>
386 <p
><b
><?php
echo $strhtmlfragment?
>:</b
></p
><br
/>
388 <?php
helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?
><br
/>
389 <?php
if ($usehtmleditor) {
390 helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
392 helpbutton("html", get_string("helphtml"), "moodle", true, true);
397 <?php
print_textarea($usehtmleditor, 20, 50, 680, 400, "alltext", $form->alltext
); ?
>
404 error(get_string("notypechosen", "resource"), $_SERVER["HTTP_REFERER"]);
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) ?>">
422 <input type
="submit" value
="<?php print_string("savechanges
") ?>">
423 <input type
="submit" name
=cancel value
="<?php print_string("cancel
") ?>">
427 if ($usehtmleditor and $form->type
== HTML
) {
430 print_simple_box_end();
431 print_footer($course);
434 error("This script was called incorrectly");