xhtml compliance
[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');
2335781f 13 $blockaction = optional_param('blockaction');
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
08cebf19 35 require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER
af62781b 36
600149be 37 add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
f9903ed0 38
e069b3e2 39 $course->format = clean_param($course->format, PARAM_ALPHA);
0f3fe4b6 40 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
41 $course->format = 'weeks'; // Default format is weeks
42 }
43
7542a4e5 44 $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
f032aa7a 45 $pageblocks = blocks_get_by_page($PAGE);
daa27ce4 46
0f3fe4b6 47 if (!isset($USER->editing)) {
48 $USER->editing = false;
49 }
50
a3f24f7c 51 if ($PAGE->user_allowed_editing()) {
52 if ($edit == 'on') {
53 $USER->editing = true;
54 } else if ($edit == 'off') {
55 $USER->editing = false;
56 if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
57 $USER->activitycopy = false;
58 $USER->activitycopycourse = NULL;
9c9f7d77 59 }
f9903ed0 60 }
8223d271 61
9b4b78fd 62 if (isset($hide) && confirm_sesskey()) {
82b181f2 63 set_section_visible($course->id, $hide, '0');
73fafc38 64 }
7d99d695 65
9b4b78fd 66 if (isset($show) && confirm_sesskey()) {
82b181f2 67 set_section_visible($course->id, $show, '1');
73fafc38 68 }
12905134 69
da71112b 70 if (!empty($blockaction)) {
71 blocks_execute_url_action($PAGE, $pageblocks);
9b4b78fd 72 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
73 // but I 'm not sure if it's worth the complexity increase...
f032aa7a 74 $pageblocks = blocks_get_by_page($PAGE);
0f3fe4b6 75 }
76
12905134 77 if (!empty($section)) {
5b224948 78 if (!empty($move) and confirm_sesskey()) {
56e34ee4 79 if (!move_section($course, $section, $move)) {
80 notify("An error occurred while moving a section");
81 }
12905134 82 }
83 }
48d72fa7 84 } else {
85 $USER->editing = false;
7d99d695 86 }
87
4c701e6f 88 $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
4c701e6f 89
83f3c62d 90 if ($course->id == SITEID) { // This course is not a real course.
91 redirect("$CFG->wwwroot/");
92 }
93
f032aa7a 94 $PAGE->print_header(get_string('course').': %fullname%');
f9903ed0 95
ee4dc51e 96 echo '<div class="course-content">'; // course wrapper start
daa27ce4 97
9c9f7d77 98 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
19801b2b 99
dfec7b01 100 if (! $sections = get_all_sections($course->id)) { // No sections found
101 // Double-check to be extra sure
102 if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) {
103 $section->course = $course->id; // Create a default section.
104 $section->section = 0;
105 $section->visible = 1;
106 $section->id = insert_record("course_sections", $section);
107 }
108 if (! $sections = get_all_sections($course->id) ) { // Try again
19801b2b 109 error("Error finding or creating section structures for this course");
110 }
111 }
7468bf01 112
51955364 113 if (empty($course->modinfo)) { // Course cache was never made
114 rebuild_course_cache($course->id);
db34bb59 115 if (! $course = get_record("course", "id", $course->id) ) {
116 error("That's an invalid course id");
117 }
51955364 118 }
119
6049fb78 120 require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format
f9903ed0 121
daa27ce4 122 echo '</div>'; // content wrapper end
093a4a24 123 print_footer(NULL, $course);
f9903ed0 124
f9903ed0 125?>