From: moodler Date: Sun, 25 Jul 2004 14:32:05 +0000 (+0000) Subject: Merged in the new resource structure to TRUNK X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d18830fe31bea658ccf3f065f9e26dfa81869840;p=moodle.git Merged in the new resource structure to TRUNK --- diff --git a/mod/resource/config.html b/mod/resource/config.html index b9234d508e..1380d66136 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 fafe88b07e..f9d92a3b00 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);"> + +

+ + + + + +

:

+ + + + + + + + + + +
+ + + +

:

+ + + + + + + + + + + + +maxparameters; $i++) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; +} + +?> + +

\n"; + echo "\n"; + echo "\n"; + echo "
+ + + +
+ + diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php new file mode 100644 index 0000000000..2b04df71a3 --- /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 ""; + exit; + } + + + /// Display the actual resource + + if ($embedded) { // Display resource embedded in page + $strdirectlink = get_string("directlink", "resource"); + + if ($inpopup) { + print_header($pagetitle); + } else { + 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, "self")); + + } + + if ($resourcetype == "image") { + echo "

"; + echo "resource->name}\" class=\"resourceimage\" src=\"$fullurl\">"; + echo "

"; + + } else if ($resourcetype == "mp3") { + echo "

"; + echo ''; + echo "wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\">"; + echo ''; + echo ''; + echo "wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\" "; + echo " quality=high bgcolor=\"#333333\" width=\"600\" height=\"70\" name=\"mp3player\" "; + echo ' type="application/x-shockwave-flash" '; + echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">'; + echo ''; + echo ''; + echo "

"; + + } else if ($resourcetype == "mediaplayer") { + echo "

"; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo "\n'; + echo ''; + echo ''; + echo "

"; + + } else if ($resourcetype == "quicktime") { + + echo "

"; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ''; + echo "\n'; + echo ''; + echo ''; + echo "

"; + } + + if (trim($this->resource->summary)) { + print_simple_box(format_text($this->resource->summary), 'center'); + } + + if ($inpopup) { + echo "

($strdirectlink)

"; + } else { + print_spacer(20,20); + print_footer($this->course); + } + + } else { // Display the resource on it's own + redirect($fullurl); + } + +} + + + +/** +* Setup a new file resource +* +* Display a form to create a new or edit an existing file resource +* +* @param form object +* @param CFG global object +* @param usehtmleditor global integer +* @param RESOURCE_WINDOW_OPTIONS global array +*/ +function setup($form) { + global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS; + + $this->set_parameters(); // set the parameter array for the form + + + $strfilename = get_string("filename", "resource"); + $strnote = get_string("note", "resource"); + $strchooseafile = get_string("chooseafile", "resource"); + $strnewwindow = get_string("newwindow", "resource"); + $strnewwindowopen = get_string("newwindowopen", "resource"); + $strsearch = get_string("searchweb", "resource"); + + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $stringname = "str$optionname"; + $$stringname = get_string("new$optionname", "resource"); + $window->$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + + $frameoption = "\"framepage\""; + $popupoptions = implode(",", $jsoption); + $jsoption[] = $frameoption; + $alloptions = implode(",", $jsoption); + + + + if ($form->instance) { // Re-editing + if (!$form->popup) { + $windowtype = "page"; // No popup text => in page + } else { + $windowtype = "popup"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = "checked"; + } + } + } + } else { + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "resource_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + + $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; + if (!isset($form->options)) { + $form->options = 'frame'; + $form->reference = $CFG->resource_defaulturl; + } + } + + +/// set the 5 parameter defaults + $alltextfield = array(); + for ($i = 0; $i < $this->maxparameters; $i++) { + $alltextfield[] = array('parameter' => '', + 'parse' => ''); + } + /// load up any stored parameters + if (!empty($form->alltext)) { + $parray = explode(',', $form->alltext); + foreach ($parray as $key => $fieldstring) { + $field = explode('=', $fieldstring); + $alltextfield[$key]['parameter'] = $field[0]; + $alltextfield[$key]['parse'] = $field[1]; + } + } + + + parent::setup($form); + + include("$CFG->dirroot/mod/resource/type/file/file.html"); + + parent::setup_end(); +} + +} + +?> diff --git a/mod/resource/type/html/html.html b/mod/resource/type/html/html.html new file mode 100644 index 0000000000..53a279ea89 --- /dev/null +++ b/mod/resource/type/html/html.html @@ -0,0 +1,14 @@ + + +

:


+ +
+
+
+
+ + + alltext); ?> + + + diff --git a/mod/resource/type/html/resource.class.php b/mod/resource/type/html/resource.class.php new file mode 100644 index 0000000000..59088d193b --- /dev/null +++ b/mod/resource/type/html/resource.class.php @@ -0,0 +1,53 @@ +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 ->"; } + + + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + 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)); + + print_simple_box(format_text($this->resource->alltext, FORMAT_HTML), "center", "", "$THEME->cellcontent", "20"); + + echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + + print_footer($this->course); +} + + + +function setup($form) { + global $CFG, $usehtmleditor; + + parent::setup($form); + + include("$CFG->dirroot/mod/resource/type/html/html.html"); + + parent::setup_end(); +} + + +} + +?> diff --git a/mod/resource/type/reference/reference.html b/mod/resource/type/reference/reference.html new file mode 100644 index 0000000000..d6e19710a7 --- /dev/null +++ b/mod/resource/type/reference/reference.html @@ -0,0 +1,17 @@ + + +

