diff --git a/mod/resource/config.html b/mod/resource/config.html
index b9234d508e1..1380d661360 100644
--- a/mod/resource/config.html
+++ b/mod/resource/config.html
@@ -28,6 +28,15 @@
+
+ resource_secretphrase:
+
+
+
+
+
+
+
resource_filterexternalpages:
diff --git a/mod/resource/coursefiles.php b/mod/resource/coursefiles.php
index fafe88b07e5..f9d92a3b001 100644
--- a/mod/resource/coursefiles.php
+++ b/mod/resource/coursefiles.php
@@ -67,7 +67,7 @@
+ onClick="lockoptions('form', 'windowpage', frameitem); document.form.windowpopup.checked=false; return lockoptions('form', 'windowpopup', popupitems);">
+
+
+
+
+
+
+
+ :
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ :
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php
new file mode 100644
index 00000000000..2b04df71a3a
--- /dev/null
+++ b/mod/resource/type/file/resource.class.php
@@ -0,0 +1,525 @@
+course->lang)) {
+ $CFG->courselang = $this->course->lang;
+ }
+ $site = get_site();
+
+
+ $this->parameters = array(
+
+ 'label1' => array('langstr' => get_string('user'),
+ 'value' => 'optgroup'),
+
+ 'userid' => array('langstr' => 'id',
+ 'value' => $USER->id),
+ 'userusername' => array('langstr' => get_string('username'),
+ 'value' => $USER->username),
+ 'useridnumber' => array('langstr' => get_string('idnumber'),
+ 'value' => $USER->idnumber),
+ 'userfirstname' => array('langstr' => get_string('firstname'),
+ 'value' => $USER->firstname),
+ 'userlastname' => array('langstr' => get_string('lastname'),
+ 'value' => $USER->lastname),
+ 'userfullname' => array('langstr' => get_string('fullname'),
+ 'value' => fullname($USER)),
+ 'useremail' => array('langstr' => get_string('email'),
+ 'value' => $USER->email),
+ 'usericq' => array('langstr' => get_string('icqnumber'),
+ 'value' => $USER->icq),
+ 'userphone1' => array('langstr' => get_string('phone'),
+ 'value' => $USER->phone1),
+ 'userinstitution' => array('langstr' => get_string('institution'),
+ 'value' => $USER->institution),
+ 'userdepartment' => array('langstr' => get_string('department'),
+ 'value' => $USER->department),
+ 'useraddress' => array('langstr' => get_string('address'),
+ 'value' => $USER->address),
+ 'usercity' => array('langstr' => get_string('city'),
+ 'value' => $USER->city),
+ 'usertimezone' => array('langstr' => get_string('timezone'),
+ 'value' => get_user_timezone()),
+ 'userurl' => array('langstr' => get_string('webpage'),
+ 'value' => $USER->url),
+
+ 'label2' => array('langstr' => "",
+ 'value' =>'/optgroup'),
+ 'label3' => array('langstr' => get_string('course'),
+ 'value' => 'optgroup'),
+
+ 'courseid' => array('langstr' => 'id',
+ 'value' => $this->course->id),
+ 'coursefullname' => array('langstr' => get_string('fullname'),
+ 'value' => $this->course->fullname),
+ 'courseshortname' => array('langstr' => get_string('shortname'),
+ 'value' => $this->course->shortname),
+ 'courseidnumber' => array('langstr' => get_string('idnumber'),
+ 'value' => $this->course->idnumber),
+ 'coursesummary' => array('langstr' => get_string('summary'),
+ 'value' => $this->course->summary),
+ 'courseformat' => array('langstr' => get_string('format'),
+ 'value' => $this->course->format),
+ 'courseteacher' => array('langstr' => get_string('wordforteacher'),
+ 'value' => $this->course->teacher),
+ 'courseteachers' => array('langstr' => get_string('wordforteachers'),
+ 'value' => $this->course->teachers),
+ 'coursestudent' => array('langstr' => get_string('wordforstudent'),
+ 'value' => $this->course->student),
+ 'coursestudents' => array('langstr' => get_string('wordforstudents'),
+ 'value' => $this->course->students),
+
+ 'label4' => array('langstr' => "",
+ 'value' =>'/optgroup'),
+ 'label5' => array('langstr' => get_string('miscellaneous'),
+ 'value' => 'optgroup'),
+
+ 'lang' => array('langstr' => get_string('preferredlanguage'),
+ 'value' => current_language()),
+ 'sitename' => array('langstr' => get_string('fullsitename'),
+ 'value' => $site->fullname),
+ 'currenttime' => array('langstr' => get_string('time'),
+ 'value' => time()),
+ 'encryptedcode' => array('langstr' => get_string('encryptedcode'),
+ 'value' => md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase)),
+
+ 'label6' => array('langstr' => "",
+ 'value' =>'/optgroup')
+ );
+
+}
+
+
+/**
+* Add new instance of file resource
+*
+* Create alltext field before calling base class function.
+*
+* @param resource object
+*/
+function add_instance($resource) {
+ $optionlist = array();
+
+ for ($i = 0; $i < $this->maxparameters; $i++) {
+ $parametername = "parameter$i";
+ $parsename = "parse$i";
+ if (!empty($resource->$parsename) and $resource->$parametername != "-") {
+ $optionlist[] = $resource->$parametername."=".$resource->$parsename;
+ }
+ }
+
+ $resource->alltext = implode(',', $optionlist);
+
+ return parent::add_instance($resource);
+}
+
+
+/**
+* Update instance of file resource
+*
+* Create alltext field before calling base class function.
+*
+* @param resource object
+*/
+function update_instance($resource) {
+ $optionlist = array();
+
+ for ($i = 0; $i < $this->maxparameters; $i++) {
+ $parametername = "parameter$i";
+ $parsename = "parse$i";
+ if (!empty($resource->$parsename) and $resource->$parametername != "-") {
+ $optionlist[] = $resource->$parametername."=".$resource->$parsename;
+ }
+ }
+
+ $resource->alltext = implode(',', $optionlist);
+
+ return parent::update_instance($resource);
+}
+
+
+/**
+* Display the file resource
+*
+* Displays a file resource embedded, in a frame, or in a popup.
+* Output depends on type of file resource.
+*
+* @param CFG global object
+* @param THEME global object
+*/
+function display() {
+ global $CFG, $THEME;
+
+ $this->set_parameters(); // set the parameters array
+
+
+ $strresource = get_string("modulename", "resource");
+ $strresources = get_string("modulenameplural", "resource");
+ $strlastmodified = get_string("lastmodified");
+
+ if ($this->course->category) {
+ require_login($this->course->id);
+ $navigation = "framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname} ->
+ framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->";
+ } else {
+ $navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->";
+ }
+
+
+
+///////////////////////////////////////////////
+
+ /// Possible display modes are:
+ /// File displayed in a frame in a normal window
+ /// File displayed embedded in a normal page
+ /// File displayed in a popup window
+ /// File displayed emebedded in a popup window
+
+
+ /// First, find out what sort of file we are dealing with.
+ require_once("$CFG->dirroot/files/mimetypes.php");
+
+ $resourcetype = "";
+ $embedded = false;
+ $mimetype = mimeinfo("type", $this->resource->reference);
+
+ if ($this->resource->options != "frame") {
+ if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
+ $resourcetype = "image";
+ $embedded = true;
+
+ } else if ($mimetype == "audio/mp3") { // It's an MP3 audio file
+ $resourcetype = "mp3";
+ $embedded = true;
+
+ } else if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file
+ $resourcetype = "mediaplayer";
+ $embedded = true;
+
+ } else if ($mimetype == "video/quicktime") { // It's a Quicktime file
+ $resourcetype = "quicktime";
+ $embedded = true;
+
+ } else if ($mimetype == "text/html") { // It's a web page
+ $resourcetype = "html";
+ }
+ }
+
+
+
+/// Form the parse string
+ if (!empty($this->resource->alltext)) {
+ $querys = array();
+ $parray = explode(',', $this->resource->alltext);
+ foreach ($parray as $fieldstring) {
+ $field = explode('=', $fieldstring);
+ $querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']);
+ }
+ $querystring = implode('&', $querys);
+ }
+
+
+ /// Set up some variables
+
+ $inpopup = !empty($_GET["inpopup"]);
+
+ if (resource_is_url($this->resource->reference)) {
+ $fullurl = $this->resource->reference;
+ if ($querystring) {
+ $urlpieces = parse_url($this->resource->reference);
+ if (empty($urlpieces['query'])) {
+ $fullurl .= '?'.$querystring;
+ } else {
+ $fullurl .= '&'.$querystring;
+ }
+ }
+ } else {
+ if ($CFG->slasharguments) {
+ $relativeurl = "/file.php/{$this->course->id}/{$this->resource->reference}";
+ if ($querystring) {
+ $relativeurl .= '?'.$querystring;
+ }
+ } else {
+ $relativeurl = "/file.php?file=/{$this->course->id}/{$this->resource->reference}";
+ if ($querystring) {
+ $relativeurl .= '&'.$querystring;
+ }
+ }
+ $fullurl = "$CFG->wwwroot$relativeurl";
+ }
+
+
+ /// Check whether this is supposed to be a popup, but was called directly
+
+ if ($this->resource->popup and !$inpopup) { /// Make a page and a pop-up window
+
+ print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm));
+
+
+ echo "\n';
+
+ if (trim($this->resource->summary)) {
+ print_simple_box(text_to_html($this->resource->summary), "center");
+ }
+
+ $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$this->cm->id}\" target=\"resource{$this->resource->id}\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$this->cm->id}', 'resource{$this->resource->id}','{$this->resource->popup}');\">{$this->resource->name} ";
+
+ echo " 
";
+ echo '';
+ print_string('popupresource', 'resource');
+ echo ' ';
+ print_string('popupresourcelink', 'resource', $link);
+ echo "
";
+
+ print_footer($this->course);
+ exit;
+ }
+
+
+ /// Now check whether we need to display a frameset
+
+ if (empty($_GET['frameset']) and !$embedded and !$inpopup and $this->resource->options == "frame") {
+ echo "{$this->course->shortname}: {$this->resource->name} \n";
+ echo "resource_framesize,*\" border=\"2\">";
+ echo " cm->id}&type={$this->resource->type}&frameset=top\">";
+ echo " ";
+ echo " ";
+ exit;
+ }
+
+
+ /// We can only get here once per resource, so add an entry to the log
+
+ add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id);
+
+
+ /// If we are in a frameset, just print the top of it
+
+ if ($_GET['frameset'] == "top") {
+ print_header($pagetitle, $this->course->fullname, "$navigation framename\" href=\"$fullurl\">{$this->resource->name} ", "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm, "parent"));
+
+ echo "".text_to_html($this->resource->summary, true, false)." ";
+ echo "