3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id',PARAM_INT
); // course
8 $PAGE->set_url('/mod/choice/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
, "choice", "view all", "index.php?id=$course->id", "");
19 $strchoice = get_string("modulename", "choice");
20 $strchoices = get_string("modulenameplural", "choice");
21 $strsectionname = get_string('sectionname', 'format_'.$course->format
);
22 $PAGE->set_title($strchoices);
23 $PAGE->set_heading($course->fullname
);
24 $PAGE->navbar
->add($strchoices);
25 echo $OUTPUT->header();
27 if (! $choices = get_all_instances_in_course("choice", $course)) {
28 notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id");
31 $usesections = course_format_uses_sections($course->format
);
33 $sections = get_all_sections($course->id
);
37 FROM {choice} ch, {choice_answers} cha
38 WHERE cha.choiceid = ch.id AND
39 ch.course = ? AND cha.userid = ?";
42 if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id
, $USER->id
))) {
43 foreach ($allanswers as $aa) {
44 $answers[$aa->choiceid
] = $aa;
52 $table = new html_table();
55 $table->head
= array ($strsectionname, get_string("question"), get_string("answer"));
56 $table->align
= array ("center", "left", "left");
58 $table->head
= array (get_string("question"), get_string("answer"));
59 $table->align
= array ("left", "left");
64 foreach ($choices as $choice) {
65 if (!empty($answers[$choice->id
])) {
66 $answer = $answers[$choice->id
];
70 if (!empty($answer->optionid
)) {
71 $aa = format_string(choice_get_option_text($choice, $answer->optionid
));
77 if ($choice->section
!== $currentsection) {
78 if ($choice->section
) {
79 $printsection = get_section_name($course, $sections[$choice->section
]);
81 if ($currentsection !== "") {
82 $table->data
[] = 'hr';
84 $currentsection = $choice->section
;
89 if (!$choice->visible
) {
90 //Show dimmed if the mod is hidden
91 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name
,true)."</a>";
93 //Show normal if the mod is visible
94 $tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name
,true)."</a>";
97 $table->data
[] = array ($printsection, $tt_href, $aa);
99 $table->data
[] = array ($tt_href, $aa);
103 echo html_writer
::table($table);
105 echo $OUTPUT->footer();