New help translation
[moodle.git] / course / view.php
blobde5e64877a0f3496ed250b1f99f772598e336ecc
1 <?PHP // $Id$
3 // Display the course home page.
5 require_once("../config.php");
6 require_once("lib.php");
8 optional_variable($id);
9 optional_variable($name);
11 if (!$id and !$name) {
12 error("Must specify course id or short name");
15 if ($name) {
16 if (! $course = get_record("course", "shortname", $name) ) {
17 error("That's an invalid short course name");
19 } else {
20 if (! $course = get_record("course", "id", $id) ) {
21 error("That's an invalid course id");
25 require_login($course->id);
27 add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
29 if (isteacheredit($course->id)) {
30 if (isset($edit)) {
31 if ($edit == "on") {
32 $USER->editing = true;
33 } else if ($edit == "off") {
34 $USER->editing = false;
38 if (isset($hide)) {
39 set_section_visible($course->id, $hide, "0");
42 if (isset($show)) {
43 set_section_visible($course->id, $show, "1");
46 if (!empty($section)) {
47 if (!empty($move)) {
48 if (!move_section($course, $section, $move)) {
49 notify("An error occurred while moving a section");
53 } else {
54 $USER->editing = false;
57 $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
59 if (! $course->category) { // This course is not a real course.
60 redirect("$CFG->wwwroot/");
63 $courseword = get_string("course");
65 $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
67 print_header("$courseword: $course->fullname", "$course->fullname", "$course->shortname", "", "", true,
68 update_course_icon($course->id), $loggedinas);
70 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
72 if (! $sections = get_all_sections($course->id)) { // No sections found
73 // Double-check to be extra sure
74 if (! $section = get_record("course_sections", "course", $course->id, "section", 0)) {
75 $section->course = $course->id; // Create a default section.
76 $section->section = 0;
77 $section->visible = 1;
78 $section->id = insert_record("course_sections", $section);
80 if (! $sections = get_all_sections($course->id) ) { // Try again
81 error("Error finding or creating section structures for this course");
85 if (empty($course->modinfo)) { // Course cache was never made
86 rebuild_course_cache($course->id);
87 if (! $course = get_record("course", "id", $course->id) ) {
88 error("That's an invalid course id");
92 if (!file_exists("$CFG->dirroot/course/format/$course->format.php")) { // Default format is weeks
93 $course->format = "weeks";
96 require("$CFG->dirroot/course/format/$course->format.php"); // Include the actual course format
98 print_footer();