Moving some images around - cleaning up organisation
[moodle.git] / course / view.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Display the course home page.
4
b0e3a925 5 require_once("../config.php");
6 require_once("lib.php");
f9903ed0 7
388f8911 8 optional_variable($id);
9 optional_variable($name);
f9903ed0 10
388f8911 11 if (!$id and !$name) {
12 error("Must specify course id or short name");
13 }
f9903ed0 14
388f8911 15 if ($name) {
16 if (! $course = get_record("course", "shortname", $name) ) {
17 error("That's an invalid short course name");
18 }
19 } else {
20 if (! $course = get_record("course", "id", $id) ) {
21 error("That's an invalid course id");
22 }
f9903ed0 23 }
24
388f8911 25 require_login($id);
26
600149be 27 add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
f9903ed0 28
9c9f7d77 29 if (isset($edit)) {
30 if (isteacher($course->id)) {
31 if ($edit == "on") {
32 $USER->editing = true;
33 } else if ($edit == "off") {
34 $USER->editing = false;
35 }
f9903ed0 36 }
37 }
9c9f7d77 38
39 if (isset($help)) {
40 if ($help == "on") {
41 $USER->help = true;
42 } else if ($help == "off") {
43 $USER->help = false;
44 }
f9903ed0 45 }
8223d271 46
4c701e6f 47 $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
4c701e6f 48
b8391635 49 if (! $course->category) { // This course is not a real course.
50 redirect("$CFG->wwwroot/");
51 }
52
53
fa0626c6 54 $courseword = get_string("course");
55
b328523c 56 $loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
a282d0ff 57
fa0626c6 58 print_header("$courseword: $course->fullname", "$course->fullname", "$course->shortname", "search.search", "", true,
a282d0ff 59 update_course_icon($course->id), $loggedinas);
f9903ed0 60
9c9f7d77 61 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
19801b2b 62
63 if (! $sections = get_all_sections($course->id)) {
64 $section->course = $course->id; // Create a default section.
65 $section->section = 0;
66 $section->id = insert_record("course_sections", $section);
67 if (! $sections = get_all_sections($course->id) ) {
68 error("Error finding or creating section structures for this course");
69 }
70 }
7468bf01 71
f9903ed0 72 switch ($course->format) {
b5fe4c93 73 case "weeks":
f9903ed0 74 include("weeks.php");
75 break;
b5fe4c93 76 case "social":
4567fb71 77 include("social.php");
78 break;
b5fe4c93 79 case "topics":
0b35af18 80 include("topics.php");
81 break;
4567fb71 82 default:
83 error("Course format not defined yet!");
f9903ed0 84 }
85
2c26c985 86 print_footer();
f9903ed0 87
f9903ed0 88?>