Initial revision
[moodle.git] / course / view.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Display the course home page.
4
5 require("../config.php");
6 require("lib.php");
7
8
9 require_login($id);
10
11 if (! $course = get_record("course", "id", $id) ) {
12 error("That's an invalid course id");
13 }
14
15 if (! $course->category) { // This course is not a real course.
16 redirect("$CFG->wwwroot");
17 }
18
19 add_to_log("View course: $course->shortname", $id);
20
21 if ( $USER->teacher[$course->id] ) {
22 if ($edit == "on") {
23 $USER->editing = true;
24 } else if ($edit == "off") {
25 $USER->editing = false;
26 }
27 }
28 if ($help == "on") {
29 $USER->help = true;
30 } else if ($help == "off") {
31 $USER->help = false;
32 }
33
34 print_header("Course: $course->fullname", "$course->fullname", "$course->shortname", "");
35
36 if (! $modtypes = get_records_sql_menu("SELECT name,fullname FROM modules ORDER BY fullname") ) {
37 error("No modules are installed!");
38 }
39
40 if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
41 FROM modules m, course_modules cm
42 WHERE cm.course = '$course->id'
43 AND cm.deleted = '0'
44 AND cm.module = m.id") ) {
45
46 foreach($rawmods as $mod) { // Index the mods
47 $mods[$mod->id] = $mod;
48 $modtype[$mod->modname] = $mod->modfullname;
49 }
50 }
51
52 switch ($course->format) {
53 case 0:
54 include("noweeks.php");
55 break;
56 case 1:
57 include("weeks.php");
58 break;
59 }
60
61 print_footer($course);
62
63
64/// FUNCTIONS ////////
65
66
67function make_editing_buttons($moduleid) {
68 return "&nbsp; &nbsp;
69 <A HREF=mod.php?delete=$moduleid><IMG
70 SRC=../pix/t/delete.gif BORDER=0 ALT=Delete></A>
71 <A HREF=mod.php?id=$moduleid&move=-1><IMG
72 SRC=../pix/t/up.gif BORDER=0 ALT=\"Move up\"></A>
73 <A HREF=mod.php?id=$moduleid&move=1><IMG
74 SRC=../pix/t/down.gif BORDER=0 ALT=\"Move down\"></A>
75 <A HREF=mod.php?update=$moduleid><IMG
76 SRC=../pix/t/edit.gif BORDER=0 ALT=Update></A>";
77}
78
79function print_side_block($heading="", $list=NULL, $footer="", $icons=NULL) {
80
81 echo "<TABLE WIDTH=100%>\n";
82 echo "<TR><TD COLSPAN=2><P><B><FONT SIZE=2>$heading</TD></TR>\n";
83 if ($list) {
84 foreach($list as $key => $string) {
85 echo "<TR><TD VALIGN=top WIDTH=12>";
86 if ($icons[$key]) {
87 echo $icons[$key];
88 } else {
89 echo "";
90 }
91 echo "</TD>\n<TD WIDTH=100%>";
92 echo "<P><FONT SIZE=1>$string</FONT></P>";
93 echo "</TD></TR>\n";
94 }
95 }
96 if ($footer) {
97 echo "<TR><TD></TD><TD ALIGN=left><P><FONT SIZE=2>$footer</TD></TR>\n";
98 }
99 echo "</TABLE><BR>\n\n";
100}
101
102?>