Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / hotpot / index.php
blob9025e98350a6e21e86e5681ad859a805d71007ea
1 <?PHP // $Id$
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", "");
18 // Print the header
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);
36 die;
39 if (isadmin()) {
40 if (isset($_POST['regrade'])) {
41 $hotpotids = array();
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);
55 if ($questionids) {
56 hotpot_delete_and_notify(
57 'hotpot_questions',
58 "id IN ($questionids)",
59 get_string('question', 'quiz')
61 hotpot_delete_and_notify(
62 'hotpot_responses',
63 "question IN ($questionids)",
64 get_string('answer', 'quiz')
68 if ($attempts = get_records_select('hotpot_attempts', $select)) {
69 $count = 0;
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);
77 $count++;
78 if ($count%10 == 0) {
79 print ".";
80 if ($count%200 == 0) {
81 print "<br>\n";
83 hotpot_flush(300);
87 if ($count) {
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
101 $timenow = time();
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.'" />';
108 } else {
109 $sesskey = '';
112 // column headings and attributes
113 $table->head = array();
114 $table->align = array();
116 switch ($course->format) {
117 case 'weeks' :
118 $title = get_string("week");
119 break;
120 case 'topics' :
121 $title = get_string("topic");
122 break;
123 default :
124 $title = '';
125 break;
127 if ($title) {
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,
136 get_string("name"),
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) {
146 $printsection = "";
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>';
177 // get best score
178 $bestscore = count_records_sql("SELECT MAX(score) FROM $attempttable WHERE $select");
179 if (is_numeric($bestscore)) {
180 $bestscore .= " / $hotpot->grade";
181 } else {
182 $bestscore = "&nbsp;";
184 } else { // no attempts
185 $report = "&nbsp;";
186 $bestscore = "&nbsp;";
189 $data = array ();
191 if ($course->format=="weeks" || $course->format=="topics") {
192 array_push($data, $printsection);
195 if (isteacheredit($course->id)) {
196 $update = ''
197 . '<form target="_parent" method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
198 . '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
199 . $sesskey
200 . '<input type="submit" value="'.$strupdate.'" />'
201 . '</form>'
203 array_push($data, $update);
205 array_push($data, $quizname, $quizclose, $bestscore, $report);
206 $table->data[] = $data;
209 echo "<br />";
211 print_table($table);
213 // Finish the page
214 print_footer($course);
216 ///////////////////
217 // functions
219 function hotpot_flush($n=0, $time=false) {
220 if ($time) {
221 $ti = strftime("%X",time());
222 } else {
223 $ti = "";
225 echo str_repeat(" ", $n) . $ti . "\n";
226 flush();