Fixed up graph pages
[moodle.git] / course / user.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3 require("../config.php");
7468bf01 4 require("lib.php");
f9903ed0 5
6 require_variable($id); // course id
7 require_variable($user); // user id
cbc83a39 8 optional_variable($mode, "graph");
f9903ed0 9
10 if (! $course = get_record("course", "id", $id)) {
11 error("Course id is incorrect.");
12 }
13
14 require_login($course->id);
15
f9903ed0 16 if (! $user = get_record("user", "id", $user)) {
17 error("User ID is incorrect");
18 }
19
5110affb 20 if (!isteacher($course->id) and $user->id != $USER->id ) {
21 error("You are not allowed to look at this page");
22 }
23
24
359b138b 25 add_to_log($course->id, "course", "user report", "user.php?id=$course->id&user=$user->id&mode=$mode", "$user->id");
f9903ed0 26
bbfe835b 27 print_header("$course->shortname: Activity Report", "$course->fullname",
f9903ed0 28 "<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
29 <A HREF=\"../user/index.php?id=$course->id\">Participants</A> ->
30 <A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
bbfe835b 31 Activity Report ($mode)", "");
32 print_heading("$user->firstname $user->lastname");
33
34 echo "<TABLE CELLPADDING=10 ALIGN=CENTER><TR>";
6ee410e3 35 echo "<TD>Reports: </TD>";
cbc83a39 36 if ($mode != "graph") {
37 echo "<TD><A HREF=user.php?id=$course->id&user=$user->id&mode=graph>Graph</A></TD>";
bbfe835b 38 } else {
cbc83a39 39 echo "<TD><U>Graph</U></TD>";
bbfe835b 40 }
41 if ($mode != "outline") {
42 echo "<TD><A HREF=user.php?id=$course->id&user=$user->id&mode=outline>Outline</A></TD>";
43 } else {
56e234f2 44 echo "<TD><U>Outline</U></TD>";
bbfe835b 45 }
46 if ($mode != "complete") {
47 echo "<TD><A HREF=user.php?id=$course->id&user=$user->id&mode=complete>Complete</A></TD>";
48 } else {
56e234f2 49 echo "<TD><U>Complete</U></TD>";
bbfe835b 50 }
51 echo "</TR></TABLE>";
52
f9903ed0 53
7468bf01 54 get_all_mods($course->id, $mods, $modtype);
600149be 55
7468bf01 56 switch ($mode) {
cbc83a39 57 case "graph" :
82f5285f 58 echo "<HR>";
c24d3070 59 echo "<CENTER><IMG SRC=\"loggraph.php?id=$course->id&user=$user->id&type=user.png\">";
7468bf01 60 break;
600149be 61
7468bf01 62 case "outline" :
63 case "complete" :
64 default:
65 $sections = get_all_sections($course->id);
600149be 66
7468bf01 67 for ($i=0; $i<=$course->numsections; $i++) {
68
69 if (isset($sections[$i])) { // should always be true
70
71 $section = $sections[$i];
72
73 if ($section->sequence) {
74 echo "<HR>";
75 echo "<H2>";
76 switch ($course->format) {
77 case "weeks": print_string("week"); break;
78 case "topics": print_string("topic"); break;
79 default: print_string("section"); break;
80 }
81 echo " $i</H2>";
82
83 echo "<UL>";
84
85 if ($mode == "outline") {
86 echo "<TABLE CELLPADDING=4 CELLSPACING=0>";
87 }
88
89 $sectionmods = explode(",", $section->sequence);
90 foreach ($sectionmods as $sectionmod) {
91 $mod = $mods[$sectionmod];
92 $instance = get_record("$mod->modname", "id", "$mod->instance");
359b138b 93 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
94
95 if (file_exists($libfile)) {
96 require_once($libfile);
97
98 switch ($mode) {
99 case "outline":
100 $user_outline = $mod->modname."_user_outline";
101 if (function_exists($user_outline)) {
102 $output = $user_outline($course, $user, $mod, $instance);
103 print_outline_row($mod, $instance, $output);
104 }
105 break;
106 case "complete":
107 $user_complete = $mod->modname."_user_complete";
108 if (function_exists($user_complete)) {
109 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" ".
110 "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
111 echo "<H4>$image $mod->modfullname: ".
112 "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
113 "$instance->name</A></H4>";
114 echo "<UL>";
115 $user_complete($course, $user, $mod, $instance);
116 echo "</UL>";
117 }
118 break;
7468bf01 119 }
120 }
121 }
122
123 if ($mode == "outline") {
124 echo "</TABLE>";
125 print_simple_box_end();
126 }
127 echo "</UL>";
359b138b 128
600149be 129
7468bf01 130 }
600149be 131 }
f9903ed0 132 }
7468bf01 133 break;
f9903ed0 134 }
135
7468bf01 136
f9903ed0 137 print_footer($course);
138
7468bf01 139
359b138b 140function print_outline_row($mod, $instance, $result) {
7468bf01 141 $image = "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
49a6849e 142
359b138b 143 echo "<TR>";
144 echo "<TD VALIGN=top>$image</TD>";
49a6849e 145 echo "<TD VALIGN=top width=300>";
359b138b 146 echo " <A TITLE=\"$mod->modfullname\"";
7468bf01 147 echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name</A></TD>";
148 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
359b138b 149 echo "<TD VALIGN=top BGCOLOR=white>";
150 if (isset($result->info)) {
151 echo "$result->info";
152 } else {
153 echo "<P ALIGN=CENTER>-</P>";
154 }
155 echo "</TD>";
156 echo "<TD>&nbsp;&nbsp;&nbsp;</TD>";
157 if (isset($result->time)) {
158 $timeago = format_time(time() - $result->time);
159 echo "<TD VALIGN=top NOWRAP>".userdate($result->time)." ($timeago ago)</TD>";
160 }
161 echo "</TR>";
7468bf01 162}
163
f9903ed0 164?>
165