:

+ + + + + + + +

()

+ + +

+ + + diff --git a/mod/resource/type/reference/resource.class.php b/mod/resource/type/reference/resource.class.php new file mode 100644 index 0000000000..ea9d8ec1f6 --- /dev/null +++ b/mod/resource/type/reference/resource.class.php @@ -0,0 +1,59 @@ +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 ->"; } + + + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + 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)); + + print_simple_box($this->resource->reference, "center"); + echo "

"; + echo text_to_html($this->resource->summary); + echo "

"; + echo "

 

"; + echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + echo "
"; + print_footer($this->course); +} + + + +function setup($form) { + global $CFG; + + global $editorfields; + $editorfields = 'summary'; + + parent::setup($form); + + include("$CFG->dirroot/mod/resource/type/reference/reference.html"); + + parent::setup_end(); +} + + +} + +?> diff --git a/mod/resource/type/text/resource.class.php b/mod/resource/type/text/resource.class.php new file mode 100644 index 0000000000..059f85d8c2 --- /dev/null +++ b/mod/resource/type/text/resource.class.php @@ -0,0 +1,58 @@ +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 ->"; } + + + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + 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)); + + print_simple_box(format_text($this->resource->alltext, $this->resource->options), "center", "", "$THEME->cellcontent", "20"); + + echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + + print_footer($this->course); +} + + + +function setup($form) { + global $CFG; + + global $editorfields; + $editorfields = 'summary'; + + parent::setup($form); + + $format_array = format_text_menu(); + unset($format_array[FORMAT_HTML]); + include("$CFG->dirroot/mod/resource/type/text/text.html"); + + parent::setup_end(); +} + + +} + +?> diff --git a/mod/resource/type/text/text.html b/mod/resource/type/text/text.html new file mode 100644 index 0000000000..ae2334de12 --- /dev/null +++ b/mod/resource/type/text/text.html @@ -0,0 +1,24 @@ + + +

:


+ +
+
+
+ + + alltext); ?> + + + + +

:


