MDL-15476
[moodle-linuxchix.git] / mod / lesson / index.php
blobea33f44ebca7b86f1d9dad0a5e76054b104e458b
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(get_string('thereareno', 'moodle', $strlessons), "../../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 $strnodeadline = get_string("nodeadline", "lesson");
55 $table = new stdClass;
57 if ($course->format == "weeks") {
58 $table->head = array ($strweek, $strname, $strgrade, $strdeadline);
59 $table->align = array ("center", "left", "center", "center");
60 } else if ($course->format == "topics") {
61 $table->head = array ($strtopic, $strname, $strgrade, $strdeadline);
62 $table->align = array ("center", "left", "center", "center");
63 } else {
64 $table->head = array ($strname, $strgrade, $strdeadline);
65 $table->align = array ("left", "center", "center");
68 foreach ($lessons as $lesson) {
69 if (!$lesson->visible) {
70 //Show dimmed if the mod is hidden
71 $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
72 } else {
73 //Show normal if the mod is visible
74 $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
76 $cm = get_coursemodule_from_instance('lesson', $lesson->id);
77 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
79 if ($lesson->deadline == 0) {
80 $due = $strnodeadline;
81 } else if ($lesson->deadline > $timenow) {
82 $due = userdate($lesson->deadline);
83 } else {
84 $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>";
87 if ($course->format == "weeks" or $course->format == "topics") {
88 if (has_capability('mod/lesson:manage', $context)) {
89 $grade_value = $lesson->grade;
90 } else {
91 // it's a student, show their grade
92 $grade_value = 0;
93 if ($return = lesson_get_user_grades($lesson, $USER->id)) {
94 $grade_value = $return[$USER->id]->rawgrade;
97 $table->data[] = array ($lesson->section, $link, $grade_value, $due);
98 } else {
99 $table->data[] = array ($link, $lesson->grade, $due);
103 echo "<br />";
105 print_table($table);
107 /// Finish the page
109 print_footer($course);