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