moodle/mod/survey/index.php

91 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2001-11-22 06:23:56 +00:00
require_once("../../config.php");
require_once("lib.php");
2001-11-22 06:23:56 +00:00
$id = required_param('id', PARAM_INT); // Course Module ID
2001-11-22 06:23:56 +00:00
$PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
2008-06-01 18:12:24 +00:00
if (!$course = $DB->get_record('course', array('id'=>$id))) {
2008-06-15 09:14:55 +00:00
print_error('invalidcourseid');
2001-11-22 06:23:56 +00:00
}
require_course_login($course);
$PAGE->set_pagelayout('incourse');
add_to_log($course->id, "survey", "view all", "index.php?id=$course->id", "");
2001-11-22 06:23:56 +00:00
2002-08-12 17:54:13 +00:00
$strsurveys = get_string("modulenameplural", "survey");
$strsectionname = get_string('sectionname', 'format_'.$course->format);
2002-08-12 17:54:13 +00:00
$strname = get_string("name");
$strstatus = get_string("status");
$strdone = get_string("done", "survey");
$strnotdone = get_string("notdone", "survey");
$PAGE->navbar->add($strsurveys);
$PAGE->set_title($strsurveys);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
2001-11-22 06:23:56 +00:00
if (! $surveys = get_all_instances_in_course("survey", $course)) {
notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
2001-11-22 06:23:56 +00:00
}
$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}
$table = new html_table();
if ($usesections) {
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('CENTER', 'LEFT', 'LEFT');
2002-06-25 16:42:34 +00:00
} else {
$table->head = array ($strname, $strintro);
$table->align = array ('LEFT', 'LEFT');
2002-06-25 16:42:34 +00:00
}
2001-11-22 06:23:56 +00:00
2004-01-26 12:29:02 +00:00
$currentsection = '';
foreach ($surveys as $survey) {
if (isloggedin() and survey_already_done($survey->id, $USER->id)) {
2002-08-12 17:54:13 +00:00
$ss = $strdone;
2001-11-22 06:23:56 +00:00
} else {
2002-08-12 17:54:13 +00:00
$ss = $strnotdone;
2001-11-22 06:23:56 +00:00
}
2004-01-26 12:29:02 +00:00
$printsection = "";
if ($usesections) {
if ($survey->section !== $currentsection) {
if ($survey->section) {
$printsection = get_section_name($course, $sections[$survey->section]);
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $survey->section;
2004-01-26 12:29:02 +00:00
}
}
//Calculate the href
if (!$survey->visible) {
//Show dimmed if the mod is hidden
$tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
} else {
//Show normal if the mod is visible
$tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
}
if ($usesections) {
$table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
2002-06-25 16:42:34 +00:00
} else {
$table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
2002-06-25 16:42:34 +00:00
}
2001-11-22 06:23:56 +00:00
}
echo "<br />";
echo html_writer::table($table);
echo $OUTPUT->footer();
2001-11-22 06:23:56 +00:00