First step for SCORM2004, new communication subsystem
[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
10     if ($id) {
11         if (! $cm = get_record("course_modules", "id", $id)) {
12             error("Course Module ID was incorrect");
13         }
15         if (! $course = get_record("course", "id", $cm->course)) {
16             error("Course is misconfigured");
17         }
19         if (! $scorm = get_record("scorm", "id", $cm->instance)) {
20             error("Course module is incorrect");
21         }
23     } else {
24         if (! $scorm = get_record("scorm", "id", $q)) {
25             error("Course module is incorrect");
26         }
27         if (! $course = get_record("course", "id", $scorm->course)) {
28             error("Course is misconfigured");
29         }
30         if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
31             error("Course Module ID was incorrect");
32         }
33     }
35     require_login($course->id, false, $cm);
37     if (!isteacher($course->id)) {
38         error("You are not allowed to use this script");
39     }
41     add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id");
43 /// Print the page header
44     if (empty($noheader)) {
46         if ($course->category) {
47             $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
48         } else {
49             $navigation = '';
50         }
52         $strscorms = get_string("modulenameplural", "scorm");
53         $strscorm  = get_string("modulename", "scorm");
54         $strreport  = get_string("report", "scorm");
56         print_header("$course->shortname: $scorm->name", "$course->fullname",
57                      "$navigation <a href=\"index.php?id=$course->id\">$strscorms</a>
58                       -> <a href=\"view.php?id=$cm->id\">$scorm->name</a> -> $strreport",
59                      "", "", true);
61         print_heading($scorm->name);
62     }
63     if ($scoes =get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
64         if ($sco_users=get_records_select("scorm_sco_users", "scormid='$scorm->id' GROUP BY userid")) {
66             $strname  = get_string("name");
68             $table->head = array("&nbsp;", $strname);
69             $table->align = array("center", "left");
70             $table->wrap = array("nowrap", "nowrap");
71             $table->width = "100%";
72             $table->size = array(10, "*");
73             foreach ($scoes as $sco) {
74                 if ($sco->launch!="") {
75                     $table->head[]=scorm_string_round($sco->title);
76                     $table->align[] = "center";
77                     $table->wrap[] = "nowrap";
78                     $table->size[] = "*";
79                 }
80             }
82             foreach ($sco_users as $sco_user) {
83                 $user_data = scorm_get_scoes_records($sco_user);
85                 $row = array();
86                 $data = current($user_data);
87                 $row[] = print_user_picture($sco_user->userid, $course->id, $data->picture, false, true);
88                 $row[] = "<a href=\"$CFG->wwwroot/user/view.php?id=$data->userid&course=$course->id\">".
89                          "$data->firstname $data->lastname</a>";
90                 foreach ($user_data as $data) {
91                     $scoreview = "";
92                     if ($data->cmi_core_score_raw > 0)
93                         $scoreview = "<br />".get_string("score","scorm").":&nbsp;".$data->cmi_core_score_raw;
94                     if ( $data->cmi_core_lesson_status == "")
95                         $data->cmi_core_lesson_status = "not attempted";
96                     $row[]="<img src=\"pix/".scorm_remove_spaces($data->cmi_core_lesson_status).".gif\"
97                         alt=\"".get_string(scorm_remove_spaces($data->cmi_core_lesson_status),"scorm")."\"
98                         title=\"".get_string(scorm_remove_spaces($data->cmi_core_lesson_status),"scorm")."\">&nbsp;"
99                         .$data->cmi_core_total_time.$scoreview;
100                 }
101                 $table->data[] = $row;
102             }
104             print_table($table);
106         } else {
107             notice("No users to report");
108         }
109     }
110     if (empty($noheader)) {
111         print_footer($course);
112     }
115 ?>