+ + + options, '') ?> + +
+
+ + + diff --git a/mod/resource/version.php b/mod/resource/version.php index f9049c7880..b9c945d7b7 100644 --- a/mod/resource/version.php +++ b/mod/resource/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2004060400; +$module->version = 2004071303; $module->requires = 2004052501; // Requires this Moodle version $module->cron = 0; diff --git a/mod/resource/view.php b/mod/resource/view.php index 12dcd6b530..4938781644 100644 --- a/mod/resource/view.php +++ b/mod/resource/view.php @@ -4,8 +4,8 @@ require_once("lib.php"); require_variable($id); // Course Module ID - optional_variable($frameset, ""); - optional_variable($subdir, ""); +// optional_variable($frameset, ""); +// optional_variable($subdir, ""); if (!empty($CFG->forcelogin)) { require_login(); @@ -15,533 +15,14 @@ error("Course Module ID was incorrect"); } - if (! $course = get_record("course", "id", $cm->course)) { - error("Course is misconfigured"); - } - if (! $resource = get_record("resource", "id", $cm->instance)) { error("Resource ID was incorrect"); } - $strresource = get_string("modulename", "resource"); - $strresources = get_string("modulenameplural", "resource"); - $strlastmodified = get_string("lastmodified"); - - if ($course->category) { - require_login($course->id); - $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname -> - framename}\" href=\"index.php?id=$course->id\">$strresources ->"; - } else { - $navigation = "framename}\" href=\"index.php?id=$course->id\">$strresources ->"; - } - - $pagetitle = strip_tags("$course->shortname: $resource->name"); - - if (!$cm->visible and !isteacher($course->id)) { - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, - update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - notice(get_string("activityiscurrentlyhidden")); - } - - switch ($resource->type) { - case REFERENCE: - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, - update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - print_simple_box($resource->reference, "center"); - echo "

"; - echo text_to_html($resource->summary); - echo "

"; - echo "

 

"; - echo "

$strlastmodified: ".userdate($resource->timemodified)."

"; - echo "
"; - print_footer($course); - break; - - case WEBLINK: - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - - $inpopup = !empty($_GET["inpopup"]); - - if ($resource->alltext and !$inpopup) { /// Make a page and a pop-up window - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, - update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - echo "\n'; - - if (trim($resource->summary)) { - print_simple_box(text_to_html($resource->summary), "center"); - } - - $link = "wwwroot/mod/resource/view.php?inpopup=true&id=$cm->id\" target=\"resource$resource->id\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id', 'resource$resource->id','$resource->alltext');\">$resource->name"; - - echo "

 

"; - echo '

'; - print_string('popupresource', 'resource'); - echo '
'; - print_string('popupresourcelink', 'resource', $link); - echo "

"; - - print_footer($course); - die; - } - - if ($CFG->resource_filterexternalpages) { - $url = "fetch.php?id=$cm->id&url=$resource->reference"; - } else { - $url = "$resource->reference"; - } - redirect($url, "", 0); - break; - - case WEBPAGE: - if ($frameset == "top") { - print_header($pagetitle, "$course->fullname", - "$navigation framename}\" href=\"$resource->reference\" - title=\"$resource->reference\">$resource->name", "", "", true, - update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm, "parent")); - echo "
".text_to_html($resource->summary, true, false)."
"; - - } else { - if ($CFG->resource_filterexternalpages) { - $url = "fetch.php?id=$cm->id&url=$resource->reference"; - } else { - $url = "$resource->reference"; - } - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - echo "$course->shortname: $resource->name\n"; - echo "resource_framesize,*\" border=\"2\">"; - echo "id&frameset=top\">"; - echo ""; - echo ""; - } - break; - - case UPLOADEDFILE: - /// 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("../../files/mimetypes.php"); - - $resourcetype = ""; - $embedded = false; - $mimetype = mimeinfo("type", $resource->reference); - - 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"; - } - - - /// Set up some variables - - $inpopup = !empty($_GET["inpopup"]); - - if ($CFG->slasharguments) { - $relativeurl = "/file.php/$course->id/$resource->reference"; - } else { - $relativeurl = "/file.php?file=/$course->id/$resource->reference"; - } - $fullurl = "$CFG->wwwroot$relativeurl"; - - - /// Check whether this is supposed to be a popup, but was called directly - - if ($resource->alltext and !$inpopup) { /// Make a page and a pop-up window - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", "", "", true, - update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - echo "\n'; - - if (trim($resource->summary)) { - print_simple_box(text_to_html($resource->summary), "center"); - } - - $link = "wwwroot/mod/resource/view.php?inpopup=true&id=$cm->id\" target=\"resource$resource->id\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id=$cm->id', 'resource$resource->id','$resource->alltext');\">$resource->name"; - - echo "

 

