4 * Extend the base resource class for file resources
6 class resource_file
extends resource_base
{
8 function resource_file($cmid=0) {
9 parent
::resource_base($cmid);
13 var $maxparameters = 5;
17 * Sets the parameters property of the extended class
19 * @param USER global object
20 * @param CFG global object
22 function set_parameters() {
27 $littlecfg = new object; // to avoid some notices later
28 $littlecfg->wwwroot
= $CFG->wwwroot
;
31 $this->parameters
= array(
32 'label2' => array('langstr' => "",
33 'value' =>'/optgroup'),
34 'label3' => array('langstr' => get_string('course'),
35 'value' => 'optgroup'),
37 'courseid' => array('langstr' => 'id',
38 'value' => $this->course
->id
),
39 'coursefullname' => array('langstr' => get_string('fullname'),
40 'value' => $this->course
->fullname
),
41 'courseshortname' => array('langstr' => get_string('shortname'),
42 'value' => $this->course
->shortname
),
43 'courseidnumber' => array('langstr' => get_string('idnumbercourse'),
44 'value' => $this->course
->idnumber
),
45 'coursesummary' => array('langstr' => get_string('summary'),
46 'value' => $this->course
->summary
),
47 'courseformat' => array('langstr' => get_string('format'),
48 'value' => $this->course
->format
),
49 'courseteacher' => array('langstr' => get_string('wordforteacher'),
50 'value' => $this->course
->teacher
),
51 'courseteachers' => array('langstr' => get_string('wordforteachers'),
52 'value' => $this->course
->teachers
),
53 'coursestudent' => array('langstr' => get_string('wordforstudent'),
54 'value' => $this->course
->student
),
55 'coursestudents' => array('langstr' => get_string('wordforstudents'),
56 'value' => $this->course
->students
),
58 'label4' => array('langstr' => "",
59 'value' =>'/optgroup'),
60 'label5' => array('langstr' => get_string('miscellaneous'),
61 'value' => 'optgroup'),
63 'lang' => array('langstr' => get_string('preferredlanguage'),
64 'value' => current_language()),
65 'sitename' => array('langstr' => get_string('fullsitename'),
66 'value' => format_string($site->fullname
)),
67 'serverurl' => array('langstr' => get_string('serverurl', 'resource', $littlecfg),
68 'value' => $littlecfg->wwwroot
),
69 'currenttime' => array('langstr' => get_string('time'),
71 'encryptedcode' => array('langstr' => get_string('encryptedcode'),
72 'value' => $this->set_encrypted_parameter()),
74 'label6' => array('langstr' => "",
75 'value' =>'/optgroup')
78 if (!empty($USER->id
)) {
80 $userparameters = array(
82 'label1' => array('langstr' => get_string('user'),
83 'value' => 'optgroup'),
85 'userid' => array('langstr' => 'id',
86 'value' => $USER->id
),
87 'userusername' => array('langstr' => get_string('username'),
88 'value' => $USER->username
),
89 'useridnumber' => array('langstr' => get_string('idnumber'),
90 'value' => $USER->idnumber
),
91 'userfirstname' => array('langstr' => get_string('firstname'),
92 'value' => $USER->firstname
),
93 'userlastname' => array('langstr' => get_string('lastname'),
94 'value' => $USER->lastname
),
95 'userfullname' => array('langstr' => get_string('fullname'),
96 'value' => fullname($USER)),
97 'useremail' => array('langstr' => get_string('email'),
98 'value' => $USER->email
),
99 'usericq' => array('langstr' => get_string('icqnumber'),
100 'value' => $USER->icq
),
101 'userphone1' => array('langstr' => get_string('phone').' 1',
102 'value' => $USER->phone1
),
103 'userphone2' => array('langstr' => get_string('phone2').' 2',
104 'value' => $USER->phone2
),
105 'userinstitution' => array('langstr' => get_string('institution'),
106 'value' => $USER->institution
),
107 'userdepartment' => array('langstr' => get_string('department'),
108 'value' => $USER->department
),
109 'useraddress' => array('langstr' => get_string('address'),
110 'value' => $USER->address
),
111 'usercity' => array('langstr' => get_string('city'),
112 'value' => $USER->city
),
113 'usertimezone' => array('langstr' => get_string('timezone'),
114 'value' => get_user_timezone_offset()),
115 'userurl' => array('langstr' => get_string('webpage'),
116 'value' => $USER->url
)
119 $this->parameters
= $userparameters +
$this->parameters
;
123 function add_instance($resource) {
124 $this->_postprocess($resource);
125 return parent
::add_instance($resource);
129 function update_instance($resource) {
130 $this->_postprocess($resource);
131 return parent
::update_instance($resource);
134 function _postprocess(&$resource) {
135 global $RESOURCE_WINDOW_OPTIONS;
136 $alloptions = $RESOURCE_WINDOW_OPTIONS;
138 if ($resource->forcedownload
) {
139 $resource->popup
= '';
140 $resource->options
= 'forcedownload';
142 } else if ($resource->windowpopup
) {
143 $optionlist = array();
144 foreach ($alloptions as $option) {
145 $optionlist[] = $option."=".$resource->$option;
146 unset($resource->$option);
148 $resource->popup
= implode(',', $optionlist);
149 unset($resource->windowpopup
);
150 $resource->options
= '';
153 if (empty($resource->framepage
)) {
154 $resource->options
= '';
156 $resource->options
= 'frame';
158 unset($resource->framepage
);
159 $resource->popup
= '';
162 $optionlist = array();
163 for ($i = 0; $i < $this->maxparameters
; $i++
) {
164 $parametername = "parameter$i";
165 $parsename = "parse$i";
166 if (!empty($resource->$parsename) and $resource->$parametername != "-") {
167 $optionlist[] = $resource->$parametername."=".$resource->$parsename;
169 unset($resource->$parsename);
170 unset($resource->$parametername);
173 $resource->alltext
= implode(',', $optionlist);
178 * Display the file resource
180 * Displays a file resource embedded, in a frame, or in a popup.
181 * Output depends on type of file resource.
183 * @param CFG global object
186 global $CFG, $THEME, $USER;
188 /// Set up generic stuff first, including checking for access
191 /// Set up some shorthand variables
193 $course = $this->course
;
194 $resource = $this->resource;
197 $this->set_parameters(); // set the parameters array
199 ///////////////////////////////////////////////
201 /// Possible display modes are:
202 /// File displayed embedded in a normal page
203 /// File displayed in a popup window
204 /// File displayed embedded in a popup window
205 /// File not displayed at all, but downloaded
208 /// First, find out what sort of file we are dealing with.
209 require_once($CFG->libdir
.'/filelib.php');
214 $mimetype = mimeinfo("type", $resource->reference
);
215 $pagetitle = strip_tags($course->shortname
.': '.format_string($resource->name
));
217 $formatoptions = new object();
218 $formatoptions->noclean
= true;
220 if ($resource->options
!= "forcedownload") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
221 if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
222 $resourcetype = "image";
225 } else if ($mimetype == "audio/mp3") { // It's an MP3 audio file
226 $resourcetype = "mp3";
229 } else if ($mimetype == "video/x-flv") { // It's a Flash video file
230 $resourcetype = "flv";
233 } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
234 $resourcetype = "mediaplayer";
237 } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
238 $resourcetype = "quicktime";
241 } else if ($mimetype == "application/x-shockwave-flash") { // It's a Flash file
242 $resourcetype = "flash";
245 } else if ($mimetype == "video/mpeg") { // It's a Mpeg file
246 $resourcetype = "mpeg";
249 } else if ($mimetype == "text/html") { // It's a web page
250 $resourcetype = "html";
252 } else if ($mimetype == "application/zip") { // It's a zip archive
253 $resourcetype = "zip";
256 } else if ($mimetype == 'application/pdf' ||
$mimetype == 'application/x-pdf') {
257 $resourcetype = "pdf";
259 } else if ($mimetype == "audio/x-pn-realaudio") { // It's a realmedia file
260 $resourcetype = "rm";
265 $isteamspeak = (stripos($resource->reference
, 'teamspeak://') === 0);
267 /// Form the parse string
269 if (!empty($resource->alltext
)) {
270 $parray = explode(',', $resource->alltext
);
271 foreach ($parray as $fieldstring) {
272 $field = explode('=', $fieldstring);
273 $querys[] = urlencode($field[1]).'='.urlencode($this->parameters
[$field[0]]['value']);
276 $querystring = implode('?', $querys);
278 $querystring = implode('&', $querys);
283 /// Set up some variables
285 $inpopup = optional_param('inpopup', 0, PARAM_BOOL
);
287 if (resource_is_url($resource->reference
)) {
288 $fullurl = $resource->reference
;
289 if (!empty($querystring)) {
290 $urlpieces = parse_url($resource->reference
);
291 if (empty($urlpieces['query']) or $isteamspeak) {
292 $fullurl .= '?'.$querystring;
294 $fullurl .= '&'.$querystring;
298 } else if ($CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) { // Localpath
299 $localpath = get_user_preferences('resource_localpath', 'D:');
300 $relativeurl = str_replace(RESOURCE_LOCALPATH
, $localpath, $resource->reference
);
303 $relativeurl .= '?'.$querystring;
306 $relativeurl = str_replace('\\', '/', $relativeurl);
307 $relativeurl = str_replace(' ', '%20', $relativeurl);
308 $fullurl = 'file:///'.htmlentities($relativeurl);
311 } else { // Normal uploaded file
312 $forcedownloadsep = '?';
313 if ($resource->options
== 'forcedownload') {
314 $querys[] = 'forcedownload=1';
316 $fullurl = get_file_url($course->id
.'/'.$resource->reference
, $querys);
319 /// Print a notice and redirect if we are trying to access a file on a local file system
320 /// and the config setting has been disabled
321 if (!$CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) {
323 print_header($pagetitle, $course->fullname
);
325 $navigation = build_navigation($this->navlinks
, $cm);
326 print_header($pagetitle, $course->fullname
, $navigation,
327 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
329 notify(get_string('notallowedlocalfileaccess', 'resource', ''));
331 close_window_button();
333 print_footer('none');
338 /// Check whether this is supposed to be a popup, but was called directly
339 if ($resource->popup
and !$inpopup) { /// Make a page and a pop-up window
340 $navigation = build_navigation($this->navlinks
, $cm);
341 print_header($pagetitle, $course->fullname
, $navigation,
342 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
344 echo "\n<script type=\"text/javascript\">";
346 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
350 if (trim(strip_tags($resource->summary
))) {
351 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions), "center");
354 $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" "
355 . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', "
356 . "'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name
,true)."</a>";
358 echo '<div class="popupnotice">';
359 print_string('popupresource', 'resource');
361 print_string('popupresourcelink', 'resource', $link);
363 print_footer($course);
368 /// Now check whether we need to display a frameset
370 $frameset = optional_param('frameset', '', PARAM_ALPHA
);
371 if (empty($frameset) and !$embedded and !$inpopup and ($resource->options
== "frame") and empty($USER->screenreader
)) {
372 @header
('Content-Type: text/html; charset=utf-8');
373 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
374 echo "<html dir=\"ltr\">\n";
376 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
377 echo "<title>" . format_string($course->shortname
) . ": ".strip_tags(format_string($resource->name
,true))."</title></head>\n";
378 echo "<frameset rows=\"$CFG->resource_framesize,*\">";
379 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" title=\""
380 . get_string('modulename','resource')."\"/>";
381 if (!empty($localpath)) { // Show it like this so we interpose some HTML
382 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" title=\"".
383 get_string('modulename','resource')."\"/>";
385 echo "<frame src=\"$fullurl\" title=\"".get_string('modulename','resource')."\"/>";
393 /// We can only get here once per resource, so add an entry to the log
395 add_to_log($course->id
, "resource", "view", "view.php?id={$cm->id}", $resource->id
, $cm->id
);
398 /// If we are in a frameset, just print the top of it
400 if (!empty( $frameset ) and ($frameset == "top") ) {
401 $navigation = build_navigation($this->navlinks
, $cm);
402 print_header($pagetitle, $course->fullname
, $navigation,
403 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "parent"));
405 $options = new object();
406 $options->para
= false;
407 echo '<div class="summary">'.format_text($resource->summary
, FORMAT_HTML
, $options).'</div>';
408 if (!empty($localpath)) { // Show some help
409 echo '<div align="right" class="helplink">';
410 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
411 get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
414 print_footer('empty');
419 /// Display the actual resource
420 if ($embedded) { // Display resource embedded in page
421 $strdirectlink = get_string("directlink", "resource");
424 print_header($pagetitle);
426 $navigation = build_navigation($this->navlinks
, $cm);
427 print_header_simple($pagetitle, '', $navigation, "", "", true,
428 update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "self"));
432 if ($resourcetype == "image") {
433 echo '<div class="resourcecontent resourceimg">';
434 echo "<img title=\"".strip_tags(format_string($resource->name
,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />";
437 } else if ($resourcetype == "mp3") {
438 if (!empty($THEME->resource_mp3player_colors
)) {
439 $c = $THEME->resource_mp3player_colors
; // You can set this up in your theme/xxx/config.php
441 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
442 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
443 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
445 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
446 $c = htmlentities($c);
447 $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache
448 $cleanurl = addslashes_js($fullurl);
451 // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins
453 echo '<div class="resourcecontent resourcemp3">';
455 echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'.
456 '<script type="text/javascript">'."\n".
458 'var FO = { movie:"'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n".
459 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
460 'UFO.create(FO, "'.$id.'");'."\n".
466 echo "<object type=\"audio/mpeg\" data=\"$fullurl\" width=\"600\" height=\"70\">";
467 echo "<param name=\"src\" value=\"$fullurl\" />";
468 echo '<param name="quality" value="high" />';
469 echo '<param name="autoplay" value="true" />';
470 echo '<param name="autostart" value="true" />';
472 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
477 } else if ($resourcetype == "flv") {
478 $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache
479 $cleanurl = addslashes_js($fullurl);
482 // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins
484 echo '<div class="resourcecontent resourceflv">';
486 echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'.
487 '<script type="text/javascript">'."\n".
489 'var FO = { movie:"'.$CFG->wwwroot
.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n".
490 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", quality: "high" };'."\n".
491 'UFO.create(FO, "'.$id.'");'."\n".
497 echo "<object type=\"video/x-flv\" data=\"$fullurl\" width=\"600\" height=\"400\">";
498 echo "<param name=\"src\" value=\"$fullurl\" />";
499 echo '<param name="quality" value="high" />';
500 echo '<param name="autoplay" value="true" />';
501 echo '<param name="autostart" value="true" />';
503 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
508 } else if ($resourcetype == "mediaplayer") {
509 echo '<div class="resourcecontent resourcewmv">';
510 echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">';
511 echo '<param name="controller" value="true" />';
512 echo '<param name="autostart" value="true" />';
513 echo "<param name=\"src\" value=\"$fullurl\" />";
514 echo '<param name="scale" value="noScale" />';
515 echo "<a href=\"$fullurl\">$fullurl</a>";
519 } else if ($resourcetype == "mpeg") {
520 echo '<div class="resourcecontent resourcempeg">';
521 echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
522 codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701"
523 type="application/x-oleobject">';
524 echo "<param name=\"fileName\" value=\"$fullurl\" />";
525 echo '<param name="autoStart" value="true" />';
526 echo '<param name="animationatStart" value="true" />';
527 echo '<param name="transparentatStart" value="true" />';
528 echo '<param name="showControls" value="true" />';
529 echo '<param name="Volume" value="-450" />';
530 echo '<!--[if !IE]>-->';
531 echo '<object type="video/mpeg" data="' . $fullurl . '">';
532 echo '<param name="controller" value="true" />';
533 echo '<param name="autostart" value="true" />';
534 echo "<param name=\"src\" value=\"$fullurl\" />";
535 echo "<a href=\"$fullurl\">$fullurl</a>";
536 echo '<!--<![endif]-->';
537 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
538 echo '<!--[if !IE]>-->';
540 echo '<!--<![endif]-->';
543 } else if ($resourcetype == "rm") {
545 echo '<div class="resourcecontent resourcerm">';
546 echo '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="320" height="240">';
547 echo '<param name="src" value="' . $fullurl . '" />';
548 echo '<param name="controls" value="All" />';
549 echo '<!--[if !IE]>-->';
550 echo '<object type="audio/x-pn-realaudio-plugin" data="' . $fullurl . '" width="320" height="240">';
551 echo '<param name="controls" value="All" />';
552 echo '<a href="' . $fullurl . '">' . $fullurl .'</a>';
554 echo '<!--<![endif]-->';
558 } else if ($resourcetype == "quicktime") {
559 echo '<div class="resourcecontent resourceqt">';
561 echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
562 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
563 echo "<param name=\"src\" value=\"$fullurl\" />";
564 echo '<param name="autoplay" value="true" />';
565 echo '<param name="loop" value="true" />';
566 echo '<param name="controller" value="true" />';
567 echo '<param name="scale" value="aspect" />';
569 echo '<!--[if !IE]>-->';
570 echo "<object type=\"video/quicktime\" data=\"$fullurl\">";
571 echo '<param name="controller" value="true" />';
572 echo '<param name="autoplay" value="true" />';
573 echo '<param name="loop" value="true" />';
574 echo '<param name="scale" value="aspect" />';
575 echo '<!--<![endif]-->';
576 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
577 echo '<!--[if !IE]>-->';
579 echo '<!--<![endif]-->';
582 } else if ($resourcetype == "flash") {
583 echo '<div class="resourcecontent resourceswf">';
584 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
585 echo "<param name=\"movie\" value=\"$fullurl\" />";
586 echo '<param name="autoplay" value="true" />';
587 echo '<param name="loop" value="true" />';
588 echo '<param name="controller" value="true" />';
589 echo '<param name="scale" value="aspect" />';
590 echo '<!--[if !IE]>-->';
591 echo "<object type=\"application/x-shockwave-flash\" data=\"$fullurl\">";
592 echo '<param name="controller" value="true" />';
593 echo '<param name="autoplay" value="true" />';
594 echo '<param name="loop" value="true" />';
595 echo '<param name="scale" value="aspect" />';
596 echo '<!--<![endif]-->';
597 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
598 echo '<!--[if !IE]>-->';
600 echo '<!--<![endif]-->';
604 } elseif ($resourcetype == 'zip') {
605 echo '<div class="resourcepdf">';
606 echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name
) . '</a>';
609 } elseif ($resourcetype == 'pdf') {
610 echo '<div class="resourcepdf">';
611 echo '<object data="' . $fullurl . '" type="application/pdf">';
612 echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name
) . '</a>';
617 if (trim($resource->summary
)) {
618 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions, $course->id
), "center");
622 echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$strdirectlink</a>)</div>";
623 echo "</div>"; // MDL-12098
624 print_footer($course); // MDL-12098
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['options']) and $defaults['options'] === 'forcedownload') {
660 $defaults['forcedownload'] = 1;
662 } else if (!isset($defaults['popup'])) {
665 } else if (!empty($defaults['popup'])) {
666 $defaults['windowpopup'] = 1;
667 if (array_key_exists('popup', $defaults)) {
668 $rawoptions = explode(',', $defaults['popup']);
669 foreach ($rawoptions as $rawoption) {
670 $option = explode('=', trim($rawoption));
671 $defaults[$option[0]] = $option[1];
675 $defaults['windowpopup'] = 0;
676 if (array_key_exists('options', $defaults)) {
677 $defaults['framepage'] = ($defaults['options']=='frame');
680 /// load up any stored parameters
681 if (!empty($defaults['alltext'])) {
682 $parray = explode(',', $defaults['alltext']);
684 foreach ($parray as $rawpar) {
685 list($param, $varname) = explode('=', $rawpar);
686 $defaults["parse$i"] = $varname;
687 $defaults["parameter$i"] = $param;
696 function setup_elements(&$mform) {
697 global $CFG, $RESOURCE_WINDOW_OPTIONS;
699 $this->set_parameters(); // set the parameter array for the form
701 $mform->addElement('choosecoursefile', 'reference', get_string('location'));
702 $mform->setDefault('reference', $CFG->resource_defaulturl
);
703 $mform->addRule('name', null, 'required', null, 'client');
705 if (!empty($CFG->resource_websearch
)) {
706 $searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...');
707 $buttonattributes = array('title'=>get_string('searchweb', 'resource'), 'onclick'=>"return window.open('"
708 . "$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,"
709 . "scrollbars,resizable,width=800,height=600');");
710 $searchbutton->updateAttributes($buttonattributes);
713 if (!empty($CFG->resource_allowlocalfiles
)) {
714 $lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...');
715 $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
716 $url = '/mod/resource/type/file/localfile.php?choose=id_reference_value';
717 $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '"
718 . $lfbutton->getName()."', '$options', 0);");
719 $lfbutton->updateAttributes($buttonattributes);
722 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
724 $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource'));
725 $mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource'));
726 $mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1);
728 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
729 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
730 $mform->setDefault('windowpopup', !empty($CFG->resource_popup
));
731 $mform->disabledIf('windowpopup', 'forcedownload', 'checked');
733 $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
735 $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
736 $mform->setDefault('framepage', 0);
737 $mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
738 $mform->disabledIf('framepage', 'forcedownload', 'checked');
739 $mform->setAdvanced('framepage');
741 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
742 if ($option == 'height' or $option == 'width') {
743 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
744 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
745 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
747 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
748 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
749 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
751 $mform->setAdvanced($option);
754 $mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
757 $options['-'] = get_string('chooseparameter', 'resource').'...';
759 foreach ($this->parameters
as $pname=>$param) {
760 if ($param['value']=='/optgroup') {
764 if ($param['value']=='optgroup') {
765 $optgroup = $param['langstr'];
768 $options[$pname] = $optgroup.' - '.$param['langstr'];
771 for ($i = 0; $i < $this->maxparameters
; $i++
) {
772 $parametername = "parameter$i";
773 $parsename = "parse$i";
775 $group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
776 $group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
777 $mform->addGroup($group, 'pargroup'.$i, get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
778 $mform->setAdvanced('pargroup'.$i);
780 $mform->setDefault($parametername, '-');