Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / lesson / index.php
bloba28404b903984857f178d9c3480ef22f60452d31
1 <?php // $Id$
2 /**
3 * This page lists all the instances of lesson in a particular course
5 * @version $Id$
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package lesson
8 **/
10 require_once("../../config.php");
11 require_once($CFG->dirroot.'/mod/lesson/lib.php');
12 require_once($CFG->dirroot.'/mod/lesson/locallib.php');
14 $id = required_param('id', PARAM_INT); // course
16 if (!$course = get_record("course", "id", $id)) {
17 error("Course ID is incorrect");
20 require_login($course->id);
22 add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", "");
25 /// Get all required strings
27 $strlessons = get_string("modulenameplural", "lesson");
28 $strlesson = get_string("modulename", "lesson");
31 /// Print the header
32 $navlinks = array();
33 $navlinks[] = array('name' => $strlessons, 'link' => '', 'type' => 'activity');
35 $navigation = build_navigation($navlinks);
37 print_header("$course->shortname: $strlessons", $course->fullname, $navigation, "", "", true, "", navmenu($course));
39 /// Get all the appropriate data
41 if (! $lessons = get_all_instances_in_course("lesson", $course)) {
42 notice("There are no lessons", "../../course/view.php?id=$course->id");
43 die;
46 /// Print the list of instances (your module will probably extend this)
48 $timenow = time();
49 $strname = get_string("name");
50 $strgrade = get_string("grade");
51 $strdeadline = get_string("deadline", "lesson");
52 $strweek = get_string("week");
53 $strtopic = get_string("topic");
54 $table = new stdClass;
56 if ($course->format == "weeks") {
57 $table->head = array ($strweek, $strname, $strgrade, $strdeadline);
58 $table->align = array ("center", "left", "center", "center");
59 } else if ($course->format == "topics") {
60 $table->head = array ($strtopic, $strname, $strgrade, $strdeadline);
61 $table->align = array ("center", "left", "center", "center");
62 } else {
63 $table->head = array ($strname, $strgrade, $strdeadline);
64 $table->align = array ("left", "center", "center");
67 foreach ($lessons as $lesson) {
68 if (!$lesson->visible) {
69 //Show dimmed if the mod is hidden
70 $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
71 } else {
72 //Show normal if the mod is visible
73 $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
75 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
76 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
78 if ($lesson->deadline > $timenow) {
79 $due = userdate($lesson->deadline);
80 } else {
81 $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>";
84 if ($course->format == "weeks" or $course->format == "topics") {
85 if (has_capability('mod/lesson:manage', $context)) {
86 $grade_value = $lesson->grade;
87 } else {
88 // it's a student, show their grade
89 $grade_value = 0;
90 if ($return = lesson_get_user_grades($lesson, $USER->id)) {
91 $grade_value = $return[$USER->id]->rawgrade;
94 $table->data[] = array ($lesson->section, $link, $grade_value, $due);
95 } else {
96 $table->data[] = array ($link, $lesson->grade, $due);
100 echo "<br />";
102 print_table($table);
104 /// Finish the page
106 print_footer($course);