Following Eloy's suggestion and Martin's clarification, the wizard is going
[moodle.git] / mod / assignment / lib.php
CommitLineData
04eba58f 1<?PHP // $Id$
2
b0e3a925 3require_once("$CFG->dirroot/files/mimetypes.php");
d699cd1e 4
b7b42874 5define("OFFLINE", "0");
6define("UPLOADSINGLE", "1");
7
8$ASSIGNMENT_TYPE = array (OFFLINE => get_string("typeoffline", "assignment"),
9 UPLOADSINGLE => get_string("typeuploadsingle", "assignment") );
d699cd1e 10
4909e176 11if (!isset($CFG->assignment_maxbytes)) {
12 set_config("assignment_maxbytes", 1024000); // Default maximum size for all assignments
13}
14
d699cd1e 15
04eba58f 16function assignment_add_instance($assignment) {
17// Given an object containing all the necessary data,
18// (defined by the form in mod.html) this function
19// will create a new instance and return the id number
20// of the new instance.
21
22 $assignment->timemodified = time();
d699cd1e 23
24 $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday,
25 $assignment->duehour, $assignment->dueminute);
04eba58f 26
27 return insert_record("assignment", $assignment);
28}
29
30
31function assignment_update_instance($assignment) {
32// Given an object containing all the necessary data,
33// (defined by the form in mod.html) this function
34// will update an existing instance with new data.
35
36 $assignment->timemodified = time();
d699cd1e 37 $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday,
38 $assignment->duehour, $assignment->dueminute);
04eba58f 39 $assignment->id = $assignment->instance;
40
41 return update_record("assignment", $assignment);
42}
43
44
45function assignment_delete_instance($id) {
46// Given an ID of an instance of this module,
47// this function will permanently delete the instance
48// and any data that depends on it.
49
50 if (! $assignment = get_record("assignment", "id", "$id")) {
51 return false;
52 }
53
54 $result = true;
55
56 if (! delete_records("assignment_submissions", "assignment", "$assignment->id")) {
57 $result = false;
58 }
59
60 if (! delete_records("assignment", "id", "$assignment->id")) {
61 $result = false;
62 }
63
64 return $result;
65}
66
77db7e4c 67function assignment_user_outline($course, $user, $mod, $assignment) {
68 if ($submission = assignment_get_submission($assignment, $user)) {
98092498 69
70 if ($submission->grade) {
71 $result->info = get_string("grade").": $submission->grade";
77db7e4c 72 }
77db7e4c 73 $result->time = $submission->timemodified;
74 return $result;
75 }
76 return NULL;
77}
78
79function assignment_user_complete($course, $user, $mod, $assignment) {
80 if ($submission = assignment_get_submission($assignment, $user)) {
81 if ($basedir = assignment_file_area($assignment, $user)) {
82 if ($files = get_directory_list($basedir)) {
83 $countfiles = count($files)." ".get_string("uploadedfiles", "assignment");
84 foreach ($files as $file) {
85 $countfiles .= "; $file";
86 }
87 }
88 }
89
90 print_simple_box_start();
0927b54b 91 echo "<p><font size=1>";
77db7e4c 92 echo get_string("lastmodified").": ";
93 echo userdate($submission->timemodified);
94 echo assignment_print_difference($assignment->timedue - $submission->timemodified);
0927b54b 95 echo "</font></p>";
77db7e4c 96
97 assignment_print_user_files($assignment, $user);
98
0927b54b 99 echo "<br />";
77db7e4c 100
0927b54b 101 if (empty($submission->timemarked)) {
102 print_string("notgradedyet", "assignment");
103 } else {
104 assignment_print_feedback($course, $submission);
105 }
77db7e4c 106
107 print_simple_box_end();
108
109 } else {
110 print_string("notsubmittedyet", "assignment");
111 }
112}
113
114
d699cd1e 115function assignment_cron () {
116// Function to be run periodically according to the moodle cron
117// Finds all assignment notifications that have yet to be mailed out, and mails them
118
a16c2180 119 global $CFG, $USER;
d699cd1e 120
121 $cutofftime = time() - $CFG->maxeditingtime;
122
9fa49e22 123 if ($submissions = assignment_get_unmailed_submissions($cutofftime)) {
d699cd1e 124 $timenow = time();
125
126 foreach ($submissions as $submission) {
127
128 echo "Processing assignment submission $submission->id\n";
129
ebc3bd2b 130 if (! $user = get_record("user", "id", "$submission->userid")) {
131 echo "Could not find user $post->userid\n";
d699cd1e 132 continue;
133 }
134
a5a4cd60 135 $USER->lang = $user->lang;
136
d699cd1e 137 if (! $course = get_record("course", "id", "$submission->course")) {
138 echo "Could not find course $submission->course\n";
139 continue;
140 }
141
142 if (! isstudent($course->id, $user->id) and !isteacher($course->id, $user->id)) {
6f2e07e8 143 echo fullname($user)." not an active participant in $course->shortname\n";
b9287b2f 144 continue;
d699cd1e 145 }
146
147 if (! $teacher = get_record("user", "id", "$submission->teacher")) {
148 echo "Could not find teacher $submission->teacher\n";
149 continue;
150 }
151
152 if (! $mod = get_coursemodule_from_instance("assignment", $submission->assignment, $course->id)) {
153 echo "Could not find course module for assignment id $submission->assignment\n";
154 continue;
155 }
156
157 $strassignments = get_string("modulenameplural", "assignment");
158 $strassignment = get_string("modulename", "assignment");
159
ae078a98 160 unset($assignmentinfo);
6f2e07e8 161 $assignmentinfo->teacher = fullname($teacher);
ae078a98 162 $assignmentinfo->assignment = "$submission->name";
163 $assignmentinfo->url = "$CFG->wwwroot/mod/assignment/view.php?id=$mod->id";
164
d699cd1e 165 $postsubject = "$course->shortname: $strassignments: $submission->name";
166 $posttext = "$course->shortname -> $strassignments -> $submission->name\n";
167 $posttext .= "---------------------------------------------------------------------\n";
ae078a98 168 $posttext .= get_string("assignmentmail", "assignment", $assignmentinfo);
d699cd1e 169 $posttext .= "---------------------------------------------------------------------\n";
ae078a98 170
d699cd1e 171 if ($user->mailformat == 1) { // HTML
ae078a98 172 $posthtml = "<p><font face=\"sans-serif\">".
173 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->".
174 "<a href=\"$CFG->wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments</a> ->".
175 "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id=$mod->id\">$submission->name</a></font></p>";
176 $posthtml .= "<hr><font face=\"sans-serif\">";
177 $posthtml .= "<p>".get_string("assignmentmailhtml", "assignment", $assignmentinfo)."</p>";
178 $posthtml .= "</font><hr>";
d699cd1e 179 } else {
ae078a98 180 $posthtml = "";
d699cd1e 181 }
182
183 if (! email_to_user($user, $teacher, $postsubject, $posttext, $posthtml)) {
184 echo "Error: assignment cron: Could not send out mail for id $submission->id to user $user->id ($user->email)\n";
185 }
186 if (! set_field("assignment_submissions", "mailed", "1", "id", "$submission->id")) {
187 echo "Could not update the mailed field for id $submission->id\n";
188 }
189 }
190 }
191
192 return true;
193}
194
1b5910c4 195function assignment_print_recent_activity($course, $isteacher, $timestart) {
3d891989 196 global $CFG;
3446205d 197
198 $content = false;
199 $assignments = NULL;
200
1b5910c4 201 if (!$logs = get_records_select("log", "time > '$timestart' AND ".
202 "course = '$course->id' AND ".
203 "module = 'assignment' AND ".
204 "action = 'upload' ", "time ASC")) {
205 return false;
206 }
207
208 foreach ($logs as $log) {
209 //Create a temp valid module structure (course,id)
210 $tempmod->course = $log->course;
211 $tempmod->id = $log->info;
212 //Obtain the visible property from the instance
213 $modvisible = instance_is_visible($log->module,$tempmod);
214
215 //Only if the mod is visible
216 if ($modvisible) {
217 $assignments[$log->info] = assignment_log_info($log);
218 $assignments[$log->info]->time = $log->time;
219 $assignments[$log->info]->url = $log->url;
3446205d 220 }
221 }
222
223 if ($assignments) {
dcde9f02 224 $strftimerecent = get_string("strftimerecent");
3446205d 225 $content = true;
226 print_headline(get_string("newsubmissions", "assignment").":");
227 foreach ($assignments as $assignment) {
dcde9f02 228 $date = userdate($assignment->time, $strftimerecent);
6f2e07e8 229 echo "<p><font size=1>$date - ".fullname($assignment)."<br />";
1b5910c4 230 echo "\"<a href=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
3446205d 231 echo "$assignment->name";
1b5910c4 232 echo "</a>\"</font></p>";
3446205d 233 }
234 }
235
236 return $content;
237}
d699cd1e 238
d0ac6bc2 239function assignment_grades($assignmentid) {
858deff0 240/// Must return an array of grades, indexed by user, and a max grade.
d0ac6bc2 241
91719320 242
243 if (!$assignment = get_record("assignment", "id", $assignmentid)) {
244 return NULL;
245 }
246
247 $grades = get_records_menu("assignment_submissions", "assignment",
248 $assignment->id, "", "userid,grade");
249
250 if ($assignment->grade >= 0) {
251 $return->grades = $grades;
734bec5d 252 $return->maxgrade = $assignment->grade;
91719320 253
254 } else {
255 $scaleid = - ($assignment->grade);
256 if ($scale = get_record("scale", "id", $scaleid)) {
257 $scalegrades = make_menu_from_list($scale->scale);
f7c225fb 258 if ($grades) {
259 foreach ($grades as $key => $grade) {
260 $grades[$key] = $scalegrades[$grade];
261 }
91719320 262 }
263 }
264 $return->grades = $grades;
265 $return->maxgrade = "";
266 }
267
858deff0 268 return $return;
d0ac6bc2 269}
270
05855091 271function assignment_get_participants($assignmentid) {
272//Returns the users with data in one assignment
273//(users with records in assignment_submissions, students and teachers)
274
275 global $CFG;
276
277 //Get students
278 $students = get_records_sql("SELECT DISTINCT u.*
279 FROM {$CFG->prefix}user u,
280 {$CFG->prefix}assignment_submissions a
281 WHERE a.assignment = '$assignmentid' and
282 u.id = a.userid");
283 //Get teachers
284 $teachers = get_records_sql("SELECT DISTINCT u.*
285 FROM {$CFG->prefix}user u,
286 {$CFG->prefix}assignment_submissions a
287 WHERE a.assignment = '$assignmentid' and
288 u.id = a.teacher");
289
290 //Add teachers to students
291 if ($teachers) {
292 foreach ($teachers as $teacher) {
293 $students[$teacher->id] = $teacher;
294 }
295 }
296 //Return students array (it contains an array of unique users)
297 return ($students);
298}
299
9fa49e22 300/// SQL STATEMENTS //////////////////////////////////////////////////////////////////
301
302function assignment_log_info($log) {
303 global $CFG;
304 return get_record_sql("SELECT a.name, u.firstname, u.lastname
305 FROM {$CFG->prefix}assignment a,
306 {$CFG->prefix}user u
307 WHERE a.id = '$log->info'
ebc3bd2b 308 AND u.id = '$log->userid'");
9fa49e22 309}
310
9fa82712 311function assignment_count_real_submissions($assignment, $groupid=0) {
8ff79e8c 312/// Return all real assignment submissions by ENROLLED students (not empty ones)
313 global $CFG;
314
9fa82712 315 if ($groupid) { /// How many in a particular group?
316 return count_records_sql("SELECT COUNT(*)
317 FROM {$CFG->prefix}assignment_submissions a,
318 {$CFG->prefix}groups_members g
319 WHERE a.assignment = $assignment->id
320 AND a.timemodified > 0
321 AND g.groupid = '$groupid'
322 AND a.userid = g.userid ");
323 } else {
324 return count_records_sql("SELECT COUNT(*)
325 FROM {$CFG->prefix}assignment_submissions a,
326 {$CFG->prefix}user_students s
327 WHERE a.assignment = '$assignment->id'
328 AND a.timemodified > 0
329 AND s.course = '$assignment->course'
330 AND a.userid = s.userid ");
331 }
8ff79e8c 332}
333
df48be74 334function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
8ff79e8c 335/// Return all assignment submissions by ENROLLED students (even empty)
9fa49e22 336 global $CFG;
000cc405 337
338 if ($sort == "lastname" or $sort == "firstname") {
339 $sort = "u.$sort $dir";
340 } else if (empty($sort)) {
341 $sort = "a.timemodified DESC";
342 } else {
343 $sort = "a.$sort $dir";
344 }
9fa49e22 345 return get_records_sql("SELECT a.*
346 FROM {$CFG->prefix}assignment_submissions a,
000cc405 347 {$CFG->prefix}user_students s,
348 {$CFG->prefix}user u
ebc3bd2b 349 WHERE a.userid = s.userid
b2d0ca3b 350 AND u.id = a.userid
9fa49e22 351 AND s.course = '$assignment->course'
352 AND a.assignment = '$assignment->id'
000cc405 353 ORDER BY $sort");
9fa49e22 354}
355
356function assignment_get_users_done($assignment) {
357/// Return list of users who have done an assignment
358 global $CFG;
359 return get_records_sql("SELECT u.*
360 FROM {$CFG->prefix}user u,
361 {$CFG->prefix}user_students s,
362 {$CFG->prefix}assignment_submissions a
363 WHERE s.course = '$assignment->course'
ebc3bd2b 364 AND s.userid = u.id
365 AND u.id = a.userid
9fa49e22 366 AND a.assignment = '$assignment->id'
367 ORDER BY a.timemodified DESC");
368}
369
370function assignment_get_unmailed_submissions($cutofftime) {
a2631c99 371/// Return list of marked submissions that have not been mailed out for currently enrolled students
9fa49e22 372 global $CFG;
373 return get_records_sql("SELECT s.*, a.course, a.name
374 FROM {$CFG->prefix}assignment_submissions s,
a2631c99 375 {$CFG->prefix}assignment a,
376 {$CFG->prefix}user_students us
9fa49e22 377 WHERE s.mailed = 0
378 AND s.timemarked < $cutofftime
379 AND s.timemarked > 0
a2631c99 380 AND s.assignment = a.id
381 AND s.userid = us.userid
382 AND a.course = us.course");
9fa49e22 383}
384
385
d699cd1e 386//////////////////////////////////////////////////////////////////////////////////////
387
388function assignment_file_area_name($assignment, $user) {
389// Creates a directory file name, suitable for make_upload_directory()
ca4f8eb8 390 global $CFG;
391
392 return "$assignment->course/$CFG->moddata/assignment/$assignment->id/$user->id";
d699cd1e 393}
394
395function assignment_file_area($assignment, $user) {
396 return make_upload_directory( assignment_file_area_name($assignment, $user) );
397}
398
399function assignment_get_submission($assignment, $user) {
21a15d9f 400 $submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $user->id);
401 if (!empty($submission->timemodified)) {
402 return $submission;
8e340cb0 403 }
404 return NULL;
d699cd1e 405}
406
407function assignment_print_difference($time) {
408 if ($time < 0) {
409 $timetext = get_string("late", "assignment", format_time($time));
410 return " (<FONT COLOR=RED>$timetext</FONT>)";
411 } else {
412 $timetext = get_string("early", "assignment", format_time($time));
413 return " ($timetext)";
414 }
415}
416
417function assignment_print_submission($assignment, $user, $submission, $teachers, $grades) {
ce78926d 418 global $THEME, $USER;
d699cd1e 419
b7b42874 420 echo "\n<TABLE BORDER=1 CELLSPACING=0 valign=top cellpadding=10 align=center>";
d699cd1e 421
422 echo "\n<TR>";
b7b42874 423 if ($assignment->type == OFFLINE) {
424 echo "\n<TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
425 } else {
426 echo "\n<TD ROWSPAN=2 BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
427 }
d699cd1e 428 print_user_picture($user->id, $assignment->course, $user->picture);
429 echo "</TD>";
6f2e07e8 430 echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">".fullname($user, true);
c4df6e17 431 if ($assignment->type != OFFLINE and $submission->timemodified) {
d699cd1e 432 echo "&nbsp;&nbsp;<FONT SIZE=1>".get_string("lastmodified").": ";
433 echo userdate($submission->timemodified);
434 echo assignment_print_difference($assignment->timedue - $submission->timemodified);
435 echo "</FONT>";
436 }
437 echo "</TR>";
438
b7b42874 439 if ($assignment->type != OFFLINE) {
440 echo "\n<TR><TD BGCOLOR=\"$THEME->cellcontent\">";
ff446576 441 if ($submission->timemodified) {
b7b42874 442 assignment_print_user_files($assignment, $user);
443 } else {
444 print_string("notsubmittedyet", "assignment");
d699cd1e 445 }
d699cd1e 446 echo "</TD></TR>";
447 }
b7b42874 448
449 echo "\n<TR>";
450 echo "<TD WIDTH=35 VALIGN=TOP>";
451 if (!$submission->teacher) {
452 $submission->teacher = $USER->id;
453 }
454 print_user_picture($submission->teacher, $assignment->course, $teachers[$submission->teacher]->picture);
455 if ($submission->timemodified > $submission->timemarked) {
456 echo "<TD BGCOLOR=\"$THEME->cellheading2\">";
457 } else {
458 echo "<TD BGCOLOR=\"$THEME->cellheading\">";
459 }
f830b324 460 echo get_string("feedback", "assignment").":";
94d0cea5 461 choose_from_menu($grades, "g$submission->id", $submission->grade, get_string("nograde"));
b7b42874 462 if ($submission->timemarked) {
463 echo "&nbsp;&nbsp;<FONT SIZE=1>".userdate($submission->timemarked)."</FONT>";
464 }
465 echo "<BR><TEXTAREA NAME=\"c$submission->id\" ROWS=6 COLS=60 WRAP=virtual>";
466 p($submission->comment);
467 echo "</TEXTAREA><BR>";
468 echo "</TD></TR>";
469
d699cd1e 470 echo "</TABLE><BR CLEAR=ALL>\n";
471}
472
473function assignment_print_feedback($course, $submission) {
474 global $CFG, $THEME, $RATING;
475
476 if (! $teacher = get_record("user", "id", $submission->teacher)) {
477 error("Weird assignment error");
478 }
479
b0f01dff 480 echo "\n<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=1 ALIGN=CENTER><TR><TD BGCOLOR=#888888>";
481 echo "\n<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 VALIGN=TOP>";
d699cd1e 482
483 echo "\n<TR>";
484 echo "\n<TD ROWSPAN=3 BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
485 print_user_picture($teacher->id, $course->id, $teacher->picture);
486 echo "</TD>";
6f2e07e8 487 echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">".fullname($teacher);
d699cd1e 488 echo "&nbsp;&nbsp;<FONT SIZE=2><I>".userdate($submission->timemarked)."</I>";
489 echo "</TR>";
490
491 echo "\n<TR><TD WIDTH=100% BGCOLOR=\"$THEME->cellcontent\">";
492
493 echo "<P ALIGN=RIGHT><FONT SIZE=-1><I>";
494 if ($submission->grade) {
495 echo get_string("grade").": $submission->grade";
496 } else {
497 echo get_string("nograde");
498 }
499 echo "</I></FONT></P>";
500
501 echo text_to_html($submission->comment);
502 echo "</TD></TR></TABLE>";
b0f01dff 503 echo "</TD></TR></TABLE>";
d699cd1e 504}
505
506
507function assignment_print_user_files($assignment, $user) {
508// Arguments are objects
509
510 global $CFG;
511
512 $filearea = assignment_file_area_name($assignment, $user);
513
514 if ($basedir = assignment_file_area($assignment, $user)) {
515 if ($files = get_directory_list($basedir)) {
516 foreach ($files as $file) {
517 $icon = mimeinfo("icon", $file);
3f8247c2 518 if ($CFG->slasharguments) {
519 $ffurl = "file.php/$filearea/$file";
520 } else {
521 $ffurl = "file.php?file=/$filearea/$file";
522 }
523
096b5432 524 echo "<img src=\"$CFG->pixpath/f/$icon\" height=16 width=16 border=0 alt=\"file\">";
525 echo "&nbsp;<a target=\"uploadedfile\" href=\"$CFG->wwwroot/$ffurl\">$file</a>";
526 echo "<br />";
d699cd1e 527 }
528 }
529 }
530}
531
532function assignment_delete_user_files($assignment, $user, $exception) {
533// Deletes all the user files in the assignment area for a user
534// EXCEPT for any file named $exception
535
536 if ($basedir = assignment_file_area($assignment, $user)) {
537 if ($files = get_directory_list($basedir)) {
538 foreach ($files as $file) {
539 if ($file != $exception) {
540 unlink("$basedir/$file");
fed7c5ba 541 notify(get_string("existingfiledeleted", "assignment", $file));
d699cd1e 542 }
543 }
544 }
545 }
546}
547
548function assignment_print_upload_form($assignment) {
549// Arguments are objects
550
551 echo "<DIV ALIGN=CENTER>";
552 echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=upload.php>";
ce78926d 553 echo " <INPUT TYPE=hidden NAME=MAX_FILE_SIZE value=\"$assignment->maxbytes\">";
d699cd1e 554 echo " <INPUT TYPE=hidden NAME=id VALUE=\"$assignment->id\">";
555 echo " <INPUT NAME=\"newfile\" TYPE=\"file\" size=\"50\">";
556 echo " <INPUT TYPE=submit NAME=save VALUE=\"".get_string("uploadthisfile")."\">";
557 echo "</FORM>";
558 echo "</DIV>";
559}
04eba58f 560
ffeca120 561function assignment_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $assignment="0", $user="", $groupid="") {
f466c9ed 562// Returns all assignments since a given time. If assignment is specified then
26b90e70 563// this restricts the results
ffeca120 564
26b90e70 565 global $CFG;
566
567 if ($assignment) {
f466c9ed 568 $assignmentselect = " AND cm.id = '$assignment'";
26b90e70 569 } else {
570 $assignmentselect = "";
571 }
572 if ($user) {
573 $userselect = " AND u.id = '$user'";
ffeca120 574 } else {
26b90e70 575 $userselect = "";
576 }
577
f466c9ed 578 $assignments = get_records_sql("SELECT asub.*, u.firstname, u.lastname, u.picture, u.id as userid,
ffeca120 579 a.grade as maxgrade, name, cm.instance, cm.section, a.type
f466c9ed 580 FROM {$CFG->prefix}assignment_submissions asub,
581 {$CFG->prefix}user u,
582 {$CFG->prefix}assignment a,
583 {$CFG->prefix}course_modules cm
584 WHERE asub.timemodified > '$sincetime'
585 AND asub.userid = u.id $userselect
586 AND a.id = asub.assignment $assignmentselect
587 AND cm.course = '$courseid'
588 AND cm.instance = a.id
589 ORDER BY asub.timemodified ASC");
590
ffeca120 591 if (empty($assignments))
592 return;
f466c9ed 593
ffeca120 594 foreach ($assignments as $assignment) {
595 if (empty($groupid) || ismember($groupid, $assignment->userid)) {
596
597 $tmpactivity->type = "assignment";
598 $tmpactivity->defaultindex = $index;
599 $tmpactivity->instance = $assignment->instance;
600 $tmpactivity->name = $assignment->name;
601 $tmpactivity->section = $assignment->section;
26b90e70 602
ffeca120 603 $tmpactivity->content->grade = $assignment->grade;
604 $tmpactivity->content->maxgrade = $assignment->maxgrade;
605 $tmpactivity->content->type = $assignment->type;
26b90e70 606
ffeca120 607 $tmpactivity->user->userid = $assignment->userid;
608 $tmpactivity->user->fullname = fullname($assignment);
609 $tmpactivity->user->picture = $assignment->picture;
26b90e70 610
ffeca120 611 $tmpactivity->timestamp = $assignment->timemodified;
f466c9ed 612
ffeca120 613 $activities[] = $tmpactivity;
f466c9ed 614
ffeca120 615 $index++;
616 }
617 }
f466c9ed 618
ffeca120 619 return;
f466c9ed 620}
621
ffeca120 622function assignment_print_recent_mod_activity($activity, $course, $detail=false) {
26b90e70 623 global $CFG, $THEME;
624
f466c9ed 625 echo '<table border="0" cellpadding="3" cellspacing="0">';
26b90e70 626
f466c9ed 627 echo "<tr><td bgcolor=\"$THEME->cellcontent2\" class=\"forumpostpicture\" width=\"35\" valign=\"top\">";
628 print_user_picture($activity->user->userid, $course, $activity->user->picture);
629 echo "</td><td width=\"100%\"><font size=2>";
26b90e70 630
26b90e70 631
f466c9ed 632 if ($detail) {
633 echo "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
634 "height=16 width=16 alt=\"$activity->type\"> ";
635 echo "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id=" . $activity->instance . "\">"
636 . $activity->name . "</a> - ";
26b90e70 637
f466c9ed 638 }
26b90e70 639
f466c9ed 640 if (isteacher($USER)) {
641 $grades = "(" . $activity->content->grade . " / " . $activity->content->maxgrade . ") ";
26b90e70 642
f466c9ed 643 $assignment->id = $activity->instance;
644 $assignment->course = $course;
645 $user->id = $activity->user->userid;
26b90e70 646
ffeca120 647 echo $grades;
648 if ($activity->content->type == UPLOADSINGLE) {
649 $file = assignment_get_user_file($assignment, $user);
650 echo "<img src=\"$CFG->pixpath/f/$file->icon\" height=16 width=16 border=0 alt=\"file\">";
651 echo "&nbsp;<a target=\"uploadedfile\" HREF=\"$CFG->wwwroot/$file->url\">$file->name</A>";
652 }
653 echo "<br>";
f466c9ed 654 }
655 echo "<a href=\"$CFG->wwwroot/user/view.php?id="
656 . $activity->user->userid . "&course=$course\">"
657 . $activity->user->fullname . "</a> ";
26b90e70 658
f466c9ed 659 echo " - " . userdate($activity->timestamp);
26b90e70 660
f466c9ed 661 echo "</font></td></tr>";
662 echo "</table>";
26b90e70 663
f466c9ed 664 return;
665}
26b90e70 666
f466c9ed 667function assignment_get_user_file($assignment, $user) {
668 global $CFG;
669
670 $tmpfile = "";
671
672 $filearea = assignment_file_area_name($assignment, $user);
673
674 if ($basedir = assignment_file_area($assignment, $user)) {
675 if ($files = get_directory_list($basedir)) {
676 foreach ($files as $file) {
677 $icon = mimeinfo("icon", $file);
678 if ($CFG->slasharguments) {
679 $ffurl = "file.php/$filearea/$file";
680 } else {
681 $ffurl = "file.php?file=/$filearea/$file";
682 }
683 $tmpfile->url = $ffurl;
684 $tmpfile->name = $file;
685 $tmpfile->icon = $icon;
686 }
687 }
26b90e70 688 }
f466c9ed 689 return $tmpfile;
26b90e70 690}
f466c9ed 691
04eba58f 692?>