MDL-50015 mod_imscp: New WS mod_imscp_view_imscp
[moodle.git] / mod / survey / index.php
CommitLineData
5956e2ef 1<?php
f9903ed0 2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
f9903ed0 5
2d5b322c 6 $id = required_param('id', PARAM_INT); // Course Module ID
f9903ed0 7
a6855934 8 $PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
5956e2ef 9
579d45b4 10 if (!$course = $DB->get_record('course', array('id'=>$id))) {
83b10e57 11 print_error('invalidcourseid');
f9903ed0 12 }
13
f950af3c 14 require_course_login($course);
191b267b 15 $PAGE->set_pagelayout('incourse');
5eb45fa0 16
9e176aa2
RT
17 $params = array(
18 'context' => context_course::instance($course->id),
19 'courseid' => $course->id
20 );
21 $event = \mod_survey\event\course_module_instance_list_viewed::create($params);
22 $event->trigger();
f9903ed0 23
98899fc0 24 $strsurveys = get_string("modulenameplural", "survey");
98899fc0 25 $strname = get_string("name");
26 $strstatus = get_string("status");
27 $strdone = get_string("done", "survey");
28 $strnotdone = get_string("notdone", "survey");
dd97c328 29
207e24b8 30 $PAGE->navbar->add($strsurveys);
31 $PAGE->set_title($strsurveys);
5617e8c9 32 $PAGE->set_heading($course->fullname);
207e24b8 33 echo $OUTPUT->header();
5def24cf 34 echo $OUTPUT->heading($strsurveys);
f9903ed0 35
1f106b3f 36 if (! $surveys = get_all_instances_in_course("survey", $course)) {
b1892167 37 notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
f9903ed0 38 }
dd97c328 39
7487c856 40 $usesections = course_format_uses_sections($course->format);
7487c856 41
02f78a26 42 $table = new html_table();
43
7487c856 44 if ($usesections) {
09af1e28 45 $strsectionname = get_string('sectionname', 'format_'.$course->format);
63d25e41 46 $table->head = array ($strsectionname, $strname, $strstatus);
77775bff 47 } else {
63d25e41 48 $table->head = array ($strname, $strstatus);
77775bff 49 }
f9903ed0 50
8eb675a5 51 $currentsection = '';
52
1f106b3f 53 foreach ($surveys as $survey) {
4f0c2d00 54 if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
98899fc0 55 $ss = $strdone;
f9903ed0 56 } else {
98899fc0 57 $ss = $strnotdone;
f9903ed0 58 }
8eb675a5 59 $printsection = "";
7487c856
SH
60 if ($usesections) {
61 if ($survey->section !== $currentsection) {
62 if ($survey->section) {
71a56e08 63 $printsection = get_section_name($course, $survey->section);
7487c856
SH
64 }
65 if ($currentsection !== "") {
66 $table->data[] = 'hr';
67 }
68 $currentsection = $survey->section;
8eb675a5 69 }
9c9f7d77 70 }
c37053ea 71 //Calculate the href
1f106b3f 72 if (!$survey->visible) {
73 //Show dimmed if the mod is hidden
74 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
75 } else {
76 //Show normal if the mod is visible
77 $tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
78 }
c37053ea 79
7487c856 80 if ($usesections) {
1f106b3f 81 $table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
77775bff 82 } else {
1f106b3f 83 $table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
77775bff 84 }
f9903ed0 85 }
86
d1290cec 87 echo "<br />";
16be8974 88 echo html_writer::table($table);
641f16ba 89 echo $OUTPUT->footer();
f9903ed0 90
e5dd8e3b 91