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 "";
}
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";
if ($CFG->resource_filterexternalpages and $resourcetype == "html") {
$fullurl = "$CFG->wwwroot/mod/resource/fetch.php?id=$cm->id&url=$fullurl";
}
/// 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 "";
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 "