Added 'studentview' button functionality.
[moodle.git] / course / view.php
CommitLineData
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
2335781f 9 $id = optional_param('id', 0, PARAM_INT);
10 $name = optional_param('name');
a3f24f7c 11 $edit = optional_param('edit');
816acb46 12 $idnumber = optional_param('idnumber');
37ef382c 13 $topic = optional_param('topic',0,PARAM_INT);
f9903ed0 14
2335781f 15 if (empty($id) && empty($name)) {
388f8911 16 error("Must specify course id or short name");
17 }
f9903ed0 18
2335781f 19 if (!empty($name)) {
20 if (! ($course = get_record('course', 'shortname', $name)) ) {
21 error('Invalid short course name');
388f8911 22 }
816acb46 23 } else if (!empty($idnumber)) {
24 if (! ($course = get_record('course', 'idnumber', $idnumber)) ) {
25 error('Invalid course idnumber');
26 }
388f8911 27 } else {
2335781f 28 if (! ($course = get_record('course', 'id', $id)) ) {
29 error('Invalid course id');
388f8911 30 }
f9903ed0 31 }
32
783da262 33 require_login($course->id);
388f8911 34
542a0435 35 //If course is hosted on an external server, redirect to corresponding
36 //url with appropriate authentication attached as parameter
892c0825 37 if (file_exists($CFG->dirroot .'/course/externservercourse.php')) {
38 include $CFG->dirroot .'/course/externservercourse.php';
542a0435 39 if (function_exists(extern_server_course)) {
40 if ($extern_url = extern_server_course($course)) {
41 redirect($extern_url);
42 }
43 }
44 }
45
08cebf19 46 require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER
af62781b 47
892c0825 48 add_to_log($course->id, 'course', 'view', "view.php?id=$course->id", "$course->id");
f9903ed0 49
e069b3e2 50 $course->format = clean_param($course->format, PARAM_ALPHA);
0f3fe4b6 51 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
52 $course->format = 'weeks'; // Default format is weeks
53 }
54
7542a4e5 55 $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
3615b2b2 56 $pageblocks = blocks_setup($PAGE);
daa27ce4 57
0f3fe4b6 58 if (!isset($USER->editing)) {
59 $USER->editing = false;
60 }
61
a3f24f7c 62 if ($PAGE->user_allowed_editing()) {
63 if ($edit == 'on') {
64 $USER->editing = true;
65 } else if ($edit == 'off') {
66 $USER->editing = false;
67 if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
68 $USER->activitycopy = false;
69 $USER->activitycopycourse = NULL;
9c9f7d77 70 }
f9903ed0 71 }
8223d271 72
9b4b78fd 73 if (isset($hide) && confirm_sesskey()) {
82b181f2 74 set_section_visible($course->id, $hide, '0');
73fafc38 75 }
7d99d695 76
9b4b78fd 77 if (isset($show) && confirm_sesskey()) {
82b181f2 78 set_section_visible($course->id, $show, '1');
73fafc38 79 }
12905134 80
81 if (!empty($section)) {
5b224948 82 if (!empty($move) and confirm_sesskey()) {
56e34ee4 83 if (!move_section($course, $section, $move)) {
892c0825 84 notify('An error occurred while moving a section');
56e34ee4 85 }
12905134 86 }
87 }
48d72fa7 88 } else {
89 $USER->editing = false;
7d99d695 90 }
91
892c0825 92 $SESSION->fromdiscussion = $CFG->wwwroot .'/course/view.php?id='. $course->id;
4c701e6f 93
83f3c62d 94 if ($course->id == SITEID) { // This course is not a real course.
892c0825 95 redirect($CFG->wwwroot .'/');
83f3c62d 96 }
97
f032aa7a 98 $PAGE->print_header(get_string('course').': %fullname%');
f9903ed0 99
ee4dc51e 100 echo '<div class="course-content">'; // course wrapper start
daa27ce4 101
9c9f7d77 102 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
19801b2b 103
dfec7b01 104 if (! $sections = get_all_sections($course->id)) { // No sections found
105 // Double-check to be extra sure
892c0825 106 if (! $section = get_record('course_sections', 'course', $course->id, 'section', 0)) {
dfec7b01 107 $section->course = $course->id; // Create a default section.
108 $section->section = 0;
109 $section->visible = 1;
892c0825 110 $section->id = insert_record('course_sections', $section);
dfec7b01 111 }
112 if (! $sections = get_all_sections($course->id) ) { // Try again
892c0825 113 error('Error finding or creating section structures for this course');
19801b2b 114 }
115 }
7468bf01 116
51955364 117 if (empty($course->modinfo)) { // Course cache was never made
118 rebuild_course_cache($course->id);
892c0825 119 if (! $course = get_record('course', 'id', $course->id) ) {
db34bb59 120 error("That's an invalid course id");
121 }
51955364 122 }
123
892c0825 124 require($CFG->dirroot .'/course/format/'. $course->format .'/format.php'); // Include the actual course format
f9903ed0 125
daa27ce4 126 echo '</div>'; // content wrapper end
093a4a24 127 print_footer(NULL, $course);
f9903ed0 128
892c0825 129?>