3 // This page lists all the instances of hotpot in a particular course
5 require_once("../../config.php");
6 require_once("lib.php");
8 $id = required_param("id"); // course
10 if (! $course = get_record("course", "id", $id)) {
11 error("Course ID is incorrect");
14 require_login($course->id
);
16 add_to_log($course->id
, "hotpot", "view all", "index.php?id=$course->id", "");
20 $strmodulenameplural = get_string("modulenameplural", "hotpot");
21 $strmodulename = get_string("modulename", "hotpot");
23 $title = "$course->shortname: $strmodulenameplural";
24 $heading = "$course->fullname";
25 $navigation = "$strmodulenameplural";
26 if ($course->category
) {
27 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
29 print_header($title, $heading, $navigation, "", "", true, "", navmenu($course));
31 $next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
33 // Get all instances of this module
34 if (! $hotpots = get_all_instances_in_course("hotpot", $course)) {
35 notice("There are no $strmodulenameplural", $next_url);
40 if (isset($_POST['regrade'])) {
42 foreach ($hotpots as $hotpot) {
43 $hotpotids[] = $hotpot->id
;
45 $hotpotids = implode(',', $hotpotids);
47 $select = "hotpot IN ($hotpotids)";
49 $questionids = array();
50 if ($questions = get_records_select("hotpot_questions", $select)) {
51 $questionids = array_keys($questions);
53 $questionids = implode(',', $questionids);
56 hotpot_delete_and_notify(
58 "id IN ($questionids)",
59 get_string('question', 'quiz')
61 hotpot_delete_and_notify(
63 "question IN ($questionids)",
64 get_string('answer', 'quiz')
68 if ($attempts = get_records_select('hotpot_attempts', $select)) {
70 foreach ($attempts as $attempt) {
71 if (isset($attempt->score
)) {
72 hotpot_add_attempt_details($attempt);
73 $attempt->details
= addslashes($attempt->details
);
74 if (! update_record('hotpot_attempts', $attempt)) {
75 error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
80 if ($count%200
== 0) {
88 notify(get_string('added', 'moodle', "$count x ".get_string('attempts', 'quiz')));
90 notify(get_string('regradecomplete', 'quiz'));
93 print '<center><form action="'.$ME.'" method="post">';
94 print '<input type="hidden" name="id" value="'.$course->id
.'">';
95 print '<input type="submit" name="regrade" value="'.get_string('regrade', 'quiz').'">';
96 print '</form></center>'."\n";
99 // Print the list of instances of this module
102 $strupdate = get_string("update");
103 $strusers = get_string("users");
105 // Moodle 1.4+ requires sesskey to be passed in forms
106 if (isset($USER->sesskey
)) {
107 $sesskey = '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
112 // column headings and attributes
113 $table->head
= array();
114 $table->align
= array();
116 switch ($course->format
) {
118 $title = get_string("week");
121 $title = get_string("topic");
128 array_push($table->head
, $title);
129 array_push($table->align
, "center");
131 if (isteacheredit($course->id
)) {
132 array_push($table->head
, $strupdate);
133 array_push($table->align
, "center");
135 array_push($table->head
,
137 get_string("quizcloses", "quiz"),
138 get_string("bestgrade", "quiz"),
139 get_string("attempts", "quiz")
141 array_push($table->align
, "left", "left", "center", "left");
143 $currentsection = "";
144 foreach ($hotpots as $hotpot) {
147 if ($hotpot->section
!== $currentsection) {
148 if ($hotpot->section
) {
149 $printsection = $hotpot->section
;
151 if ($currentsection !== "") {
152 $table->data
[] = 'hr';
154 $currentsection = $hotpot->section
;
157 $class = ($hotpot->visible
) ?
'' : 'class="dimmed" ';
158 $quizname = '<A '.$class.'href="view.php?id='.$hotpot->coursemodule
.'">'.$hotpot->name
.'</A>';
159 $quizclose = userdate($hotpot->timeclose
);
161 $select = isteacher($course->id
) ?
'' : "userid='$USER->id' AND ";
162 $select .= "hotpot='$hotpot->id' AND timefinish>0";
164 $attempttable = "{$CFG->prefix}hotpot_attempts";
166 // get number of attempts. if any
167 if ($attemptcount = count_records_sql("SELECT COUNT(*) FROM $attempttable WHERE $select")) {
169 // report number of attempts (and users)
170 $report = get_string("viewallreports","quiz", $attemptcount);
171 if (isteacher($course->id
)) {
172 $usercount = count_records_sql("SELECT COUNT(DISTINCT userid) FROM $attempttable WHERE $select");
173 $report .= " ($usercount $strusers)";
175 $report = '<a href="report.php?hp='.$hotpot->id
.'">'.$report.'</a>';
178 $bestscore = count_records_sql("SELECT MAX(score) FROM $attempttable WHERE $select");
179 if (is_numeric($bestscore)) {
180 $bestscore .= " / $hotpot->grade";
182 $bestscore = " ";
184 } else { // no attempts
186 $bestscore = " ";
191 if ($course->format
=="weeks" ||
$course->format
=="topics") {
192 array_push($data, $printsection);
195 if (isteacheredit($course->id
)) {
197 . '<form target="_parent" method="get" action="'.$CFG->wwwroot
.'/course/mod.php">'
198 . '<input type="hidden" name="update" value="'.$hotpot->coursemodule
.'" />'
200 . '<input type="submit" value="'.$strupdate.'" />'
203 array_push($data, $update);
205 array_push($data, $quizname, $quizclose, $bestscore, $report);
206 $table->data
[] = $data;
214 print_footer($course);
219 function hotpot_flush($n=0, $time=false) {
221 $ti = strftime("%X",time());
225 echo str_repeat(" ", $n) . $ti . "\n";