moodle/mod/choice/index.php

96 lines
3.0 KiB
PHP
Raw Normal View History

<?php // $Id$
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
2001-11-22 06:23:56 +00:00
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
require_course_login($course);
2001-11-22 06:23:56 +00:00
add_to_log($course->id, "choice", "view all", "index?id=$course->id", "");
2001-11-22 06:23:56 +00:00
2002-08-12 08:28:04 +00:00
$strchoice = get_string("modulename", "choice");
$strchoices = get_string("modulenameplural", "choice");
$crumbs[] = array('name' => $strchoices, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($crumbs);
2002-08-12 08:28:04 +00:00
print_header_simple("$strchoices", "", $navigation, "", "", true, "", navmenu($course));
2001-11-22 06:23:56 +00:00
if (! $choices = get_all_instances_in_course("choice", $course)) {
2001-11-22 06:23:56 +00:00
notice("There are no choices", "../../course/view.php?id=$course->id");
}
if ( !empty($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) {
foreach ($allanswers as $aa) {
$answers[$aa->choiceid] = $aa;
2001-11-22 06:23:56 +00:00
}
} else {
$answers = array () ;
}
$timenow = time();
2002-06-25 16:42:34 +00:00
if ($course->format == "weeks") {
2002-08-12 08:28:04 +00:00
$table->head = array (get_string("week"), get_string("question"), get_string("answer"));
2004-10-22 07:45:58 +00:00
$table->align = array ("center", "left", "left");
2002-06-25 16:42:34 +00:00
} else if ($course->format == "topics") {
2002-08-12 08:28:04 +00:00
$table->head = array (get_string("topic"), get_string("question"), get_string("answer"));
2004-10-22 07:45:58 +00:00
$table->align = array ("center", "left", "left");
2002-06-25 16:42:34 +00:00
} else {
2002-08-12 08:28:04 +00:00
$table->head = array (get_string("question"), get_string("answer"));
2004-10-22 07:45:58 +00:00
$table->align = array ("left", "left");
2002-06-25 16:42:34 +00:00
}
2001-11-22 06:23:56 +00:00
$currentsection = "";
2001-11-22 06:23:56 +00:00
foreach ($choices as $choice) {
if (!empty($answers[$choice->id])) {
$answer = $answers[$choice->id];
} else {
$answer = "";
}
if (!empty($answer->optionid)) {
$aa = format_string(choice_get_option_text($choice, $answer->optionid));
} else {
$aa = "";
}
$printsection = "";
if ($choice->section !== $currentsection) {
if ($choice->section) {
$printsection = $choice->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $choice->section;
2003-01-06 13:55:37 +00:00
}
//Calculate the href
if (!$choice->visible) {
//Show dimmed if the mod is hidden
$tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
} else {
//Show normal if the mod is visible
$tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
}
2002-06-25 16:42:34 +00:00
if ($course->format == "weeks" || $course->format == "topics") {
$table->data[] = array ($printsection, $tt_href, $aa);
2002-06-25 16:42:34 +00:00
} else {
$table->data[] = array ($tt_href, $aa);
2002-06-25 16:42:34 +00:00
}
2001-11-22 06:23:56 +00:00
}
echo "<br />";
2001-11-22 06:23:56 +00:00
print_table($table);
print_footer($course);
?>