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