a85ab7be79dda7ecf2a9fb0b511ce54ee5022890
[moodle.git] / mod / resource / view.php
1 <?PHP  // $Id$
3     require("../../config.php");
4     require("lib.php");
6     require_variable($id);    // Course Module ID
8     if (! $cm = get_record("course_modules", "id", $id)) {
9         error("Course Module ID was incorrect");
10     }
12     if (! $course = get_record("course", "id", $cm->course)) {
13         error("Course is misconfigured");
14     }
16     if (! $resource = get_record("resource", "id", $cm->instance)) {
17         error("Resource ID was incorrect");
18     }
20     $strresource = get_string("modulename", "resource");
21     $strresources = get_string("modulenameplural", "resource");
22     $strlastmodified = get_string("lastmodified");
24     if ($course->category) {
25         require_login($course->id);
26         $navigation = "<A TARGET=_top HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
27                        <A TARGET=_top HREF=\"index.php?id=$course->id\">$strresources</A> ->";
28     } else {
29         $navigation = "<A TARGET=_top HREF=\"index.php?id=$course->id\">$strresources</A> ->";
30     }
32     switch ($resource->type) {
33         case 1:  // Reference (eg Journal or Book etc)
34             add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
35             print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
36                          "", "", true, update_module_button($cm->id, $course->id, $strresource));
38             print_simple_box($resource->reference, "center");
39             echo "<CENTER><P>";
40             echo text_to_html($resource->summary);
41             echo "</P>";
42             echo "<P>&nbsp</P>";
43             echo "<P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P>";
44             echo "</CENTER>";
45             print_footer($course);
46             break;
48         case 5: // Web Link
49             add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
50             redirect($resource->reference);
51             break;
53         case 2: // Web Page
54             if ($frameset) {
55                 print_header("$course->shortname: $resource->name", "$course->fullname", 
56                 "$navigation <A TARGET=_top HREF=\"$resource->reference\" TITLE=\"$resource->reference\">$resource->name</A>",
57                 "", "", true, update_module_button($cm->id, $course->id, $strresource));
58                 echo "<CENTER><FONT SIZE=-1>".text_to_html($resource->summary, true, false)."</FONT></CENTER>";
60             } else {
61                 add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
62                 echo "<HEAD><TITLE>$course->shortname: $resource->name</TITLE></HEAD>\n";
63                 echo "<FRAMESET ROWS=130,*>";
64                 echo "<FRAME SRC=\"view.php?id=$cm->id&frameset=true\">";
65                 echo "<FRAME SRC=\"$resource->reference\">";
66                 echo "</FRAMESET>";
67             }
68             break;
70         case 3:  // Uploaded File
71             if ($frameset) {
72                 print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
73                          "", "", true, update_module_button($cm->id, $course->id, $strresource));
74                 echo "<CENTER><FONT SIZE=-1>".text_to_html($resource->summary, true, false)."</FONT></CENTER>";
76             } else {
77                 add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
78                 if ($CFG->slasharguments) {
79                     $ffurl = "file.php/$course->id/$resource->reference";
80                 } else {
81                     $ffurl = "file.php?file=/$course->id/$resource->reference";
82                 }
83                 echo "<HEAD><TITLE>$course->shortname: $resource->name</TITLE></HEAD>\n";
84                 echo "<FRAMESET ROWS=130,*>";
85                 echo "<FRAME SRC=\"view.php?id=$cm->id&frameset=true\">";
86                 echo "<FRAME SRC=\"$CFG->wwwroot/$ffurl\">";
87                 echo "</FRAMESET>";
88             }
89             break;
91         case 4:  // Plain text
92             add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
93             print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
94                          "", "", true, update_module_button($cm->id, $course->id, $strresource));
96             print_simple_box(text_to_html($resource->alltext), "CENTER", "", "$THEME->cellcontent", "20");
98             echo "<CENTER><P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P></CENTER>";
100             print_footer($course);
101             break;
103         case 6:  // HTML text
104             add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
105             print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
106                          "", "", true, update_module_button($cm->id, $course->id, $strresource));
108             print_simple_box_start("CENTER", "", "$THEME->cellcontent", "20");
110             echo $resource->alltext;
112             print_simple_box_end();
114             echo "<CENTER><P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P></CENTER>";
116             print_footer($course);
117             break;
119         default:
120             print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
121                          "", "", true, update_module_button($cm->id, $course->id, $strresource));
122             print_heading($resource->name);
124             print_simple_box("Error: unknown type of resource", "center");
126             print_footer($course);
127             break;
128     }
131 ?>