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