b75365980236c34078cb488286aacbcaf37f58ab
[moodle.git] / mod / survey / index.php
1 <?php
3     require_once("../../config.php");
4     require_once("lib.php");
6     $id = required_param('id', PARAM_INT);    // Course Module ID
8     $PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
10     if (!$course = $DB->get_record('course', array('id'=>$id))) {
11         print_error('invalidcourseid');
12     }
14     require_course_login($course);
15     $PAGE->set_pagelayout('incourse');
17     add_to_log($course->id, "survey", "view all", "index.php?id=$course->id", "");
19     $strsurveys = get_string("modulenameplural", "survey");
20     $strname = get_string("name");
21     $strstatus = get_string("status");
22     $strdone  = get_string("done", "survey");
23     $strnotdone  = get_string("notdone", "survey");
25     $PAGE->navbar->add($strsurveys);
26     $PAGE->set_title($strsurveys);
27     $PAGE->set_heading($course->fullname);
28     echo $OUTPUT->header();
29     echo $OUTPUT->heading($strsurveys);
31     if (! $surveys = get_all_instances_in_course("survey", $course)) {
32         notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
33     }
35     $usesections = course_format_uses_sections($course->format);
37     $table = new html_table();
38     $table->width = '100%';
40     if ($usesections) {
41         $strsectionname = get_string('sectionname', 'format_'.$course->format);
42         $table->head  = array ($strsectionname, $strname, $strstatus);
43     } else {
44         $table->head  = array ($strname, $strstatus);
45     }
47     $currentsection = '';
49     foreach ($surveys as $survey) {
50         if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
51             $ss = $strdone;
52         } else {
53             $ss = $strnotdone;
54         }
55         $printsection = "";
56         if ($usesections) {
57             if ($survey->section !== $currentsection) {
58                 if ($survey->section) {
59                     $printsection = get_section_name($course, $survey->section);
60                 }
61                 if ($currentsection !== "") {
62                     $table->data[] = 'hr';
63                 }
64                 $currentsection = $survey->section;
65             }
66         }
67         //Calculate the href
68         if (!$survey->visible) {
69             //Show dimmed if the mod is hidden
70             $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
71         } else {
72             //Show normal if the mod is visible
73             $tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
74         }
76         if ($usesections) {
77             $table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
78         } else {
79             $table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
80         }
81     }
83     echo "<br />";
84     echo html_writer::table($table);
85     echo $OUTPUT->footer();