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
== "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";
249 } else if ($mimetype == 'application/pdf' ||
$mimetype == 'application/x-pdf') {
250 $resourcetype = "pdf";
255 $isteamspeak = (stripos($resource->reference
, 'teamspeak://') === 0);
257 /// Form the parse string
258 if (!empty($resource->alltext
)) {
260 $parray = explode(',', $resource->alltext
);
261 foreach ($parray as $fieldstring) {
262 $field = explode('=', $fieldstring);
263 $querys[] = urlencode($field[1]).'='.urlencode($this->parameters
[$field[0]]['value']);
266 $querystring = implode('?', $querys);
268 $querystring = implode('&', $querys);
273 /// Set up some variables
275 $inpopup = optional_param('inpopup', 0, PARAM_BOOL
);
277 if (resource_is_url($resource->reference
)) {
278 $fullurl = $resource->reference
;
279 if (!empty($querystring)) {
280 $urlpieces = parse_url($resource->reference
);
281 if (empty($urlpieces['query']) or $isteamspeak) {
282 $fullurl .= '?'.$querystring;
284 $fullurl .= '&'.$querystring;
288 } else if ($CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) { // Localpath
289 $localpath = get_user_preferences('resource_localpath', 'D:');
290 $relativeurl = str_replace(RESOURCE_LOCALPATH
, $localpath, $resource->reference
);
293 $relativeurl .= '?'.$querystring;
296 $relativeurl = str_replace('\\', '/', $relativeurl);
297 $relativeurl = str_replace(' ', '%20', $relativeurl);
298 $fullurl = 'file:///'.htmlentities($relativeurl);
301 } else { // Normal uploaded file
302 if ($CFG->slasharguments
) {
303 $relativeurl = "/file.php/{$course->id}/{$resource->reference}";
305 $relativeurl .= '?'.$querystring;
308 $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}";
310 $relativeurl .= '&'.$querystring;
313 $fullurl = "$CFG->wwwroot$relativeurl";
316 /// Print a notice and redirect if we are trying to access a file on a local file system
317 /// and the config setting has been disabled
318 if (!$CFG->resource_allowlocalfiles
and (strpos($resource->reference
, RESOURCE_LOCALPATH
) === 0)) {
320 print_header($pagetitle, $course->fullname
);
322 print_header($pagetitle, $course->fullname
, "$this->navigation ".format_string($resource->name
), "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
324 notify(get_string('notallowedlocalfileaccess', 'resource', ''));
326 close_window_button();
328 print_footer('none');
333 /// Check whether this is supposed to be a popup, but was called directly
334 if ($resource->popup
and !$inpopup) { /// Make a page and a pop-up window
336 print_header($pagetitle, $course->fullname
, "$this->navigation ".format_string($resource->name
), "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm));
339 echo "\n<script type=\"text/javascript\">";
341 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
345 if (trim(strip_tags($resource->summary
))) {
346 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions), "center");
349 $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name
,true)."</a>";
351 echo '<div class="popupnotice">';
352 print_string('popupresource', 'resource');
354 print_string('popupresourcelink', 'resource', $link);
357 print_footer($course);
362 /// Now check whether we need to display a frameset
364 $frameset = optional_param('frameset', '', PARAM_ALPHA
);
365 if (empty($frameset) and !$embedded and !$inpopup and ($resource->options
== "frame") and empty($USER->screenreader
)) {
366 @header
('Content-Type: text/html; charset=utf-8');
367 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
368 echo "<html dir=\"ltr\">\n";
370 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
371 echo "<title>" . format_string($course->shortname
) . ": ".strip_tags(format_string($resource->name
,true))."</title></head>\n";
372 echo "<frameset rows=\"$CFG->resource_framesize,*\">";
373 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" title=\"".get_string('modulename','resource')."\"/>";
374 if (!empty($localpath)) { // Show it like this so we interpose some HTML
375 echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" title=\"".get_string('modulename','resource')."\"/>";
377 echo "<frame src=\"$fullurl\" title=\"".get_string('modulename','resource')."\"/>";
385 /// We can only get here once per resource, so add an entry to the log
387 add_to_log($course->id
, "resource", "view", "view.php?id={$cm->id}", $resource->id
, $cm->id
);
390 /// If we are in a frameset, just print the top of it
392 if (!empty( $frameset ) and ($frameset == "top") ) {
394 print_header($pagetitle, $course->fullname
, "$this->navigation ".format_string($resource->name
), "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "parent"));
396 $options = new object();
397 $options->para
= false;
398 echo '<div class="summary">'.format_text($resource->summary
, FORMAT_HTML
, $options).'</div>';
399 if (!empty($localpath)) { // Show some help
400 echo '<div align="right" class="helplink">';
401 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
404 echo '</div></div></body></html>';
409 /// Display the actual resource
410 if ($embedded) { // Display resource embedded in page
411 $strdirectlink = get_string("directlink", "resource");
414 print_header($pagetitle);
416 print_header_simple($pagetitle, '', "$this->navigation <a $CFG->frametarget title=\"$strdirectlink\" href=\"$fullurl\"> ".format_string($resource->name
,true)."</a>", "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
), navmenu($course, $cm, "self"));
420 if ($resourcetype == "image") {
421 echo '<div class="resourcecontent resourceimg">';
422 echo "<img title=\"".strip_tags(format_string($resource->name
,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />";
425 } else if ($resourcetype == "mp3") {
426 if (!empty($THEME->resource_mp3player_colors
)) {
427 $c = $THEME->resource_mp3player_colors
; // You can set this up in your theme/xxx/config.php
429 $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
430 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
431 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
433 $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
434 $c = htmlentities($c);
435 $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache
436 $cleanurl = addslashes_js($fullurl);
439 // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins
441 echo '<div class="resourcecontent resourcemp3">';
443 echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'.
444 '<script type="text/javascript">'."\n".
446 'var FO = { movie:"'.$CFG->wwwroot
.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n".
447 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
448 'UFO.create(FO, "'.$id.'");'."\n".
454 echo "<object type=\"audio/mpeg\" data=\"$fullurl\" width=\"600\" height=\"70\">";
455 echo "<param name=\"src\" value=\"$fullurl\" />";
456 echo '<param name="quality" value="high" />';
457 echo '<param name="autoplay" value="true" />';
458 echo '<param name="autostart" value="true" />';
460 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
465 } else if ($resourcetype == "flv") {
466 $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache
467 $cleanurl = addslashes_js($fullurl);
470 // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins
472 echo '<div class="resourcecontent resourceflv">';
474 echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'.
475 '<script type="text/javascript">'."\n".
477 'var FO = { movie:"'.$CFG->wwwroot
.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n".
478 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", quality: "high" };'."\n".
479 'UFO.create(FO, "'.$id.'");'."\n".
485 echo "<object type=\"video/x-flv\" data=\"$fullurl\" width=\"600\" height=\"400\">";
486 echo "<param name=\"src\" value=\"$fullurl\" />";
487 echo '<param name="quality" value="high" />';
488 echo '<param name="autoplay" value="true" />';
489 echo '<param name="autostart" value="true" />';
491 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
496 } else if ($resourcetype == "mediaplayer") {
497 echo '<div class="resourcecontent resourcewmv">';
498 echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">';
499 echo '<param name="controller" value="true" />';
500 echo '<param name="autostart" value="true" />';
501 echo "<param name=\"src\" value=\"$fullurl\" />";
502 echo '<param name="scale" value="noScale" />';
503 echo "<a href=\"$fullurl\">$fullurl</a>";
507 } else if ($resourcetype == "mpeg") {
508 echo '<div class="resourcecontent resourcempeg">';
509 echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
510 codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701"
511 type="application/x-oleobject">';
512 echo "<param name=\"fileName\" value=\"$fullurl\" />";
513 echo '<param name="autoStart" value="true" />';
514 echo '<param name="animationatStart" value="true" />';
515 echo '<param name="transparentatStart" value="true" />';
516 echo '<param name="showControls" value="true" />';
517 echo '<param name="Volume" value="-450" />';
518 echo '<!--[if !IE]>-->';
519 echo '<object type="video/mpeg" data="' . $fullurl . '">';
520 echo '<param name="controller" value="true" />';
521 echo '<param name="autostart" value="true" />';
522 echo "<param name=\"src\" value=\"$fullurl\" />";
523 echo "<a href=\"$fullurl\">$fullurl</a>";
524 echo '<!--<![endif]-->';
525 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
526 echo '<!--[if !IE]>-->';
528 echo '<!--<![endif]-->';
532 } else if ($resourcetype == "quicktime") {
533 echo '<style type="text/css">';
534 echo '/* class to hide nested objects in IE */';
535 echo '/* hides the second object from all versions of IE */';
536 echo '* html object.hiddenObjectForIE { display: none; }';
537 echo '/* display the second object only for IE5 Mac */';
538 echo '/* IE Mac \*//*/';
539 echo '* html object.hiddenObjectForIE { display: inline; }';
542 echo '<div class="resourcecontent resourceqt">';
544 echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
545 echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
546 echo "<param name=\"src\" value=\"$fullurl\" />";
547 echo '<param name="autoplay" value="true" />';
548 echo '<param name="loop" value="true" />';
549 echo '<param name="controller" value="true" />';
550 echo '<param name="scale" value="aspect" />';
552 echo "<object class=\"hiddenObjectForIE\" type=\"video/quicktime\" data=\"$fullurl\">";
553 echo '<param name="controller" value="true" />';
554 echo '<param name="autoplay" value="true" />';
555 echo '<param name="loop" value="true" />';
556 echo '<param name="scale" value="aspect" />';
558 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
561 } else if ($resourcetype == "flash") {
562 echo '<div class="resourcecontent resourceswf">';
563 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
564 echo "<param name=\"movie\" value=\"$fullurl\" />";
565 echo '<param name="autoplay" value="true" />';
566 echo '<param name="loop" value="true" />';
567 echo '<param name="controller" value="true" />';
568 echo '<param name="scale" value="aspect" />';
569 echo '<!--[if !IE]>-->';
570 echo "<object type=\"application/x-shockwave-flash\" 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 } elseif ($resourcetype == 'pdf') {
583 echo '<div class="resourcepdf">';
584 echo '<object data="' . $fullurl . '" type="application/pdf">';
585 echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name
) . '</a>';
590 if (trim($resource->summary
)) {
591 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions, $course->id
), "center");
595 echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$strdirectlink</a>)</div>";
598 print_footer($course);
601 } else { // Display the resource on it's own
602 if (!empty($localpath)) { // Show a link to help work around browser security
603 echo '<div align="right" class="helplink">';
604 link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
606 echo "<div class=\"popupnotice\">(<a href=\"$fullurl\">$fullurl</a>)</div>";
614 //backwards compatible with existing resources
615 function set_encrypted_parameter() {
618 if (!empty($this->resource->reference
) && file_exists($CFG->dirroot
."/mod/resource/type/file/externserverfile.php")) {
619 include $CFG->dirroot
."/mod/resource/type/file/externserverfile.php";
620 if (function_exists(extern_server_file
)) {
621 return extern_server_file($this->resource->reference
);
624 return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase
);
627 function setup_preprocessing(&$defaults){
629 if (!isset($defaults['popup'])) {
632 } else if (!empty($defaults['popup'])) {
633 $defaults['windowpopup'] = 1;
634 if (array_key_exists('popup', $defaults)) {
635 $rawoptions = explode(',', $defaults['popup']);
636 foreach ($rawoptions as $rawoption) {
637 $option = explode('=', trim($rawoption));
638 $defaults[$option[0]] = $option[1];
642 $defaults['windowpopup'] = 0;
643 if (array_key_exists('options', $defaults)) {
644 $defaults['framepage'] = ($defaults['options']=='frame');
647 /// load up any stored parameters
648 if (!empty($defaults['alltext'])) {
649 $parray = explode(',', $defaults['alltext']);
651 foreach ($parray as $rawpar) {
652 list($param, $varname) = explode('=', $rawpar);
653 $defaults["parse$i"] = $varname;
654 $defaults["parameter$i"] = $param;
660 function setup_elements(&$mform) {
661 global $CFG, $RESOURCE_WINDOW_OPTIONS;
663 $this->set_parameters(); // set the parameter array for the form
665 $mform->addElement('choosecoursefile', 'reference', get_string('location'));
666 $mform->setDefault('reference', $CFG->resource_defaulturl
);
667 $mform->addRule('name', null, 'required', null, 'client');
669 if (!empty($CFG->resource_websearch
)) {
670 $searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...');
671 $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');");
672 $searchbutton->updateAttributes($buttonattributes);
675 if (!empty($CFG->resource_allowlocalfiles
)) {
676 $lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...');
677 $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
678 $url = '/mod/resource/type/file/localfile.php?choose=id_reference_value';
679 $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '".$lfbutton->getName()."', '$options', 0);");
680 $lfbutton->updateAttributes($buttonattributes);
683 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
685 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
686 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
687 $mform->setDefault('windowpopup', !empty($CFG->resource_popup
));
689 $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
691 $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
692 $mform->setDefault('framepage', 0);
693 $mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
694 $mform->setAdvanced('framepage');
696 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
697 if ($option == 'height' or $option == 'width') {
698 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
699 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
700 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
702 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
703 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
704 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
706 $mform->setAdvanced($option);
709 $mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
712 $options['-'] = get_string('chooseparameter', 'resource').'...';
714 foreach ($this->parameters
as $pname=>$param) {
715 if ($param['value']=='/optgroup') {
719 if ($param['value']=='optgroup') {
720 $optgroup = $param['langstr'];
723 $options[$pname] = $optgroup.' - '.$param['langstr'];
726 for ($i = 0; $i < $this->maxparameters
; $i++
) {
727 $parametername = "parameter$i";
728 $parsename = "parse$i";
730 $group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
731 $group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
732 $mform->addGroup($group, 'pargroup'.$i, get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
733 $mform->setAdvanced('pargroup'.$i);
735 $mform->setDefault($parametername, '-');