file width.html was added on branch MOODLE_15_STABLE on 2005-07-07 16:14:37 +0000
[moodle.git] / course / view.php
blob943584b85effe05981f5c0b07461f86947e4bdb0
1 <?php // $Id$
3 // Display the course home page.
5 require_once('../config.php');
6 require_once('lib.php');
7 require_once($CFG->libdir.'/blocklib.php');
9 $id = optional_param('id', 0, PARAM_INT);
10 $name = optional_param('name');
11 $edit = optional_param('edit');
12 $idnumber = optional_param('idnumber');
14 if (empty($id) && empty($name)) {
15 error("Must specify course id or short name");
18 if (!empty($name)) {
19 if (! ($course = get_record('course', 'shortname', $name)) ) {
20 error('Invalid short course name');
22 } else if (!empty($idnumber)) {
23 if (! ($course = get_record('course', 'idnumber', $idnumber)) ) {
24 error('Invalid course idnumber');
26 } else {
27 if (! ($course = get_record('course', 'id', $id)) ) {
28 error('Invalid course id');
32 require_login($course->id);
34 //If course is hosted on an external server, redirect to corresponding
35 //url with appropriate authentication attached as parameter
36 if (file_exists($CFG->dirroot ."/course/externservercourse.php")) {
37 include $CFG->dirroot ."/course/externservercourse.php";
38 if (function_exists(extern_server_course)) {
39 if ($extern_url = extern_server_course($course)) {
40 redirect($extern_url);
45 require_once($CFG->dirroot.'/calendar/lib.php'); /// This is after login because it needs $USER
47 add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
49 $course->format = clean_param($course->format, PARAM_ALPHA);
50 if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) {
51 $course->format = 'weeks'; // Default format is weeks
54 $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
55 $pageblocks = blocks_setup($PAGE);
57 if (!isset($USER->editing)) {
58 $USER->editing = false;
61 if ($PAGE->user_allowed_editing()) {
62 if ($edit == 'on') {
63 $USER->editing = true;
64 } else if ($edit == 'off') {
65 $USER->editing = false;
66 if(!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
67 $USER->activitycopy = false;
68 $USER->activitycopycourse = NULL;
72 if (isset($hide) && confirm_sesskey()) {
73 set_section_visible($course->id, $hide, '0');
76 if (isset($show) && confirm_sesskey()) {
77 set_section_visible($course->id, $show, '1');
80 if (!empty($section)) {
81 if (!empty($move) and confirm_sesskey()) {
82 if (!move_section($course, $section, $move)) {
83 notify("An error occurred while moving a section");
87 } else {
88 $USER->editing = false;
91 $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
93 if ($course->id == SITEID) { // This course is not a real course.
94 redirect("$CFG->wwwroot/");
97 $PAGE->print_header(get_string('course').': %fullname%');
99 echo '<div class="course-content">'; // course wrapper start
101 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
103 if (! $sections = get_all_sections($course->id)) { // No sections found
104 // Double-check to be extra sure
105 if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) {
106 $section->course = $course->id; // Create a default section.
107 $section->section = 0;
108 $section->visible = 1;
109 $section->id = insert_record("course_sections", $section);
111 if (! $sections = get_all_sections($course->id) ) { // Try again
112 error("Error finding or creating section structures for this course");
116 if (empty($course->modinfo)) { // Course cache was never made
117 rebuild_course_cache($course->id);
118 if (! $course = get_record("course", "id", $course->id) ) {
119 error("That's an invalid course id");
123 require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format
125 echo '</div>'; // content wrapper end
126 print_footer(NULL, $course);