3 // Display the course home page.
5 require_once('../config.php');
6 require_once('lib.php');
7 require_once($CFG->libdir
.'/blocklib.php');
9 $id = optional_param('id', 0, PARAM_INT
);
10 $name = optional_param('name');
11 $edit = optional_param('edit','',PARAM_ALPHA
);
12 $idnumber = optional_param('idnumber');
13 $topic = optional_param('topic',0,PARAM_INT
);
14 $studentview = optional_param('studentview','',PARAM_ALPHA
);
16 if (empty($id) && empty($name) && empty($idnumber)) {
17 error("Must specify course id, short name or idnumber");
21 if (! ($course = get_record('course', 'shortname', $name)) ) {
22 error('Invalid short course name');
24 } else if (!empty($idnumber)) {
25 if (! ($course = get_record('course', 'idnumber', $idnumber)) ) {
26 error('Invalid course idnumber');
29 if (! ($course = get_record('course', 'id', $id)) ) {
30 error('Invalid course id');
34 require_login($course->id
);
36 //If course is hosted on an external server, redirect to corresponding
37 //url with appropriate authentication attached as parameter
38 if (file_exists($CFG->dirroot
.'/course/externservercourse.php')) {
39 include $CFG->dirroot
.'/course/externservercourse.php';
40 if (function_exists(extern_server_course
)) {
41 if ($extern_url = extern_server_course($course)) {
42 redirect($extern_url);
47 require_once($CFG->dirroot
.'/calendar/lib.php'); /// This is after login because it needs $USER
49 add_to_log($course->id
, 'course', 'view', "view.php?id=$course->id", "$course->id");
51 $course->format
= clean_param($course->format
, PARAM_ALPHA
);
52 if (!file_exists($CFG->dirroot
.'/course/format/'.$course->format
.'/format.php')) {
53 $course->format
= 'weeks'; // Default format is weeks
56 $PAGE = page_create_object(PAGE_COURSE_VIEW
, $course->id
);
57 $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH
);
59 if (!isset($USER->editing
)) {
60 $USER->editing
= false;
63 if (!isset($USER->studentview
)) {
64 $USER->studentview
= false;
67 // need to check this here, as studentview=on disables edit allowed (where 'on' is checked)
68 if (($studentview == 'off') and confirm_sesskey()) {
69 $USER->studentview
= false;
72 if ($PAGE->user_allowed_editing()) {
73 if (($edit == 'on') and confirm_sesskey()) {
74 $USER->editing
= true;
75 } else if (($edit == 'off') and confirm_sesskey()) {
76 $USER->editing
= false;
77 if(!empty($USER->activitycopy
) && $USER->activitycopycourse
== $course->id
) {
78 $USER->activitycopy
= false;
79 $USER->activitycopycourse
= NULL;
83 if (($studentview == 'on') and confirm_sesskey()) {
84 $USER->studentview
= true;
85 $USER->editing
= false;
88 if (isset($hide) && confirm_sesskey()) {
89 set_section_visible($course->id
, $hide, '0');
92 if (isset($show) && confirm_sesskey()) {
93 set_section_visible($course->id
, $show, '1');
96 if (!empty($section)) {
97 if (!empty($move) and confirm_sesskey()) {
98 if (!move_section($course, $section, $move)) {
99 notify('An error occurred while moving a section');
104 $USER->editing
= false;
107 $SESSION->fromdiscussion
= $CFG->wwwroot
.'/course/view.php?id='. $course->id
;
109 if ($course->id
== SITEID
) { // This course is not a real course.
110 redirect($CFG->wwwroot
.'/');
113 $PAGE->print_header(get_string('course').': %fullname%');
115 echo '<div class="course-content">'; // course wrapper start
117 get_all_mods($course->id
, $mods, $modnames, $modnamesplural, $modnamesused);
119 if (! $sections = get_all_sections($course->id
)) { // No sections found
120 // Double-check to be extra sure
121 if (! $section = get_record('course_sections', 'course', $course->id
, 'section', 0)) {
122 $section->course
= $course->id
; // Create a default section.
123 $section->section
= 0;
124 $section->visible
= 1;
125 $section->id
= insert_record('course_sections', $section);
127 if (! $sections = get_all_sections($course->id
) ) { // Try again
128 error('Error finding or creating section structures for this course');
132 if (empty($course->modinfo
)) { // Course cache was never made
133 rebuild_course_cache($course->id
);
134 if (! $course = get_record('course', 'id', $course->id
) ) {
135 error("That's an invalid course id");
139 require($CFG->dirroot
.'/course/format/'. $course->format
.'/format.php'); // Include the actual course format
141 echo '</div>'; // content wrapper end
142 print_footer(NULL, $course);