MDL-32925 lang: Add extended help texts for all modules
[moodle.git] / course / view.php
CommitLineData
aa6c1ced 1<?php
f9903ed0 2
3// Display the course home page.
4
08cebf19 5 require_once('../config.php');
6 require_once('lib.php');
afc58a28 7 require_once($CFG->dirroot.'/mod/forum/lib.php');
ce4dfd27 8 require_once($CFG->libdir.'/conditionlib.php');
516c5eca 9 require_once($CFG->libdir.'/completionlib.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
599a52fe 22 $params = array();
2335781f 23 if (!empty($name)) {
599a52fe 24 $params = array('shortname' => $name);
816acb46 25 } else if (!empty($idnumber)) {
599a52fe
DP
26 $params = array('idnumber' => $idnumber);
27 } else if (!empty($id)) {
28 $params = array('id' => $id);
29 }else {
30 print_error('unspecifycourseid', 'error');
f9903ed0 31 }
32
599a52fe
DP
33 $course = $DB->get_record('course', $params, '*', MUST_EXIST);
34
45774bdd
DP
35 $urlparams = array('id' => $course->id);
36 if ($section) {
37 $urlparams['section'] = $section;
38 }
39
40 $PAGE->set_url('/course/view.php', $urlparams); // Defined here to avoid notices on errors etc
088e3363 41
fbb4c959
SH
42 // Prevent caching of this page to stop confusion when changing page after making AJAX changes
43 $PAGE->set_cacheable(false);
44
00653161 45 preload_course_contexts($course->id);
599a52fe 46 $context = context_course::instance($course->id, MUST_EXIST);
3a52e764 47
d7d4b0e5 48 // Remove any switched roles before checking login
49 if ($switchrole == 0 && confirm_sesskey()) {
ac4c51be 50 role_switch($switchrole, $context);
51 }
52
a6af674a 53 require_login($course);
388f8911 54
d7d4b0e5 55 // Switchrole - sanity check in cost-order...
46bd37bf 56 $reset_user_allowed_editing = false;
d7d4b0e5 57 if ($switchrole > 0 && confirm_sesskey() &&
58 has_capability('moodle/role:switchroles', $context)) {
59 // is this role assignable in this context?
60 // inquiring minds want to know...
82701e24 61 $aroles = get_switchable_roles($context);
d7d4b0e5 62 if (is_array($aroles) && isset($aroles[$switchrole])) {
63 role_switch($switchrole, $context);
64 // Double check that this role is allowed here
cdbea7ee 65 require_login($course);
d7d4b0e5 66 }
46bd37bf 67 // reset course page state - this prevents some weird problems ;-)
68 $USER->activitycopy = false;
69 $USER->activitycopycourse = NULL;
70 unset($USER->activitycopyname);
71 unset($SESSION->modform);
72 $USER->editing = 0;
73 $reset_user_allowed_editing = true;
3a52e764 74 }
75
542a0435 76 //If course is hosted on an external server, redirect to corresponding
aa6c1ced 77 //url with appropriate authentication attached as parameter
892c0825 78 if (file_exists($CFG->dirroot .'/course/externservercourse.php')) {
79 include $CFG->dirroot .'/course/externservercourse.php';
4d2401d5 80 if (function_exists('extern_server_course')) {
542a0435 81 if ($extern_url = extern_server_course($course)) {
82 redirect($extern_url);
83 }
84 }
85 }
86
3a52e764 87
08cebf19 88 require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER
af62781b 89
45774bdd 90 //TODO: danp do we need different urls?
892c0825 91 add_to_log($course->id, 'course', 'view', "view.php?id=$course->id", "$course->id");
f9903ed0 92
e069b3e2 93 $course->format = clean_param($course->format, PARAM_ALPHA);
0f3fe4b6 94 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
95 $course->format = 'weeks'; // Default format is weeks
96 }
97
78946b9b 98 $PAGE->set_pagelayout('course');
66b10689 99 $PAGE->set_pagetype('course-view-' . $course->format);
cfcfb9f3 100 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
b7b2d0f3 101
46bd37bf 102 if ($reset_user_allowed_editing) {
103 // ugly hack
104 unset($PAGE->_user_allowed_editing);
105 }
daa27ce4 106
0f3fe4b6 107 if (!isset($USER->editing)) {
d2b23346 108 $USER->editing = 0;
0f3fe4b6 109 }
a3f24f7c 110 if ($PAGE->user_allowed_editing()) {
0cdae0dc 111 if (($edit == 1) and confirm_sesskey()) {
d2b23346 112 $USER->editing = 1;
ad96cc52
AKA
113 // Redirect to site root if Editing is toggled on frontpage
114 if ($course->id == SITEID) {
115 redirect($CFG->wwwroot .'/?redirect=0');
116 } else {
117 redirect($PAGE->url);
118 }
0cdae0dc 119 } else if (($edit == 0) and confirm_sesskey()) {
d2b23346 120 $USER->editing = 0;
a3f24f7c 121 if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
122 $USER->activitycopy = false;
123 $USER->activitycopycourse = NULL;
9c9f7d77 124 }
ad96cc52
AKA
125 // Redirect to site root if Editing is toggled on frontpage
126 if ($course->id == SITEID) {
127 redirect($CFG->wwwroot .'/?redirect=0');
128 } else {
129 redirect($PAGE->url);
130 }
f9903ed0 131 }
8223d271 132
af189935
PS
133 if (has_capability('moodle/course:update', $context)) {
134 if ($hide && confirm_sesskey()) {
135 set_section_visible($course->id, $hide, '0');
e3c171e1 136 redirect($PAGE->url);
af189935 137 }
7d99d695 138
af189935
PS
139 if ($show && confirm_sesskey()) {
140 set_section_visible($course->id, $show, '1');
e3c171e1 141 redirect($PAGE->url);
af189935 142 }
12905134 143
af189935
PS
144 if (!empty($section)) {
145 if (!empty($move) and confirm_sesskey()) {
93d46f48
RK
146 if (move_section($course, $section, $move)) {
147 if ($course->id == SITEID) {
148 redirect($CFG->wwwroot . '/?redirect=0');
149 } else {
e3c171e1 150 redirect(course_get_url($course));
93d46f48
RK
151 }
152 } else {
af189935
PS
153 echo $OUTPUT->notification('An error occurred while moving a section');
154 }
56e34ee4 155 }
12905134 156 }
157 }
48d72fa7 158 } else {
d2b23346 159 $USER->editing = 0;
7d99d695 160 }
161
45774bdd 162 $SESSION->fromdiscussion = $PAGE->url->out(false);
4c701e6f 163
f45cc76f 164
165 if ($course->id == SITEID) {
166 // This course is not a real course.
892c0825 167 redirect($CFG->wwwroot .'/');
83f3c62d 168 }
0a127169 169
cf615522 170 $completion = new completion_info($course);
171 if ($completion->is_enabled() && ajaxenabled()) {
76c0123b
PS
172 $PAGE->requires->string_for_js('completion-title-manual-y', 'completion');
173 $PAGE->requires->string_for_js('completion-title-manual-n', 'completion');
174 $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion');
175 $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion');
176
177 $PAGE->requires->js_init_call('M.core_completion.init');
cf615522 178 }
179
8a7934f7
PS
180 // We are currently keeping the button here from 1.x to help new teachers figure out
181 // what to do, even though the link also appears in the course admin block. It also
2b3d1ac7 182 // means you can back out of a situation where you removed the admin block. :)
5d3e9d9f 183 if ($PAGE->user_allowed_editing()) {
d628215d 184 $buttons = $OUTPUT->edit_button($PAGE->url);
2b3d1ac7 185 $PAGE->set_button($buttons);
5d3e9d9f 186 }
187
2b9e3bac 188 $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
0a122046 189 $PAGE->set_heading($course->fullname);
0a122046 190 echo $OUTPUT->header();
f45cc76f 191
cf615522 192 if ($completion->is_enabled() && ajaxenabled()) {
9a5a0694 193 // This value tracks whether there has been a dynamic change to the page.
194 // It is used so that if a user does this - (a) set some tickmarks, (b)
195 // go to another page, (c) clicks Back button - the page will
196 // automatically reload. Otherwise it would start with the wrong tick
197 // values.
47e75d04
SH
198 echo html_writer::start_tag('form', array('action'=>'.', 'method'=>'get'));
199 echo html_writer::start_tag('div');
200 echo html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'completion_dynamic_change', 'name'=>'completion_dynamic_change', 'value'=>'0'));
201 echo html_writer::end_tag('div');
202 echo html_writer::end_tag('form');
4e781c7b 203 }
204
f45cc76f 205 // Course wrapper start.
47e75d04 206 echo html_writer::start_tag('div', array('class'=>'course-content'));
f45cc76f 207
f20edd52 208 $modinfo = get_fast_modinfo($COURSE);
9c9f7d77 209 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
a6af674a 210 foreach($mods as $modid=>$unused) {
211 if (!isset($modinfo->cms[$modid])) {
212 rebuild_course_cache($course->id);
f20edd52 213 $modinfo = get_fast_modinfo($COURSE);
a6af674a 214 debugging('Rebuilding course cache', DEBUG_DEVELOPER);
215 break;
216 }
217 }
19801b2b 218
94dc3c7d 219 if (!$sections = $modinfo->get_section_info_all()) { // No sections found
ce4dfd27 220 $section = new stdClass;
221 $section->course = $course->id; // Create a default section.
222 $section->section = 0;
223 $section->visible = 1;
224 $section->summaryformat = FORMAT_HTML;
225 $section->id = $DB->insert_record('course_sections', $section);
226 rebuild_course_cache($course->id);
227 $modinfo = get_fast_modinfo($COURSE);
94dc3c7d 228 if (!$sections = $modinfo->get_section_info_all()) { // Try again
dbf91d9d 229 print_error('cannotcreateorfindstructs', 'error');
19801b2b 230 }
231 }
7468bf01 232
45774bdd
DP
233 // CAUTION, hacky fundamental variable defintion to follow!
234 // Note that because of the way course fromats are constructed though
235 // inclusion we pass parameters around this way..
236 $displaysection = $section;
237
f45cc76f 238 // Include the actual course format.
239 require($CFG->dirroot .'/course/format/'. $course->format .'/format.php');
240 // Content wrapper end.
47e75d04
SH
241
242 echo html_writer::end_tag('div');
f45cc76f 243
ebaa29d1 244 // Include the command toolbox YUI module
5103b5e6 245 include_course_ajax($course, $modnamesused, $modnames);
f45cc76f 246
d60c1124 247 echo $OUTPUT->footer();