"; - echo '

'; - print_string('popupresource', 'resource'); - echo '
'; - print_string('popupresourcelink', 'resource', $link); - echo "

"; - - print_footer($course); - exit; - } - - - /// Now check whether we need to display a frameset - - if (empty($frameset) and !$embedded and !$inpopup) { - echo "$course->shortname: $resource->name\n"; - echo "resource_framesize,*\" border=\"2\">"; - echo "id&frameset=top\">"; - echo ""; - echo ""; - exit; - } - - - /// We can only get here once per resource, so add an entry to the log - - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - - - /// If we are in a frameset, just print the top of it - - if ($frameset == "top") { - print_header($pagetitle, "$course->fullname", - "$navigation framename\" href=\"$fullurl\">$resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), - navmenu($course, $cm, "parent")); - echo "
".text_to_html($resource->summary, true, false)."
"; - echo ""; - exit; - } - - - /// Display the actual resource - - if ($embedded) { // Display resource embedded in page - $strdirectlink = get_string("directlink", "resource"); + require ("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php"); - if ($inpopup) { - print_header($pagetitle); - } else { - print_header($pagetitle, "$course->fullname", - "$navigation framename\" ". - "href=\"$fullurl\">$resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), - navmenu($course, $cm, "self")); - } + $resourceinstance = new resource($id); - if ($resourcetype == "image") { - echo "

"; - echo "name\" class=\"resourceimage\" src=\"$fullurl\">"; - echo "

"; - - } else if ($resourcetype == "mp3") { - echo "

"; - echo ''; - echo "wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\">"; - echo ''; - echo ''; - echo "wwwroot/lib/mp3player/mp3player.swf?src=$fullurl&autostart=yes\" "; - echo " quality=high bgcolor=\"#333333\" width=\"600\" height=\"70\" name=\"mp3player\" "; - echo ' type="application/x-shockwave-flash" '; - echo ' pluginspage="http://www.macromedia.com/go/getflashplayer">'; - echo ''; - echo ''; - echo "

"; - - } else if ($resourcetype == "mediaplayer") { - echo "

"; - echo ''; - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo "\n'; - echo ''; - echo ''; - echo "

"; - - } else if ($resourcetype == "quicktime") { - - echo "

"; - echo ''; - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo "\n'; - echo ''; - echo ''; - echo "

"; - } - - if (trim($resource->summary)) { - print_simple_box(format_text($resource->summary), 'center'); - } - - if ($inpopup) { - echo "

($strdirectlink)

"; - } else { - print_spacer(20,20); - print_footer($course); - } - - } else { // Display the resource on it's own - redirect($fullurl); - } - break; - - - case PLAINTEXT: - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - print_simple_box(format_text($resource->alltext), "center", "", "$THEME->cellcontent", "20"); - - echo "

$strlastmodified: ".userdate($resource->timemodified)."

"; - - print_footer($course); - break; - - case HTML: - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - print_simple_box_start("center", "", "$THEME->cellcontent", "20"); - - echo format_text($resource->alltext, FORMAT_HTML); - - print_simple_box_end(); - - echo "

$strlastmodified: ".userdate($resource->timemodified)."

