Added user activity support
[moodle.git] / mod / scorm / report.php
1 <?php  // $Id$
3 // This script uses installed report plugins to print quiz reports
5     require_once("../../config.php");
6     require_once("lib.php");
8     optional_variable($id);    // Course Module ID, or
9     optional_variable($b);     // SCO ID
10     optional_variable($user);  // User ID
12     if ($id) {
13         if (! $cm = get_record("course_modules", "id", $id)) {
14             error("Course Module ID was incorrect");
15         }
16         if (! $course = get_record("course", "id", $cm->course)) {
17             error("Course is misconfigured");
18         }
19         if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20             error("Course module is incorrect");
21         }
22     } else if (isset($b)) {
23         if (! $sco = get_record("scorm_scoes", "id", $b)) {
24             error("Scorm activity is incorrect");
25         }
26         if (! $scorm = get_record("scorm", "id", $sco->scorm)) {
27             error("Course module is incorrect");
28         }
29         if (! $course = get_record("course", "id", $scorm->course)) {
30             error("Course is misconfigured");
31         }
32         if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
33             error("Course Module ID was incorrect");
34         }
35     }
37     require_login($course->id, false, $cm);
39     if (!isteacher($course->id)) {
40         error("You are not allowed to use this script");
41     }
43     add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id");
45 /// Print the page header
46     if (empty($noheader)) {
47         if ($course->category) {
48             $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
49         } else {
50             $navigation = '';
51         }
53         $strscorms = get_string("modulenameplural", "scorm");
54         $strscorm  = get_string("modulename", "scorm");
55         $strreport  = get_string("report", "scorm");
56         $strname  = get_string('name');
57         if (!empty($id)) {
58             print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
59                      "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
60                       -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport",
61                      "", "", true);
62         } else {
63             print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
64                      "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
65                       -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a>
66               -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",
67                      "", "", true);
68         }
69         print_heading(format_string($scorm->name));
70     }
71     if (!empty($id)) {
72         if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
73             if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {
74                 $table->head = array('&nbsp;', $strname);
75                 $table->align = array('center', 'left');
76                 $table->wrap = array('nowrap', 'nowrap');
77                 $table->width = '100%';
78                 $table->size = array(10, '*');
79                 foreach ($scoes as $sco) {
80                     if ($sco->launch!='') {
81                         $table->head[]=scorm_string_round($sco->title);
82                         $table->align[] = 'center';
83                         $table->wrap[] = 'nowrap';
84                         $table->size[] = '*';
85                     }
86                 }
88                 foreach ($scousers as $scouser) {
89                     if ($userdata = scorm_get_user_data($scouser->userid)) {
90                         $row = '';
91                         $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);
92                         $row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">".
93                                  "$userdata->firstname $userdata->lastname</a>";
94                         foreach ($scoes as $sco) {
95                             if ($sco->launch!='') {
96                                 $anchorstart = '';
97                                 $anchorend = '';
98                                 $scoreview = '';
99                                 if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) {
100                                     if ($trackdata->score_raw != '') {
101                                         $scoreview = '<br />'.get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
102                                     }
103                                     if ($trackdata->status == '') {
104                                         $trackdata->status = 'notattempted';
105                                     } else {
106                                         $anchorstart = '<a href="report.php?b='.$sco->id.'&user='.$scouser->userid.'" title="'.
107                                                        get_string('details','scorm').'">';
108                                         $anchorend = '</a>';
109                                     }
110                                 } else {
111                                     $trackdata->status = 'notattempted';
112                                     $trackdata->total_time = '';
113                                 }
114                                 $strstatus = get_string($trackdata->status,'scorm');
115                                 $row[] = $anchorstart.'<img src="pix/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
116                                          $strstatus.'">&nbsp;'.$trackdata->total_time.$scoreview.$anchorend;
117                             }
118                         }
119                         $table->data[] = $row;
120                     }
121                 }
122                 print_table($table);
123             } else {
124                 notice('No users to report');
125             }
126         }
127     } else {
128         if (!empty($user)) {
129             if ($userdata = scorm_get_user_data($user)) {
130                 print_simple_box_start('center');
131                 print_heading(format_string($sco->title));
132                 echo '<div align="center">'."\n";
133                 print_user_picture($user, $course->id, $userdata->picture, false, false);
134                 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&course=$course->id\">".
135                      "$userdata->firstname $userdata->lastname</a><br />";
136                 $scoreview = '';
137                 if ($trackdata = scorm_get_tracks($sco->id,$user)) {
138                     if ($trackdata->score_raw != '') {
139                         $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
140                     }
141                     if ($trackdata->status == '') {
142                         $trackdata->status = 'notattempted';
143                     }
144                 } else {
145                     $trackdata->status = 'notattempted';
146                     $trackdata->total_time = '';
147                 }
148                 $strstatus = get_string($trackdata->status,'scorm');
149                 echo '<img src="pix/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
150                 $strstatus.'">&nbsp;'.$trackdata->total_time.'<br />'.$scoreview.'<br />';
151                 echo '</div>'."\n";
152                 foreach($trackdata as $element => $value) {
153                     if (substr($element,0,3) == 'cmi') {
154                         echo $element.' => '.$value.'<br />';
155                     }
156                 }
157                 print_simple_box_end();
158             }
159         } else {
160             error('Missing script parameter');
161         }
162     }
163     if (empty($noheader)) {
164         print_footer($course);
165     }
166 ?>