adding some strings
[moodle-linuxchix.git] / mod / hotpot / report / overview / report.php
blob365f7b1558a5e7effebd65ece1bd308664843a22
1 <?php // $Id$
2 /// Overview report just displays a big table of all the attempts
3 class hotpot_report extends hotpot_default_report {
5 function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
6 $tables = array();
7 $this->create_overview_table($hotpot, $cm, $course, $users, $attempts, $questions, $options, $tables);
8 $this->print_report($course, $hotpot, $tables, $options);
9 return true;
11 function create_overview_table(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {
12 global $CFG;
13 $strtimeformat = get_string('strftimedatetime');
14 $is_html = ($options['reportformat']=='htm');
15 $spacer = $is_html ? '&nbsp;' : ' ';
16 $br = $is_html ? "<br />\n" : "\n";
17 // initialize $table
18 unset($table);
19 $table->border = 1;
20 $table->width = 10;
21 $table->head = array();
22 $table->align = array();
23 $table->size = array();
24 $table->wrap = array();
25 // picture column, if required
26 if ($is_html) {
27 $table->head[] = $spacer;
28 $table->align[] = 'center';
29 $table->size[] = 10;
30 $table->wrap[] = "nowrap";
32 array_push($table->head,
33 get_string("name"),
34 hotpot_grade_heading($hotpot, $options),
35 get_string("attempt", "quiz"),
36 get_string("time", "quiz"),
37 get_string("reportstatus", "hotpot"),
38 get_string("timetaken", "quiz"),
39 get_string("score", "quiz")
41 array_push($table->align, "left", "center", "center", "left", "center", "center", "center");
42 array_push($table->wrap, "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
43 array_push($table->size, "*", "*", "*", "*", "*", "*", "*");
44 $abandoned = 0;
45 foreach ($users as $user) {
46 // shortcut to user info held in first attempt record
47 $u = &$user->attempts[0];
48 $picture = '';
49 $name = fullname($u);
50 if ($is_html) {
51 $picture = print_user_picture($u->userid, $course->id, $u->picture, false, true);
52 $name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&course='.$course->id.'">'.$name.'</a>';
54 $grade = isset($user->grade) && $user->grade<>'&nbsp;' ? $user->grade : $spacer;
55 $attemptcount = count($user->attempts);
56 if ($attemptcount>1) {
57 $text = $name;
58 $name = NULL;
59 $name->text = $text;
60 $name->rowspan = $attemptcount;
61 $text = $grade;
62 $grade = NULL;
63 $grade->text = $text;
64 $grade->rowspan = $attemptcount;
66 $data = array();
67 if ($is_html) {
68 if ($attemptcount>1) {
69 $text = $picture;
70 $picture = NULL;
71 $picture->text = $text;
72 $picture->rowspan = $attemptcount;
74 $data[] = $picture;
76 array_push($data, $name, $grade);
77 foreach ($user->attempts as $attempt) {
78 // increment count of abandoned attempts
79 // if attempt is marked as finished but has no score
80 if ($attempt->status==HOTPOT_STATUS_ABANDONED) {
81 $abandoned++;
83 $attemptnumber = $attempt->attempt;
84 $starttime = trim(userdate($attempt->timestart, $strtimeformat));
85 if ($is_html && isset($attempt->score) && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review)) {
86 $attemptnumber = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$attemptnumber.'</a>';
87 $starttime = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$starttime.'</a>';
89 if ($is_html && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id))) {
90 $checkbox = '<input type=checkbox name="box'.$attempt->clickreportid.'" value="'.$attempt->clickreportid.'">'.$spacer;
91 } else {
92 $checkbox = '';
94 $timetaken = empty($attempt->timefinish) ? $spacer : format_time($attempt->timefinish - $attempt->timestart);
95 $score = hotpot_format_score($attempt);
96 if ($is_html && is_numeric($score) && $score==$user->grade) { // best grade
97 $score = '<span class="highlight">'.$score.'</span>';
99 array_push($data,
100 $attemptnumber,
101 $checkbox.$starttime,
102 hotpot_format_status($attempt),
103 $timetaken,
104 $score
106 $table->data[] = $data;
107 $data = array();
108 } // end foreach $attempt
109 $table->data[] = 'hr';
110 } // end foreach $user
111 // remove final 'hr' from data rows
112 array_pop($table->data);
113 // add the "delete" form to the table
114 if ($options['reportformat']=='htm' && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id))) {
115 $strdeletecheck = get_string('deleteattemptcheck','quiz');
116 $table->start = $this->deleteform_javascript();
117 $table->start .= '<form method="post" action="report.php" id="deleteform" onsubmit="'."return deletecheck('".$strdeletecheck."', 'selection')".'">'."\n";
118 $table->start .= '<input type="hidden" name="del" value="selection" />'."\n";
119 $table->start .= '<input type="hidden" name="id" value="'.$cm->id.'">'."\n";
120 $table->finish = '<center>'."\n";
121 $table->finish .= '<input type="submit" value="'.get_string("deleteselected").'" />&nbsp;'."\n";
122 if ($abandoned) {
123 $table->finish .= '<input type=button value="'.get_string('deleteabandoned', 'hotpot').'" onClick="if(deletecheck('."'".addslashes(get_string('deleteabandonedcheck', 'hotpot', $abandoned))."', 'abandoned', true".')) getElementById(\'deleteform\').submit();" />'."\n";
125 $table->finish .= '<input type=button value="'.get_string("deleteall").'" onClick="if(deletecheck('."'".addslashes($strdeletecheck)."', 'all', true".'))getElementById(\'deleteform\').submit();" />'."\n";
126 $table->finish .= '</center>'."\n";
127 $table->finish .= '</form>'."\n";
129 $tables[] = &$table;
131 function deleteform_javascript() {
132 $strselectattempt = addslashes(get_string('selectattempt','hotpot'));
133 return <<<END_OF_JAVASCRIPT
134 <script type="text/javascript">
135 <!--
136 function deletecheck(p, v, x) {
137 var r = false; // result
138 // get length of form elements
139 var f = getElementById('deleteform');
140 var l = f ? f.elements.length : 0;
141 // count selected items, if necessary
142 if (!x) {
143 x = 0;
144 for (var i=0; i<l; i++) {
145 var obj = f.elements[i];
146 if (obj.type && obj.type=='checkbox' && obj.checked) {
147 x++;
151 // confirm deletion
152 var n = navigator;
153 if (x || (n.appName=='Netscape' && parseint(n.appVersion)==2)) {
154 r = confirm(p);
155 if (r) {
156 f.del.value = v;
158 } else {
159 alert('$strselectattempt');
161 return r;
163 //-->
164 </script>
165 END_OF_JAVASCRIPT
167 } // end function
168 } // end class