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'); |
f45cc76f |
8 | require_once($CFG->libdir.'/ajax/ajaxlib.php'); |
afc58a28 |
9 | require_once($CFG->dirroot.'/mod/forum/lib.php'); |
f9903ed0 |
10 | |
2335781f |
11 | $id = optional_param('id', 0, PARAM_INT); |
0cdae0dc |
12 | $name = optional_param('name', '', PARAM_RAW); |
13 | $edit = optional_param('edit', -1, PARAM_BOOL); |
14 | $hide = optional_param('hide', 0, PARAM_INT); |
15 | $show = optional_param('show', 0, PARAM_INT); |
16 | $idnumber = optional_param('idnumber', '', PARAM_RAW); |
0cdae0dc |
17 | $section = optional_param('section', 0, PARAM_INT); |
18 | $move = optional_param('move', 0, PARAM_INT); |
f4f0bc84 |
19 | $marker = optional_param('marker',-1 , PARAM_INT); |
3a52e764 |
20 | $switchrole = optional_param('switchrole',-1, PARAM_INT); |
21 | |
7ea8ea7f |
22 | |
f9903ed0 |
23 | |
533229c4 |
24 | if (empty($id) && empty($name) && empty($idnumber)) { |
25 | error("Must specify course id, short name or idnumber"); |
388f8911 |
26 | } |
f9903ed0 |
27 | |
2335781f |
28 | if (!empty($name)) { |
29 | if (! ($course = get_record('course', 'shortname', $name)) ) { |
30 | error('Invalid short course name'); |
388f8911 |
31 | } |
816acb46 |
32 | } else if (!empty($idnumber)) { |
33 | if (! ($course = get_record('course', 'idnumber', $idnumber)) ) { |
34 | error('Invalid course idnumber'); |
35 | } |
388f8911 |
36 | } else { |
2335781f |
37 | if (! ($course = get_record('course', 'id', $id)) ) { |
38 | error('Invalid course id'); |
388f8911 |
39 | } |
f9903ed0 |
40 | } |
41 | |
3a52e764 |
42 | if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) { |
43 | print_error('nocontext'); |
44 | } |
45 | |
ac4c51be |
46 | if ($switchrole == 0) { // Remove any switched roles before checking login |
47 | role_switch($switchrole, $context); |
48 | } |
49 | |
783da262 |
50 | require_login($course->id); |
388f8911 |
51 | |
ac4c51be |
52 | if ($switchrole > 0) { |
3a52e764 |
53 | role_switch($switchrole, $context); |
ac4c51be |
54 | require_login($course->id); // Double check that this role is allowed here |
3a52e764 |
55 | } |
56 | |
542a0435 |
57 | //If course is hosted on an external server, redirect to corresponding |
58 | //url with appropriate authentication attached as parameter |
892c0825 |
59 | if (file_exists($CFG->dirroot .'/course/externservercourse.php')) { |
60 | include $CFG->dirroot .'/course/externservercourse.php'; |
4d2401d5 |
61 | if (function_exists('extern_server_course')) { |
542a0435 |
62 | if ($extern_url = extern_server_course($course)) { |
63 | redirect($extern_url); |
64 | } |
65 | } |
66 | } |
67 | |
3a52e764 |
68 | |
08cebf19 |
69 | require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER |
af62781b |
70 | |
892c0825 |
71 | add_to_log($course->id, 'course', 'view', "view.php?id=$course->id", "$course->id"); |
f9903ed0 |
72 | |
e069b3e2 |
73 | $course->format = clean_param($course->format, PARAM_ALPHA); |
0f3fe4b6 |
74 | if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) { |
75 | $course->format = 'weeks'; // Default format is weeks |
76 | } |
77 | |
7542a4e5 |
78 | $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); |
f45cc76f |
79 | $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH); |
80 | |
daa27ce4 |
81 | |
0f3fe4b6 |
82 | if (!isset($USER->editing)) { |
d2b23346 |
83 | $USER->editing = 0; |
0f3fe4b6 |
84 | } |
a3f24f7c |
85 | if ($PAGE->user_allowed_editing()) { |
0cdae0dc |
86 | if (($edit == 1) and confirm_sesskey()) { |
d2b23346 |
87 | $USER->editing = 1; |
0cdae0dc |
88 | } else if (($edit == 0) and confirm_sesskey()) { |
d2b23346 |
89 | $USER->editing = 0; |
a3f24f7c |
90 | if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) { |
91 | $USER->activitycopy = false; |
92 | $USER->activitycopycourse = NULL; |
9c9f7d77 |
93 | } |
f9903ed0 |
94 | } |
8223d271 |
95 | |
0cdae0dc |
96 | if ($hide && confirm_sesskey()) { |
82b181f2 |
97 | set_section_visible($course->id, $hide, '0'); |
73fafc38 |
98 | } |
7d99d695 |
99 | |
0cdae0dc |
100 | if ($show && confirm_sesskey()) { |
82b181f2 |
101 | set_section_visible($course->id, $show, '1'); |
73fafc38 |
102 | } |
12905134 |
103 | |
104 | if (!empty($section)) { |
5b224948 |
105 | if (!empty($move) and confirm_sesskey()) { |
56e34ee4 |
106 | if (!move_section($course, $section, $move)) { |
892c0825 |
107 | notify('An error occurred while moving a section'); |
56e34ee4 |
108 | } |
12905134 |
109 | } |
110 | } |
48d72fa7 |
111 | } else { |
d2b23346 |
112 | $USER->editing = 0; |
7d99d695 |
113 | } |
114 | |
892c0825 |
115 | $SESSION->fromdiscussion = $CFG->wwwroot .'/course/view.php?id='. $course->id; |
4c701e6f |
116 | |
f45cc76f |
117 | |
118 | if ($course->id == SITEID) { |
119 | // This course is not a real course. |
892c0825 |
120 | redirect($CFG->wwwroot .'/'); |
83f3c62d |
121 | } |
122 | |
f9903ed0 |
123 | |
f45cc76f |
124 | // AJAX-capable course format? |
61c1b4b5 |
125 | $CFG->useajax = false; |
f45cc76f |
126 | $ajaxformatfile = $CFG->dirroot.'/course/format/'.$course->format.'/ajax.php'; |
4e86c6d7 |
127 | $bodytags = ''; |
f45cc76f |
128 | |
61c1b4b5 |
129 | if (file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default |
130 | |
131 | $CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile |
132 | $CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile |
133 | |
f45cc76f |
134 | require_once($ajaxformatfile); |
4e86c6d7 |
135 | |
61c1b4b5 |
136 | if (!empty($USER->editing) && $CFG->ajaxcapable && has_capability('moodle/course:manageactivities', $context)) { |
137 | // Course-based switches |
7b9c9979 |
138 | |
61c1b4b5 |
139 | if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // Browser, user and site-based switches |
f47e1c17 |
140 | |
141 | require_js(array('yui_yahoo', |
142 | 'yui_dom', |
143 | 'yui_event', |
144 | 'yui_dragdrop', |
145 | 'yui_connection', |
146 | 'ajaxcourse_blocks', |
147 | 'ajaxcourse_sections')); |
148 | |
4e86c6d7 |
149 | if (debugging('', DEBUG_DEVELOPER)) { |
f47e1c17 |
150 | require_js(array('yui_logger')); |
4e86c6d7 |
151 | |
a202dfa0 |
152 | $bodytags = 'onload = "javascript: |
4e86c6d7 |
153 | show_logger = function() { |
154 | var logreader = new YAHOO.widget.LogReader(); |
155 | logreader.newestOnTop = false; |
156 | logreader.setTitle(\'Moodle Debug: YUI Log Console\'); |
157 | }; |
158 | show_logger(); |
159 | "'; |
160 | } |
f47e1c17 |
161 | |
4e86c6d7 |
162 | // Okay, global variable alert. VERY UGLY. We need to create |
163 | // this object here before the <blockname>_print_block() |
164 | // function is called, since that function needs to set some |
165 | // stuff in the javascriptportal object. |
166 | $COURSE->javascriptportal = new jsportal(); |
75c3849a |
167 | $CFG->useajax = true; |
4e86c6d7 |
168 | } |
f45cc76f |
169 | } |
f45cc76f |
170 | } |
171 | |
75c3849a |
172 | $CFG->blocksdrag = $CFG->useajax; // this will add a new class to the header so we can style differently |
173 | |
f45cc76f |
174 | |
f47e1c17 |
175 | $PAGE->print_header(get_string('course').': %fullname%', NULL, '', $bodytags); |
f45cc76f |
176 | // Course wrapper start. |
177 | echo '<div class="course-content">'; |
178 | |
daa27ce4 |
179 | |
9c9f7d77 |
180 | get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); |
19801b2b |
181 | |
dfec7b01 |
182 | if (! $sections = get_all_sections($course->id)) { // No sections found |
183 | // Double-check to be extra sure |
892c0825 |
184 | if (! $section = get_record('course_sections', 'course', $course->id, 'section', 0)) { |
dfec7b01 |
185 | $section->course = $course->id; // Create a default section. |
186 | $section->section = 0; |
187 | $section->visible = 1; |
892c0825 |
188 | $section->id = insert_record('course_sections', $section); |
dfec7b01 |
189 | } |
190 | if (! $sections = get_all_sections($course->id) ) { // Try again |
892c0825 |
191 | error('Error finding or creating section structures for this course'); |
19801b2b |
192 | } |
193 | } |
7468bf01 |
194 | |
f45cc76f |
195 | |
196 | if (empty($course->modinfo)) { |
197 | // Course cache was never made. |
51955364 |
198 | rebuild_course_cache($course->id); |
892c0825 |
199 | if (! $course = get_record('course', 'id', $course->id) ) { |
db34bb59 |
200 | error("That's an invalid course id"); |
201 | } |
51955364 |
202 | } |
203 | |
f9903ed0 |
204 | |
f45cc76f |
205 | // Include the actual course format. |
206 | require($CFG->dirroot .'/course/format/'. $course->format .'/format.php'); |
207 | // Content wrapper end. |
f47e1c17 |
208 | echo "</div>\n\n"; |
f45cc76f |
209 | |
210 | |
211 | // Use AJAX? |
217a8ee9 |
212 | if ($CFG->useajax && has_capability('moodle/course:manageactivities', $context)) { |
f45cc76f |
213 | // At the bottom because we want to process sections and activities |
f47e1c17 |
214 | // after the relevant html has been generated. We're forced to do this |
215 | // because of the way in which lib/ajax/ajaxcourse.js is written. |
216 | echo '<script type="text/javascript" '; |
217 | echo "src=\"{$CFG->wwwroot}/lib/ajax/ajaxcourse.js\"></script>\n"; |
218 | |
219 | $COURSE->javascriptportal->print_javascript($course->id); |
f45cc76f |
220 | } |
221 | |
222 | |
093a4a24 |
223 | print_footer(NULL, $course); |
f9903ed0 |
224 | |
61c1b4b5 |
225 | ?> |