Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / lesson / index.php
blob0c64f97bb8b2464f3b60f7c11dc9e542f851cdba
1 <?PHP // $Id$
3 /// This page lists all the instances of lesson in a particular course
5 require_once("../../config.php");
6 require_once("locallib.php");
8 require_variable($id); // course
10 if (!$course = get_record("course", "id", $id)) {
11 error("Course ID is incorrect");
14 require_login($course->id);
16 add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", "");
19 /// Get all required strings
21 $strlessons = get_string("modulenameplural", "lesson");
22 $strlesson = get_string("modulename", "lesson");
25 /// Print the header
27 if ($course->category) {
28 $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
31 print_header("$course->shortname: $strlessons", "$course->fullname", "$navigation $strlessons", "", "", true, "", navmenu($course));
33 /// Get all the appropriate data
35 if (! $lessons = get_all_instances_in_course("lesson", $course)) {
36 notice("There are no lessons", "../../course/view.php?id=$course->id");
37 die;
40 /// Print the list of instances (your module will probably extend this)
42 $timenow = time();
43 $strname = get_string("name");
44 $strgrade = get_string("grade");
45 $strdeadline = get_string("deadline", "lesson");
46 $strweek = get_string("week");
47 $strtopic = get_string("topic");
48 $table = new stdClass;
50 if ($course->format == "weeks") {
51 $table->head = array ($strweek, $strname, $strgrade, $strdeadline);
52 $table->align = array ("CENTER", "LEFT", "CENTER", "CENTER");
53 } else if ($course->format == "topics") {
54 $table->head = array ($strtopic, $strname, $strgrade, $strdeadline);
55 $table->align = array ("CENTER", "LEFT", "CENTER", "CENTER");
56 } else {
57 $table->head = array ($strname, $strgrade, $strdeadline);
58 $table->align = array ("LEFT", "CENTER", "CENTER");
61 foreach ($lessons as $lesson) {
62 if (!$lesson->visible) {
63 //Show dimmed if the mod is hidden
64 $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
65 } else {
66 //Show normal if the mod is visible
67 $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
70 if ($lesson->deadline > $timenow) {
71 $due = userdate($lesson->deadline);
72 } else {
73 $due = "<FONT COLOR=\"red\">".userdate($lesson->deadline)."</FONT>";
76 if ($course->format == "weeks" or $course->format == "topics") {
77 if (isteacher($course->id)) {
78 $grade_value = $lesson->grade;
79 } else {
80 // it's a student, show their mean or maximum grade
81 if ($lesson->usemaxgrade) {
82 $grade = get_record_sql("SELECT MAX(grade) as grade FROM {$CFG->prefix}lesson_grades
83 WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
84 } else {
85 $grade = get_record_sql("SELECT AVG(grade) as grade FROM {$CFG->prefix}lesson_grades
86 WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
88 if ($grade) {
89 // grades are stored as percentages
90 $grade_value = number_format($grade->grade * $lesson->grade / 100, 1);
91 } else {
92 $grade_value = 0;
95 $table->data[] = array ($lesson->section, $link, $grade_value, $due);
96 } else {
97 $table->data[] = array ($link, $grade_value, $due);
101 echo "<BR>";
103 print_table($table);
105 /// Finish the page
107 print_footer($course);