f9903ed0 |
1 | <?PHP // $Id$ |
2 | |
3 | // Display the course home page. |
4 | |
b0e3a925 |
5 | require_once("../config.php"); |
6 | require_once("lib.php"); |
0d250ac1 |
7 | require_once('../calendar/lib.php'); |
f9903ed0 |
8 | |
388f8911 |
9 | optional_variable($id); |
10 | optional_variable($name); |
f9903ed0 |
11 | |
388f8911 |
12 | if (!$id and !$name) { |
13 | error("Must specify course id or short name"); |
14 | } |
f9903ed0 |
15 | |
c7609872 |
16 | if (!empty($_GET['name'])) { |
388f8911 |
17 | if (! $course = get_record("course", "shortname", $name) ) { |
18 | error("That's an invalid short course name"); |
19 | } |
20 | } else { |
21 | if (! $course = get_record("course", "id", $id) ) { |
22 | error("That's an invalid course id"); |
23 | } |
f9903ed0 |
24 | } |
25 | |
783da262 |
26 | require_login($course->id); |
388f8911 |
27 | |
600149be |
28 | add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); |
f9903ed0 |
29 | |
73047f2f |
30 | if (isteacheredit($course->id)) { |
73fafc38 |
31 | if (isset($edit)) { |
9c9f7d77 |
32 | if ($edit == "on") { |
33 | $USER->editing = true; |
34 | } else if ($edit == "off") { |
35 | $USER->editing = false; |
36 | } |
f9903ed0 |
37 | } |
8223d271 |
38 | |
73fafc38 |
39 | if (isset($hide)) { |
40 | set_section_visible($course->id, $hide, "0"); |
41 | } |
7d99d695 |
42 | |
73fafc38 |
43 | if (isset($show)) { |
44 | set_section_visible($course->id, $show, "1"); |
45 | } |
12905134 |
46 | |
47 | if (!empty($section)) { |
48 | if (!empty($move)) { |
56e34ee4 |
49 | if (!move_section($course, $section, $move)) { |
50 | notify("An error occurred while moving a section"); |
51 | } |
12905134 |
52 | } |
53 | } |
48d72fa7 |
54 | } else { |
55 | $USER->editing = false; |
7d99d695 |
56 | } |
57 | |
4c701e6f |
58 | $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id"; |
4c701e6f |
59 | |
b8391635 |
60 | if (! $course->category) { // This course is not a real course. |
61 | redirect("$CFG->wwwroot/"); |
62 | } |
63 | |
196ca3fe |
64 | $currentgroup = get_current_group($course->id); |
65 | |
43acb21f |
66 | $strcourse = get_string("course"); |
fa0626c6 |
67 | |
b328523c |
68 | $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>"; |
a282d0ff |
69 | |
8b68eb7e |
70 | print_header("$strcourse: $course->fullname", "$course->fullname", "$course->shortname", |
43acb21f |
71 | "", "", true, update_course_icon($course->id), $loggedinas); |
f9903ed0 |
72 | |
9c9f7d77 |
73 | get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); |
19801b2b |
74 | |
dfec7b01 |
75 | if (! $sections = get_all_sections($course->id)) { // No sections found |
76 | // Double-check to be extra sure |
77 | if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) { |
78 | $section->course = $course->id; // Create a default section. |
79 | $section->section = 0; |
80 | $section->visible = 1; |
81 | $section->id = insert_record("course_sections", $section); |
82 | } |
83 | if (! $sections = get_all_sections($course->id) ) { // Try again |
19801b2b |
84 | error("Error finding or creating section structures for this course"); |
85 | } |
86 | } |
7468bf01 |
87 | |
51955364 |
88 | if (empty($course->modinfo)) { // Course cache was never made |
89 | rebuild_course_cache($course->id); |
db34bb59 |
90 | if (! $course = get_record("course", "id", $course->id) ) { |
91 | error("That's an invalid course id"); |
92 | } |
51955364 |
93 | } |
94 | |
6049fb78 |
95 | if (!file_exists("$CFG->dirroot/course/format/$course->format/format.php")) { // Default format is weeks |
7142bc1b |
96 | $course->format = "weeks"; |
97 | } |
98 | |
6049fb78 |
99 | require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format |
f9903ed0 |
100 | |
2c26c985 |
101 | print_footer(); |
f9903ed0 |
102 | |
f9903ed0 |
103 | ?> |