_ added the div framework
[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
388f8911 9 optional_variable($id);
10 optional_variable($name);
f9903ed0 11
9b4b78fd 12 optional_param('blockaction');
13 optional_param('instanceid', 0, PARAM_INT);
14 optional_param('blockid', 0, PARAM_INT);
15
388f8911 16 if (!$id and !$name) {
17 error("Must specify course id or short name");
18 }
f9903ed0 19
c7609872 20 if (!empty($_GET['name'])) {
0f3fe4b6 21 if (! ($course = get_record("course", "shortname", $name)) ) {
388f8911 22 error("That's an invalid short course name");
23 }
24 } else {
0f3fe4b6 25 if (! ($course = get_record("course", "id", $id)) ) {
388f8911 26 error("That's an invalid course id");
27 }
f9903ed0 28 }
29
783da262 30 require_login($course->id);
388f8911 31
08cebf19 32 require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER
af62781b 33
600149be 34 add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
f9903ed0 35
0f3fe4b6 36 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
37 $course->format = 'weeks'; // Default format is weeks
38 }
39
9b128500 40 $PAGE = page_create_object(MOODLE_PAGE_COURSE, $course->id);
f032aa7a 41 $pageblocks = blocks_get_by_page($PAGE);
9b4b78fd 42
0f3fe4b6 43 if (!isset($USER->editing)) {
44 $USER->editing = false;
45 }
46
47 $editing = false;
48
73047f2f 49 if (isteacheredit($course->id)) {
0f3fe4b6 50 if (isset($edit)) {
9c9f7d77 51 if ($edit == "on") {
52 $USER->editing = true;
53 } else if ($edit == "off") {
54 $USER->editing = false;
55 }
f9903ed0 56 }
8223d271 57
0f3fe4b6 58 $editing = $USER->editing;
59
9b4b78fd 60 if (isset($hide) && confirm_sesskey()) {
82b181f2 61 set_section_visible($course->id, $hide, '0');
73fafc38 62 }
7d99d695 63
9b4b78fd 64 if (isset($show) && confirm_sesskey()) {
82b181f2 65 set_section_visible($course->id, $show, '1');
73fafc38 66 }
12905134 67
9b4b78fd 68 if (!empty($blockaction) && confirm_sesskey()) {
69 if (!empty($blockid)) {
f032aa7a 70 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
9b4b78fd 71
0f3fe4b6 72 }
9b4b78fd 73 else if (!empty($instanceid)) {
74 $instance = blocks_find_instance($instanceid, $pageblocks);
f032aa7a 75 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
0f3fe4b6 76 }
9b4b78fd 77 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
78 // but I 'm not sure if it's worth the complexity increase...
f032aa7a 79 $pageblocks = blocks_get_by_page($PAGE);
0f3fe4b6 80 }
81
f032aa7a 82 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
9b4b78fd 83
12905134 84 if (!empty($section)) {
5b224948 85 if (!empty($move) and confirm_sesskey()) {
56e34ee4 86 if (!move_section($course, $section, $move)) {
87 notify("An error occurred while moving a section");
88 }
12905134 89 }
90 }
48d72fa7 91 } else {
92 $USER->editing = false;
7d99d695 93 }
94
4c701e6f 95 $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
4c701e6f 96
83f3c62d 97 if ($course->id == SITEID) { // This course is not a real course.
98 redirect("$CFG->wwwroot/");
99 }
100
f032aa7a 101 $PAGE->print_header(get_string('course').': %fullname%');
f9903ed0 102
9c9f7d77 103 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
19801b2b 104
dfec7b01 105 if (! $sections = get_all_sections($course->id)) { // No sections found
106 // Double-check to be extra sure
107 if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) {
108 $section->course = $course->id; // Create a default section.
109 $section->section = 0;
110 $section->visible = 1;
111 $section->id = insert_record("course_sections", $section);
112 }
113 if (! $sections = get_all_sections($course->id) ) { // Try again
19801b2b 114 error("Error finding or creating section structures for this course");
115 }
116 }
7468bf01 117
51955364 118 if (empty($course->modinfo)) { // Course cache was never made
119 rebuild_course_cache($course->id);
db34bb59 120 if (! $course = get_record("course", "id", $course->id) ) {
121 error("That's an invalid course id");
122 }
51955364 123 }
124
6049fb78 125 require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format
f9903ed0 126
093a4a24 127 print_footer(NULL, $course);
f9903ed0 128
f9903ed0 129?>