Merge branch 'install_21_STABLE' of git://git.moodle.cz/moodle-install into MOODLE_21...
[moodle.git] / mod / survey / index.php
blob6154acfa2f536b91f26fd282009de4a91aa7bcca
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');
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 $strsectionname = get_string('sectionname', 'format_'.$course->format);
21 $strname = get_string("name");
22 $strstatus = get_string("status");
23 $strdone = get_string("done", "survey");
24 $strnotdone = get_string("notdone", "survey");
26 $PAGE->navbar->add($strsurveys);
27 $PAGE->set_title($strsurveys);
28 $PAGE->set_heading($course->fullname);
29 echo $OUTPUT->header();
31 if (! $surveys = get_all_instances_in_course("survey", $course)) {
32 notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
35 $usesections = course_format_uses_sections($course->format);
36 if ($usesections) {
37 $sections = get_all_sections($course->id);
40 $table = new html_table();
41 $table->width = '100%';
43 if ($usesections) {
44 $table->head = array ($strsectionname, $strname, $strstatus);
45 } else {
46 $table->head = array ($strname, $strstatus);
49 $currentsection = '';
51 foreach ($surveys as $survey) {
52 if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
53 $ss = $strdone;
54 } else {
55 $ss = $strnotdone;
57 $printsection = "";
58 if ($usesections) {
59 if ($survey->section !== $currentsection) {
60 if ($survey->section) {
61 $printsection = get_section_name($course, $sections[$survey->section]);
63 if ($currentsection !== "") {
64 $table->data[] = 'hr';
66 $currentsection = $survey->section;
69 //Calculate the href
70 if (!$survey->visible) {
71 //Show dimmed if the mod is hidden
72 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
73 } else {
74 //Show normal if the mod is visible
75 $tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
78 if ($usesections) {
79 $table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
80 } else {
81 $table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
85 echo "<br />";
86 echo html_writer::table($table);
87 echo $OUTPUT->footer();