changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / report.php
CommitLineData
d1290cec 1<?php // $Id$
98ca59f6 2
3// This script uses installed report plugins to print quiz reports
4
5 require_once("../../config.php");
6 require_once("lib.php");
7
7b873234 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
98ca59f6 11
7b873234 12 if (!empty($id)) {
98ca59f6 13 if (! $cm = get_record("course_modules", "id", $id)) {
14 error("Course Module ID was incorrect");
15 }
98ca59f6 16 if (! $course = get_record("course", "id", $cm->course)) {
17 error("Course is misconfigured");
18 }
98ca59f6 19 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20 error("Course module is incorrect");
21 }
7b873234 22 } else if (!empty($b)) {
a5463b34 23 if (! $sco = get_record("scorm_scoes", "id", $b)) {
7b873234 24 error("Course module is incorrect");
a5463b34 25 }
26 if (! $scorm = get_record("scorm", "id", $sco->scorm)) {
7b873234 27 error("Scorm activity is incorrect");
98ca59f6 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 }
7b873234 35 } else {
36 error('A required parameter is missing');
98ca59f6 37 }
38
2a0407b7 39 require_login($course->id, false, $cm);
98ca59f6 40
41 if (!isteacher($course->id)) {
42 error("You are not allowed to use this script");
43 }
44
45 add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id");
46
47/// Print the page header
48 if (empty($noheader)) {
98ca59f6 49 if ($course->category) {
50 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
27d394ca 51 } else {
52 $navigation = '';
98ca59f6 53 }
ec81373f 54
98ca59f6 55 $strscorms = get_string("modulenameplural", "scorm");
56 $strscorm = get_string("modulename", "scorm");
57 $strreport = get_string("report", "scorm");
a5463b34 58 $strname = get_string('name');
9633a423 59 if (!empty($id)) {
a5463b34 60 print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname",
ec81373f 61 "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
d858c876 62 -> <a href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."</a> -> $strreport",
98ca59f6 63 "", "", true);
9633a423 64 } else {
a5463b34 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>
9633a423 68 -> <a href=\"report.php?id=$cm->id\">$strreport</a> -> $sco->title",
a5463b34 69 "", "", true);
9633a423 70 }
d858c876 71 print_heading(format_string($scorm->name));
98ca59f6 72 }
a5463b34 73 if (!empty($id)) {
9633a423 74 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
57472983 75 if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) {
9633a423 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 }
3f8eeff2 88 }
ec81373f 89
9633a423 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);
a5463b34 125 } else {
9633a423 126 notice('No users to report');
127 }
5e5b6b7f 128 }
a5463b34 129 } else {
9633a423 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');
5e5b6b7f 163 }
98ca59f6 164 }
165 if (empty($noheader)) {
166 print_footer($course);
167 }
98ca59f6 168?>