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