"; - - print_footer($course); - break; - - case PROGRAM: // Code provided by Mark Kimes - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - - $temptime = gmdate("YmdHis",time()); - - $temproot = $CFG->wwwroot . "/mod/resource/"; - - // I tried to get around this. I really did. But here we - // are, redefining the navigation resources specifically anyway. - // On the plus side, you can change the format of the navigation - // strings above without worrying what it'll do to this code. On - // the negative side, you'll have to update this code if you - // change the structure of the navigation completely. Bonus - // is that now we can have a chain of cooperative sites, each - // adding to the navigation string as it moves down the line, - // which could be quite cool. -- Mark - - if ($course->category) { - $tempref = "<$course->shortname><" . $temproot . "../../course/view.php?id=$course->id>" . - "<$strresources><" . $temproot . "index.php?id=$course->id>"; - } else { - $tempref = "<$strresources>id>"; - } - - $tempurl = trim($resource->reference); - - if ($tempquerystring = strstr($tempurl,'?')) { - $tempquerystring = substr($tempquerystring,1); - $tempurl = substr($tempurl,0,strlen($tempurl) - strlen($tempquerystring)); - } - if (!empty($tempquerystring)) { - $tempquerystring = preg_replace("/(.*=)([^&]*)/e", - "'\\1' . urlencode('\\2')", - $tempquerystring); - } - $temp = $tempurl . $tempquerystring . - ((strstr($tempurl,'?')) ? "&" : "?") . - "extern_nav=" . urlencode($tempref) . - "&extern_usr=" . - urlencode($USER->username) . - "&extern_nam=" . urlencode("$USER->firstname $USER->lastname") . - "&extern_tim=" . urlencode($temptime) . - "&extern_pwd=" . - urlencode(md5($temptime . $USER->password)); - redirect($temp); - break; - - case WIKITEXT: - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - - print_simple_box(format_text($resource->alltext, FORMAT_WIKI), "center", "", "$THEME->cellcontent", "20" ); - - echo "

$strlastmodified: ".userdate($resource->timemodified)."

"; - - print_footer($course); - break; - - case DIRECTORY: - require_once("../../files/mimetypes.php"); - - add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id); - - if ($resource->reference) { - $relativepath = "$course->id/$resource->reference"; - } else { - $relativepath = "$course->id"; - } - - if ($subdir) { - if (detect_munged_arguments($subdir)) { - error("The value for 'subdir' contains illegal characters!"); - } - $relativepath = "$relativepath$subdir"; - - $subs = explode('/', $subdir); - array_shift($subs); - $countsubs = count($subs); - $count = 0; - $subnav = "id\">$resource->name"; - $backsub = ''; - foreach ($subs as $sub) { - $count++; - if ($count < $countsubs) { - $backsub .= "/$sub"; - $subnav .= " -> id&subdir=$backsub\">$sub"; - } else { - $subnav .= " -> $sub"; - } - } - } else { - $subnav = $resource->name; - } - - print_header($pagetitle, "$course->fullname", "$navigation $subnav", - "", "", true, update_module_button($cm->id, $course->id, $strresource), - navmenu($course, $cm)); - - if (isteacheredit($course->id)) { - echo ""; - } - - - if (trim($resource->summary)) { - print_simple_box(text_to_html($resource->summary), "center"); - print_spacer(10,10); - } - - $files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true); - - - if (!$files) { - print_heading(get_string("nofilesyet")); - print_footer($course); - exit; - } - - print_simple_box_start("center", "", "$THEME->cellcontent", '0' ); - - $strftime = get_string('strftimedatetime'); - $strname = get_string("name"); - $strsize = get_string("size"); - $strmodified = get_string("modified"); - - echo ''; - echo "". - "". - "". - ""; - foreach ($files as $file) { - if (is_dir("$CFG->dataroot/$relativepath/$file")) { // Must be a directory - $icon = "folder.gif"; - $relativeurl = "/view.php?blah"; - $filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file")); - - } else { - $icon = mimeinfo("icon", $file); - - if ($CFG->slasharguments) { - $relativeurl = "/file.php/$relativepath/$file"; - } else { - $relativeurl = "/file.php?file=/$relativepath/$file"; - } - $filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file")); - } - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
$strname$strsize$strmodified
'; - echo "pixpath/f/$icon\" width=\"16\" height=\"16\">"; - echo '

'; - if ($icon == 'folder.gif') { - echo "id&subdir=$subdir/$file\">$file"; - } else { - link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, ''); - } - echo '

 

'; - echo $filesize; - echo '

'; - echo userdate(filectime("$CFG->dataroot/$relativepath/$file"), $strftime); - echo '

'; - - print_simple_box_end(); - - print_footer($course); - break; - - default: - print_header($pagetitle, "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); - print_heading($resource->name); - - print_simple_box("Error: unknown type of resource", "center"); - - print_footer($course); - break; - } + $resourceinstance->display(); ?>