MDL-21695 adding help string
[moodle.git] / mod / lesson / index.php
blob6f87d2bde02b845768c0fb1cb7f94d93f516383c
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This page lists all the instances of lesson in a particular course
21 * @package lesson
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 **/
26 /** Include required files */
27 require_once("../../config.php");
28 require_once($CFG->dirroot.'/mod/lesson/locallib.php');
30 $id = required_param('id', PARAM_INT); // course
32 $PAGE->set_url('/mod/lesson/index.php', array('id'=>$id));
34 if (!$course = $DB->get_record("course", array("id" => $id))) {
35 print_error('invalidcourseid');
38 require_login($course);
39 $PAGE->set_pagelayout('incourse');
41 add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", "");
44 /// Get all required strings
46 $strlessons = get_string("modulenameplural", "lesson");
47 $strlesson = get_string("modulename", "lesson");
50 /// Print the header
51 $PAGE->navbar->add($strlessons);
52 $PAGE->set_title("$course->shortname: $strlessons");
53 $PAGE->set_heading($course->fullname);
54 echo $OUTPUT->header();
56 /// Get all the appropriate data
58 if (! $lessons = get_all_instances_in_course("lesson", $course)) {
59 notice(get_string('thereareno', 'moodle', $strlessons), "../../course/view.php?id=$course->id");
60 die;
63 /// Print the list of instances (your module will probably extend this)
65 $timenow = time();
66 $strname = get_string("name");
67 $strgrade = get_string("grade");
68 $strdeadline = get_string("deadline", "lesson");
69 $strweek = get_string("week");
70 $strtopic = get_string("topic");
71 $strnodeadline = get_string("nodeadline", "lesson");
72 $table = new html_table();
74 if ($course->format == "weeks") {
75 $table->head = array ($strweek, $strname, $strgrade, $strdeadline);
76 $table->align = array ("center", "left", "center", "center");
77 } else if ($course->format == "topics") {
78 $table->head = array ($strtopic, $strname, $strgrade, $strdeadline);
79 $table->align = array ("center", "left", "center", "center");
80 } else {
81 $table->head = array ($strname, $strgrade, $strdeadline);
82 $table->align = array ("left", "center", "center");
85 foreach ($lessons as $lesson) {
86 if (!$lesson->visible) {
87 //Show dimmed if the mod is hidden
88 $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
89 } else {
90 //Show normal if the mod is visible
91 $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
93 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
94 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
96 if ($lesson->deadline == 0) {
97 $due = $strnodeadline;
98 } else if ($lesson->deadline > $timenow) {
99 $due = userdate($lesson->deadline);
100 } else {
101 $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>";
104 if ($course->format == "weeks" or $course->format == "topics") {
105 if (has_capability('mod/lesson:manage', $context)) {
106 $grade_value = $lesson->grade;
107 } else {
108 // it's a student, show their grade
109 $grade_value = 0;
110 if ($return = lesson_get_user_grades($lesson, $USER->id)) {
111 $grade_value = $return[$USER->id]->rawgrade;
114 $table->data[] = array ($lesson->section, $link, $grade_value, $due);
115 } else {
116 $table->data[] = array ($link, $lesson->grade, $due);
119 echo html_writer::table($table);
120 echo $OUTPUT->footer();