24f2b65a |
1 | <?php // $Id$ |
f9903ed0 |
2 | |
3 | // Display the course home page. |
4 | |
08cebf19 |
5 | require_once('../config.php'); |
6 | require_once('lib.php'); |
7 | require_once($CFG->libdir.'/blocklib.php'); |
f9903ed0 |
8 | |
388f8911 |
9 | optional_variable($id); |
10 | optional_variable($name); |
f9903ed0 |
11 | |
9b4b78fd |
12 | optional_param('blockaction'); |
13 | optional_param('instanceid', 0, PARAM_INT); |
14 | optional_param('blockid', 0, PARAM_INT); |
15 | |
388f8911 |
16 | if (!$id and !$name) { |
17 | error("Must specify course id or short name"); |
18 | } |
f9903ed0 |
19 | |
c7609872 |
20 | if (!empty($_GET['name'])) { |
0f3fe4b6 |
21 | if (! ($course = get_record("course", "shortname", $name)) ) { |
388f8911 |
22 | error("That's an invalid short course name"); |
23 | } |
24 | } else { |
0f3fe4b6 |
25 | if (! ($course = get_record("course", "id", $id)) ) { |
388f8911 |
26 | error("That's an invalid course id"); |
27 | } |
f9903ed0 |
28 | } |
29 | |
783da262 |
30 | require_login($course->id); |
388f8911 |
31 | |
08cebf19 |
32 | require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER |
af62781b |
33 | |
600149be |
34 | add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); |
f9903ed0 |
35 | |
e069b3e2 |
36 | $course->format = clean_param($course->format, PARAM_ALPHA); |
0f3fe4b6 |
37 | if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) { |
38 | $course->format = 'weeks'; // Default format is weeks |
39 | } |
40 | |
9b128500 |
41 | $PAGE = page_create_object(MOODLE_PAGE_COURSE, $course->id); |
f032aa7a |
42 | $pageblocks = blocks_get_by_page($PAGE); |
daa27ce4 |
43 | |
0f3fe4b6 |
44 | if (!isset($USER->editing)) { |
45 | $USER->editing = false; |
46 | } |
47 | |
48 | $editing = false; |
49 | |
73047f2f |
50 | if (isteacheredit($course->id)) { |
0f3fe4b6 |
51 | if (isset($edit)) { |
9c9f7d77 |
52 | if ($edit == "on") { |
53 | $USER->editing = true; |
54 | } else if ($edit == "off") { |
55 | $USER->editing = false; |
56 | } |
f9903ed0 |
57 | } |
8223d271 |
58 | |
0f3fe4b6 |
59 | $editing = $USER->editing; |
60 | |
9b4b78fd |
61 | if (isset($hide) && confirm_sesskey()) { |
82b181f2 |
62 | set_section_visible($course->id, $hide, '0'); |
73fafc38 |
63 | } |
7d99d695 |
64 | |
9b4b78fd |
65 | if (isset($show) && confirm_sesskey()) { |
82b181f2 |
66 | set_section_visible($course->id, $show, '1'); |
73fafc38 |
67 | } |
12905134 |
68 | |
9b4b78fd |
69 | if (!empty($blockaction) && confirm_sesskey()) { |
70 | if (!empty($blockid)) { |
f032aa7a |
71 | blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid)); |
daa27ce4 |
72 | |
0f3fe4b6 |
73 | } |
9b4b78fd |
74 | else if (!empty($instanceid)) { |
75 | $instance = blocks_find_instance($instanceid, $pageblocks); |
f032aa7a |
76 | blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance); |
0f3fe4b6 |
77 | } |
9b4b78fd |
78 | // This re-query could be eliminated by judicious programming in blocks_execute_action(), |
79 | // but I 'm not sure if it's worth the complexity increase... |
f032aa7a |
80 | $pageblocks = blocks_get_by_page($PAGE); |
0f3fe4b6 |
81 | } |
82 | |
f032aa7a |
83 | $missingblocks = blocks_get_missing($PAGE, $pageblocks); |
9b4b78fd |
84 | |
12905134 |
85 | if (!empty($section)) { |
5b224948 |
86 | if (!empty($move) and confirm_sesskey()) { |
56e34ee4 |
87 | if (!move_section($course, $section, $move)) { |
88 | notify("An error occurred while moving a section"); |
89 | } |
12905134 |
90 | } |
91 | } |
48d72fa7 |
92 | } else { |
93 | $USER->editing = false; |
7d99d695 |
94 | } |
95 | |
4c701e6f |
96 | $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id"; |
4c701e6f |
97 | |
83f3c62d |
98 | if ($course->id == SITEID) { // This course is not a real course. |
99 | redirect("$CFG->wwwroot/"); |
100 | } |
101 | |
f032aa7a |
102 | $PAGE->print_header(get_string('course').': %fullname%'); |
f9903ed0 |
103 | |
ee4dc51e |
104 | echo '<div class="course-content">'; // course wrapper start |
daa27ce4 |
105 | |
9c9f7d77 |
106 | get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); |
19801b2b |
107 | |
dfec7b01 |
108 | if (! $sections = get_all_sections($course->id)) { // No sections found |
109 | // Double-check to be extra sure |
110 | if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) { |
111 | $section->course = $course->id; // Create a default section. |
112 | $section->section = 0; |
113 | $section->visible = 1; |
114 | $section->id = insert_record("course_sections", $section); |
115 | } |
116 | if (! $sections = get_all_sections($course->id) ) { // Try again |
19801b2b |
117 | error("Error finding or creating section structures for this course"); |
118 | } |
119 | } |
7468bf01 |
120 | |
51955364 |
121 | if (empty($course->modinfo)) { // Course cache was never made |
122 | rebuild_course_cache($course->id); |
db34bb59 |
123 | if (! $course = get_record("course", "id", $course->id) ) { |
124 | error("That's an invalid course id"); |
125 | } |
51955364 |
126 | } |
127 | |
6049fb78 |
128 | require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format |
f9903ed0 |
129 | |
daa27ce4 |
130 | echo '</div>'; // content wrapper end |
093a4a24 |
131 | print_footer(NULL, $course); |
f9903ed0 |
132 | |
f9903ed0 |
133 | ?> |