mirrored from git://git.moodle.org/moodle.git
/
view.php
108 lines (72 loc) · 3.66 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php // $Id$
require_once("../../config.php");
require_once("lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID
$action = optional_param('action', '', PARAM_ALPHA);
$attemptids = optional_param('attemptid', array(), PARAM_INT); // array of attempt ids for delete action
if (! $cm = get_coursemodule_from_id('choice', $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
require_course_login($course, false, $cm);
if (!$choice = choice_get_choice($cm->instance)) {
error("Course module is incorrect");
}
$strchoice = get_string("modulename", "choice");
$strchoices = get_string("modulenameplural", "choice");
/// Submit any new data if there is any
if ($form = data_submitted()) {
$timenow = time();
if (isteacher($course->id, $USER->id)) {
if ($action == 'delete') { //some responses need to be deleted
choice_delete_responses($attemptids); //delete responses.
redirect("view.php?id=$cm->id");
}
}
if (empty($form->answer)) {
redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
} else {
choice_user_submit_response($form->answer, $choice, $USER->id, $course->id, $cm);
}
redirect("view.php?id=$cm->id");
exit;
}
/// Display the choice and possibly results
add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id);
print_header_simple(format_string($choice->name), "",
"<a href=\"index.php?id=$course->id\">$strchoices</a> -> ".format_string($choice->name), "", "", true,
update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm));
if (isteacher($course->id)) {
choice_show_reportlink($choice, $course->id, $cm->id);
} else if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
}
if ($choice->text) {
print_simple_box(format_text($choice->text, $choice->format), 'center', '70%', '', 5, 'generalbox', 'intro');
}
//if user has already made a selection, and they are not allowed to update it, show their selected answer.
if (isset($USER->id) && ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id))) {
print_simple_box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), "center");
}
/// Print the form
if ($choice->timeopen > time() ) {
print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center");
print_footer($course);
exit;
}
if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) {
// They haven't made their choice yet or updates allowed and choice is open
echo "<form name=\"form\" method=\"post\" action=\"view.php\">";
choice_show_form($choice, $USER, $cm);
echo "</form>";
}
// print the results at the bottom of the screen
if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or
( $choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
( $choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and $choice->timeclose <= time() ) ) {
choice_show_results($choice, $course, $cm);
}
print_footer($course);
?>