4 * Extend the base resource class for file resources
6 * Extend the base resource class for file resources
9 class resource_file
extends resource_base
{
11 function resource_file($cmid=0) {
12 parent
::resource_base($cmid);
16 var $maxparameters = 5;
20 * Sets the parameters property of the extended class
22 * Sets the parameters property of the extended file resource class
24 * @param USER global object
25 * @param CFG global object
27 function set_parameters() {
33 $this->parameters
= array(
34 'label2' => array('langstr' => "",
35 'value' =>'/optgroup'),
36 'label3' => array('langstr' => get_string('course'),
37 'value' => 'optgroup'),
39 'courseid' => array('langstr' => 'id',
40 'value' => $this->course
->id
),
41 'coursefullname' => array('langstr' => get_string('fullname'),
42 'value' => $this->course
->fullname
),
43 'courseshortname' => array('langstr' => get_string('shortname'),
44 'value' => $this->course
->shortname
),
45 'courseidnumber' => array('langstr' => get_string('idnumbercourse'),
46 'value' => $this->course
->idnumber
),
47 'coursesummary' => array('langstr' => get_string('summary'),
48 'value' => $this->course
->summary
),
49 'courseformat' => array('langstr' => get_string('format'),
50 'value' => $this->course
->format
),
51 'courseteacher' => array('langstr' => get_string('wordforteacher'),
52 'value' => $this->course
->teacher
),
53 'courseteachers' => array('langstr' => get_string('wordforteachers'),
54 'value' => $this->course
->teachers
),
55 'coursestudent' => array('langstr' => get_string('wordforstudent'),
56 'value' => $this->course
->student
),
57 'coursestudents' => array('langstr' => get_string('wordforstudents'),
58 'value' => $this->course
->students
),
60 'label4' => array('langstr' => "",
61 'value' =>'/optgroup'),
62 'label5' => array('langstr' => get_string('miscellaneous'),
63 'value' => 'optgroup'),
65 'lang' => array('langstr' => get_string('preferredlanguage'),
66 'value' => current_language()),
67 'sitename' => array('langstr' => get_string('fullsitename'),
68 'value' => format_string($site->fullname
)),
69 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $CFG),
70 'value' => $CFG->wwwroot
),
71 'currenttime' => array('langstr' => get_string('time'),
73 'encryptedcode' => array('langstr' => get_string('encryptedcode'),
74 'value' => $this->set_encrypted_parameter()),
76 'label6' => array('langstr' => "",
77 'value' =>'/optgroup')
80 if (!empty($USER->id
)) {
82 $userparameters = array(
84 'label1' => array('langstr' => get_string('user'),
85 'value' => 'optgroup'),
87 'userid' => array('langstr' => 'id',
88 'value' => $USER->id
),
89 'userusername' => array('langstr' => get_string('username'),
90 'value' => $USER->username
),
91 'useridnumber' => array('langstr' => get_string('idnumber'),
92 'value' => $USER->idnumber
),
93 'userfirstname' => array('langstr' => get_string('firstname'),
94 'value' => $USER->firstname
),
95 'userlastname' => array('langstr' => get_string('lastname'),
96 'value' => $USER->lastname
),
97 'userfullname' => array('langstr' => get_string('fullname'),
98 'value' => fullname($USER)),
99 'useremail' => array('langstr' => get_string('email'),
100 'value' => $USER->email
),
101 'usericq' => array('langstr' => get_string('icqnumber'),
102 'value' => $USER->icq
),
103 'userphone1' => array('langstr' => get_string('phone').' 1',
104 'value' => $USER->phone1
),
105 'userphone2' => array('langstr' => get_string('phone').' 2',
106 'value' => $USER->phone2
),
107 'userinstitution' => array('langstr' => get_string('institution'),
108 'value' => $USER->institution
),
109 'userdepartment' => array('langstr' => get_string('department'),
110 'value' => $USER->department
),
111 'useraddress' => array('langstr' => get_string('address'),
112 'value' => $USER->address
),
113 'usercity' => array('langstr' => get_string('city'),
114 'value' => $USER->city
),
115 'usertimezone' => array('langstr' => get_string('timezone'),
116 'value' => get_user_timezone_offset()),
117 'userurl' => array('langstr' => get_string('webpage'),
118 'value' => $USER->url
)
121 $this->parameters
= $userparameters +
$this->parameters
;
125 function add_instance($resource) {
126 $this->_postprocess($resource);
127 return parent
::add_instance($resource);
131 function update_instance($resource) {
132 $this->_postprocess($resource);
133 return parent
::update_instance($resource);
136 function _postprocess(&$resource) {
137 global $RESOURCE_WINDOW_OPTIONS;
138 $alloptions = $RESOURCE_WINDOW_OPTIONS;
140 if ($resource->windowpopup
) {
141 $optionlist = array();
142 foreach ($alloptions as $option) {
143 $optionlist[] = $option."=".$resource->$option;
144 unset($resource->$option);
146 $resource->popup
= implode(',', $optionlist);
147 unset($resource->windowpopup
);
148 $resource->options
= '';
151 if (empty($resource->framepage
)) {
152 $resource->options
= '';
154 $resource->options
= 'frame';
156 unset($resource->framepage
);
157 $resource->popup
= '';
160 $optionlist = array();
161 for ($i = 0; $i < $this->maxparameters
; $i++
) {
162 $parametername = "parameter$i";
163 $parsename = "parse$i";
164 if (!empty($resource->$parsename) and $resource->$parametername != "-") {
165 $optionlist[] = $resource->$parametername."=".$resource->$parsename;
167 unset($resource->$parsename);
168 unset($resource->$parametername);
171 $resource->alltext
= implode(',', $optionlist);
176 * Display the file resource
178 * Displays a file resource embedded, in a frame, or in a popup.
179 * Output depends on type of file resource.
181 * @param CFG global object
184 global $CFG, $THEME, $USER;
186 /// Set up generic stuff first, including checking for access
189 /// Set up some shorthand variables
191 $course = $this->course
;
192 $resource = $this->resource;
195 $this->set_parameters(); // set the parameters array
197 ///////////////////////////////////////////////
199 /// Possible display modes are:
200 /// File displayed in a frame in a normal window
201 /// File displayed embedded in a normal page
202 /// File displayed in a popup window
203 /// File displayed emebedded in a popup window
206 /// First, find out what sort of file we are dealing with.
207 require_once($CFG->libdir
.'/filelib.php');
212 $mimetype = mimeinfo("type", $resource->reference
);
213 $pagetitle = strip_tags($course->shortname
.': '.format_string($resource->name
));
215 $formatoptions = new object();
216 $formatoptions->noclean
= true;
218 if ($resource->options
!= "bogusoption_usedtobe_frame") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
219 if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
220 $resourcetype = "image";
223 } else if ($mimetype == "audio/mp3") { // It's an MP3 audio file
224 $resourcetype = "mp3";
227 } else if ($mimetype == "video/x-flv") { // It's a Flash video file
228 $resourcetype = "flv";
231 } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
232 $resourcetype = "mediaplayer";
235 } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
236 $resourcetype = "quicktime";
239 } else if ($mimetype == "application/x-shockwave-flash") { // It's a Flash file
240 $resourcetype = "flash";
243 } else if ($mimetype == "video/mpeg") { // It's a Mpeg file
244 $resourcetype = "mpeg";
247 } else if ($mimetype == "text/html") { // It's a web page
248 $resourcetype = "html";
250 } else if ($mimetype == "application/zip") { // It's a zip archive
251 $resourcetype = "zip";
254 } else if ($mimetype == 'application/pdf' ||
$mimetype == 'application/x-pdf') {
255 $resourcetype = "pdf";
260 $isteamspeak = (stripos($resource->reference
, 'teamspeak://') === 0);
262 /// Form the parse string
263 if (!empty($resource->alltext
)) {
265 $parray = explode(',', $resource->alltext
);
266 foreach ($parray as $fieldstring) {
267 $field = explode('=', $fieldstring);
268 $querys[] = urlencode($field[1]).'='.urlencode($this->parameters
[$field[0]]['value']);
271 $querystring = implode('?', $querys);
273 $querystring = implode('&', $querys);
278 /// Set up some variables
280 $inpopup = optional_param('inpopup', 0, PARAM_BOOL
);
282 if (resource_is_url($resource->reference
)) {
283 $fullurl = $resource->reference
;
284 if (!empty($querystring)) {
285 $urlpieces = parse_url($resource->reference
);
286 if (empty($urlpieces['query']) or $isteamspeak) {
287 $fullurl .= '?'.$querystring;
289 $fullurl .= '&'.$querystring;
293 } else if ($CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) { // Localpath
294 $localpath = get_user_preferences('resource_localpath', 'D:');
295 $relativeurl = str_replace(RESOURCE_LOCALPATH
, $localpath, $resource->reference
);
298 $relativeurl .= '?'.$querystring;
301 $relativeurl = str_replace('\\', '/', $relativeurl);
302 $relativeurl = str_replace(' ', '%20', $relativeurl);
303 $fullurl = 'file:///'.htmlentities($relativeurl);
306 } else { // Normal uploaded file
307 if ($CFG->slasharguments
) {
308 $relativeurl = "/file.php/{$course->id}/{$resource->reference}";
310 $relativeurl .= '?'.$querystring;
313 $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}";
315 $relativeurl .= '&'.$querystring;
318 $fullurl = "$CFG->wwwroot$relativeurl";
321 /// Print a notice and redirect if we are trying to access a file on a local file system
322 /// and the config setting has been disabled
323 if (!$CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) {
325 print_header($pagetitle, $course->fullname
);
327 $this->navlinks
[] = array('name' => format_string($resource->name
), 'link' => null, 'type' => 'misc');
328 $this->navigation
= build_navigation($this->navlinks
);
329 print_header($pagetitle, $course->fullname
, $this->navigation
,
330 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
332 notify(get_string('notallowedlocalfileaccess', 'resource', ''));
334 close_window_button();
336 print_footer('none');
341 /// Check whether this is supposed to be a popup, but was called directly
342 if ($resource->popup
and !$inpopup) { /// Make a page and a pop-up window
343 $this->navlinks
[] = array('name' => format_string($resource->name
), 'link' => null, 'type' => 'misc');
344 $this->navigation
= build_navigation($this->navlinks
);
346 print_header($pagetitle, $course->fullname
, $this->navigation
,
347 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
350 echo "\n<script type=\"text/javascript\">";
352 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
356 if (trim(strip_tags($resource->summary
))) {
357 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions), "center");
360 $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" "
361 . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', "
362 . "'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name
,true)."</a>";
364 echo '<div class="popupnotice">';
365 print_string('popupresource', 'resource');
367 print_string('popupresourcelink', 'resource', $link);
370 print_footer($course);
375 /// Now check whether we need to display a frameset
377 $frameset = optional_param('frameset', '', PARAM_ALPHA
);
378 if (empty($frameset) and !$embedded and !$inpopup and ($resource->options
== "frame") and empty($USER->screenreader
)) {
379 @header
('Content-Type: text/html; charset=utf-8');
380 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
381 echo "<html dir=\"ltr\">\n";
383 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
384 echo "<title>" . format_string($course->shortname
) . ": ".strip_tags(format_string($resource->name
,true))."</title></head>\n";
385 echo "<frameset rows=\"$CFG->resource_framesize,*\">";
386 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" title=\""
387 . get_string('modulename','resource')."\"/>";
388 if (!empty($localpath)) { // Show it like this so we interpose some HTML
389 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" title=\"".
390 get_string('modulename','resource')."\"/>";
392 echo "<frame src=\"$fullurl\" title=\"".get_string('modulename','resource')."\"/>";
400 /// We can only get here once per resource, so add an entry to the log
402 add_to_log($course->id
, "resource", "view", "view.php?id={$cm->id}", $resource->id
, $cm->id
);
405 /// If we are in a frameset, just print the top of it
407 if (!empty( $frameset ) and ($frameset == "top") ) {
408 $this->navlinks
[] = array('name' => format_string($resource->name
), 'link' => null, 'type' => 'misc');
409 $this->navigation
= build_navigation($this->navlinks
);
410 print_header($pagetitle, $course->fullname
, $this->navigation
,
411 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "parent"));
413 $options = new object();
414 $options->para
= false;
415 echo '<div class="summary">'.format_text($resource->summary
, FORMAT_HTML
, $options).'</div>';
416 if (!empty($localpath)) { // Show some help
417 echo '<div align="right" class="helplink">';
418 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
419 get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
422 echo '</div></div></body></html>';
427 /// Display the actual resource
428 if ($embedded) { // Display resource embedded in page
429 $strdirectlink = get_string("directlink", "resource");
432 print_header($pagetitle);
434 $this->navlinks
[] = array('name' => format_string($resource->name
, true),
437 $this->navigation
= build_navigation($this->navlinks
);
438 print_header_simple($pagetitle, '', $this->navigation
, "", "", true,
439 update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "self"));
443 if ($resourcetype == "image") {
444 echo '<div class="resourcecontent resourceimg">';
445 echo "<img title=\"".strip_tags(format_string($resource->name
,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />";
448 } else if ($resourcetype == "mp3") {
449 if (!empty($THEME->resource_mp3player_colors
)) {
450 $c = $THEME->resource_mp3player_colors
; // You can set this up in your theme/xxx/config.php
452 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
453 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
454 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
456 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
457 $c = htmlentities($c);
458 $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache
459 $cleanurl = addslashes_js($fullurl);
462 // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins
464 echo '<div class="resourcecontent resourcemp3">';
466 echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'.
467 '<script type="text/javascript">'."\n".
469 'var FO = { movie:"'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n".
470 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
471 'UFO.create(FO, "'.$id.'");'."\n".
477 echo "<object type=\"audio/mpeg\" data=\"$fullurl\" width=\"600\" height=\"70\">";
478 echo "<param name=\"src\" value=\"$fullurl\" />";
479 echo '<param name="quality" value="high" />';
480 echo '<param name="autoplay" value="true" />';
481 echo '<param name="autostart" value="true" />';
483 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
488 } else if ($resourcetype == "flv") {
489 $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache
490 $cleanurl = addslashes_js($fullurl);
493 // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins
495 echo '<div class="resourcecontent resourceflv">';
497 echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'.
498 '<script type="text/javascript">'."\n".
500 'var FO = { movie:"'.$CFG->wwwroot
.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n".
501 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", quality: "high" };'."\n".
502 'UFO.create(FO, "'.$id.'");'."\n".
508 echo "<object type=\"video/x-flv\" data=\"$fullurl\" width=\"600\" height=\"400\">";
509 echo "<param name=\"src\" value=\"$fullurl\" />";
510 echo '<param name="quality" value="high" />';
511 echo '<param name="autoplay" value="true" />';
512 echo '<param name="autostart" value="true" />';
514 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
519 } else if ($resourcetype == "mediaplayer") {
520 echo '<div class="resourcecontent resourcewmv">';
521 echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">';
522 echo '<param name="controller" value="true" />';
523 echo '<param name="autostart" value="true" />';
524 echo "<param name=\"src\" value=\"$fullurl\" />";
525 echo '<param name="scale" value="noScale" />';
526 echo "<a href=\"$fullurl\">$fullurl</a>";
530 } else if ($resourcetype == "mpeg") {
531 echo '<div class="resourcecontent resourcempeg">';
532 echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
533 codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701"
534 type="application/x-oleobject">';
535 echo "<param name=\"fileName\" value=\"$fullurl\" />";
536 echo '<param name="autoStart" value="true" />';
537 echo '<param name="animationatStart" value="true" />';
538 echo '<param name="transparentatStart" value="true" />';
539 echo '<param name="showControls" value="true" />';
540 echo '<param name="Volume" value="-450" />';
541 echo '<!--[if !IE]>-->';
542 echo '<object type="video/mpeg" data="' . $fullurl . '">';
543 echo '<param name="controller" value="true" />';
544 echo '<param name="autostart" value="true" />';
545 echo "<param name=\"src\" value=\"$fullurl\" />";
546 echo "<a href=\"$fullurl\">$fullurl</a>";
547 echo '<!--<![endif]-->';
548 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
549 echo '<!--[if !IE]>-->';
551 echo '<!--<![endif]-->';
555 } else if ($resourcetype == "quicktime") {
556 echo '<style type="text/css">';
557 echo '/* class to hide nested objects in IE */';
558 echo '/* hides the second object from all versions of IE */';
559 echo '* html object.hiddenObjectForIE { display: none; }';
560 echo '/* display the second object only for IE5 Mac */';
561 echo '/* IE Mac \*//*/';
562 echo '* html object.hiddenObjectForIE { display: inline; }';
565 echo '<div class="resourcecontent resourceqt">';
567 echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
568 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
569 echo "<param name=\"src\" value=\"$fullurl\" />";
570 echo '<param name="autoplay" value="true" />';
571 echo '<param name="loop" value="true" />';
572 echo '<param name="controller" value="true" />';
573 echo '<param name="scale" value="aspect" />';
575 echo "<object class=\"hiddenObjectForIE\" type=\"video/quicktime\" data=\"$fullurl\">";
576 echo '<param name="controller" value="true" />';
577 echo '<param name="autoplay" value="true" />';
578 echo '<param name="loop" value="true" />';
579 echo '<param name="scale" value="aspect" />';
581 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
584 } else if ($resourcetype == "flash") {
585 echo '<div class="resourcecontent resourceswf">';
586 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
587 echo "<param name=\"movie\" value=\"$fullurl\" />";
588 echo '<param name="autoplay" value="true" />';
589 echo '<param name="loop" value="true" />';
590 echo '<param name="controller" value="true" />';
591 echo '<param name="scale" value="aspect" />';
592 echo '<!--[if !IE]>-->';
593 echo "<object type=\"application/x-shockwave-flash\" data=\"$fullurl\">";
594 echo '<param name="controller" value="true" />';
595 echo '<param name="autoplay" value="true" />';
596 echo '<param name="loop" value="true" />';
597 echo '<param name="scale" value="aspect" />';
598 echo '<!--<![endif]-->';
599 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
600 echo '<!--[if !IE]>-->';
602 echo '<!--<![endif]-->';
606 } elseif ($resourcetype == 'zip') {
607 echo '<div class="resourcepdf">';
608 echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name
) . '</a>';
611 } elseif ($resourcetype == 'pdf') {
612 echo '<div class="resourcepdf">';
613 echo '<object data="' . $fullurl . '" type="application/pdf">';
614 echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name
) . '</a>';
619 if (trim($resource->summary
)) {
620 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions, $course->id
), "center");
624 echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$strdirectlink</a>)</div>";
627 print_footer($course);
630 } else { // Display the resource on it's own
631 if (!empty($localpath)) { // Show a link to help work around browser security
632 echo '<div align="right" class="helplink">';
633 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
634 get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
636 echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$fullurl</a>)</div>";
644 //backwards compatible with existing resources
645 function set_encrypted_parameter() {
648 if (!empty($this->resource->reference
) && file_exists($CFG->dirroot
."/mod/resource/type/file/externserverfile.php")) {
649 include $CFG->dirroot
."/mod/resource/type/file/externserverfile.php";
650 if (function_exists(extern_server_file
)) {
651 return extern_server_file($this->resource->reference
);
654 return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase
);
657 function setup_preprocessing(&$defaults){
659 if (!isset($defaults['popup'])) {
662 } else if (!empty($defaults['popup'])) {
663 $defaults['windowpopup'] = 1;
664 if (array_key_exists('popup', $defaults)) {
665 $rawoptions = explode(',', $defaults['popup']);
666 foreach ($rawoptions as $rawoption) {
667 $option = explode('=', trim($rawoption));
668 $defaults[$option[0]] = $option[1];
672 $defaults['windowpopup'] = 0;
673 if (array_key_exists('options', $defaults)) {
674 $defaults['framepage'] = ($defaults['options']=='frame');
677 /// load up any stored parameters
678 if (!empty($defaults['alltext'])) {
679 $parray = explode(',', $defaults['alltext']);
681 foreach ($parray as $rawpar) {
682 list($param, $varname) = explode('=', $rawpar);
683 $defaults["parse$i"] = $varname;
684 $defaults["parameter$i"] = $param;
690 function setup_elements(&$mform) {
691 global $CFG, $RESOURCE_WINDOW_OPTIONS;
693 $this->set_parameters(); // set the parameter array for the form
695 $mform->addElement('choosecoursefile', 'reference', get_string('location'));
696 $mform->setDefault('reference', $CFG->resource_defaulturl
);
697 $mform->addRule('name', null, 'required', null, 'client');
699 if (!empty($CFG->resource_websearch
)) {
700 $searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...');
701 $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return window.open('"
702 . "$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,"
703 . "scrollbars,resizable,width=800,height=600');");
704 $searchbutton->updateAttributes($buttonattributes);
707 if (!empty($CFG->resource_allowlocalfiles
)) {
708 $lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...');
709 $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
710 $url = '/mod/resource/type/file/localfile.php?choose=id_reference_value';
711 $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '"
712 . $lfbutton->getName()."', '$options', 0);");
713 $lfbutton->updateAttributes($buttonattributes);
716 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
718 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
719 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
720 $mform->setDefault('windowpopup', !empty($CFG->resource_popup
));
722 $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
724 $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
725 $mform->setDefault('framepage', 0);
726 $mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
727 $mform->setAdvanced('framepage');
729 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
730 if ($option == 'height' or $option == 'width') {
731 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
732 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
733 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
735 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
736 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
737 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
739 $mform->setAdvanced($option);
742 $mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
745 $options['-'] = get_string('chooseparameter', 'resource').'...';
747 foreach ($this->parameters
as $pname=>$param) {
748 if ($param['value']=='/optgroup') {
752 if ($param['value']=='optgroup') {
753 $optgroup = $param['langstr'];
756 $options[$pname] = $optgroup.' - '.$param['langstr'];
759 for ($i = 0; $i < $this->maxparameters
; $i++
) {
760 $parametername = "parameter$i";
761 $parsename = "parse$i";
763 $group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
764 $group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
765 $mform->addGroup($group, 'pargroup'.$i, get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
766 $mform->setAdvanced('pargroup'.$i);
768 $mform->setDefault($parametername, '-');