42
preload_course_contexts($course->id);
42
43
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
43
44
print_error('nocontext');
46
if ($switchrole == 0) { // Remove any switched roles before checking login
47
// Remove any switched roles before checking login
48
if ($switchrole == 0 && confirm_sesskey()) {
47
49
role_switch($switchrole, $context);
50
require_login($course->id);
52
require_login($course);
52
if ($switchrole > 0) {
53
role_switch($switchrole, $context);
54
require_login($course->id); // Double check that this role is allowed here
54
// Switchrole - sanity check in cost-order...
55
$reset_user_allowed_editing = false;
56
if ($switchrole > 0 && confirm_sesskey() &&
57
has_capability('moodle/role:switchroles', $context)) {
58
// is this role assignable in this context?
59
// inquiring minds want to know...
60
$aroles = get_assignable_roles($context);
61
if (is_array($aroles) && isset($aroles[$switchrole])) {
62
role_switch($switchrole, $context);
63
// Double check that this role is allowed here
64
require_login($course->id);
66
// reset course page state - this prevents some weird problems ;-)
67
$USER->activitycopy = false;
68
$USER->activitycopycourse = NULL;
69
unset($USER->activitycopyname);
70
unset($SESSION->modform);
72
$reset_user_allowed_editing = true;
57
75
//If course is hosted on an external server, redirect to corresponding
78
96
$PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
79
97
$pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
99
if ($reset_user_allowed_editing) {
101
unset($PAGE->_user_allowed_editing);
82
104
if (!isset($USER->editing)) {
83
105
$USER->editing = 0;
124
146
// AJAX-capable course format?
125
$CFG->useajax = false;
126
148
$ajaxformatfile = $CFG->dirroot.'/course/format/'.$course->format.'/ajax.php';
129
if (file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default
151
if (empty($CFG->disablecourseajax) and file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default
153
// TODO: stop abusing CFG global here
131
154
$CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile
132
155
$CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile
134
157
require_once($ajaxformatfile);
136
if (!empty($USER->editing) && $CFG->ajaxcapable) { // Course-based switches
159
if (!empty($USER->editing) && $CFG->ajaxcapable && has_capability('moodle/course:manageactivities', $context)) {
160
// Course-based switches
138
if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // rowser, user and site-based switches
162
if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // Browser, user and site-based switches
140
164
require_js(array('yui_yahoo',
163
187
// function is called, since that function needs to set some
164
188
// stuff in the javascriptportal object.
165
189
$COURSE->javascriptportal = new jsportal();
166
$CFG->useajax = true;
171
$CFG->blocksdrag = $CFG->useajax; // this will add a new class to the header so we can style differently
195
$CFG->blocksdrag = $useajax; // this will add a new class to the header so we can style differently
174
198
$PAGE->print_header(get_string('course').': %fullname%', NULL, '', $bodytags);
175
199
// Course wrapper start.
176
200
echo '<div class="course-content">';
202
$modinfo =& get_fast_modinfo($COURSE);
179
203
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
204
foreach($mods as $modid=>$unused) {
205
if (!isset($modinfo->cms[$modid])) {
206
rebuild_course_cache($course->id);
207
$modinfo =& get_fast_modinfo($COURSE);
208
debugging('Rebuilding course cache', DEBUG_DEVELOPER);
181
213
if (! $sections = get_all_sections($course->id)) { // No sections found
182
214
// Double-check to be extra sure
195
if (empty($course->modinfo)) {
196
// Course cache was never made.
197
rebuild_course_cache($course->id);
198
if (! $course = get_record('course', 'id', $course->id) ) {
199
error("That's an invalid course id");
204
226
// Include the actual course format.
205
227
require($CFG->dirroot .'/course/format/'. $course->format .'/format.php');
206
228
// Content wrapper end.
233
if ($useajax && has_capability('moodle/course:manageactivities', $context)) {
212
234
// At the bottom because we want to process sections and activities
213
235
// after the relevant html has been generated. We're forced to do this
214
236
// because of the way in which lib/ajax/ajaxcourse.js is written.