dirroot/files/mimetypes.php"); function assignment_add_instance($assignment) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function // will create a new instance and return the id number // of the new instance. $assignment->timemodified = time(); $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday, $assignment->duehour, $assignment->dueminute); return insert_record("assignment", $assignment); } function assignment_update_instance($assignment) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function // will update an existing instance with new data. $assignment->timemodified = time(); $assignment->timedue = make_timestamp($assignment->dueyear, $assignment->duemonth, $assignment->dueday, $assignment->duehour, $assignment->dueminute); $assignment->id = $assignment->instance; return update_record("assignment", $assignment); } function assignment_delete_instance($id) { // Given an ID of an instance of this module, // this function will permanently delete the instance // and any data that depends on it. if (! $assignment = get_record("assignment", "id", "$id")) { return false; } $result = true; if (! delete_records("assignment_submissions", "assignment", "$assignment->id")) { $result = false; } if (! delete_records("assignment", "id", "$assignment->id")) { $result = false; } return $result; } function assignment_user_outline($course, $user, $mod, $assignment) { if ($submission = assignment_get_submission($assignment, $user)) { if ($basedir = assignment_file_area($assignment, $user)) { if ($files = get_directory_list($basedir)) { $countfiles = count($files)." ".get_string("uploadedfiles", "assignment"); foreach ($files as $file) { $countfiles .= "; $file"; } } } $result->info = $countfiles; $result->time = $submission->timemodified; return $result; } return NULL; } function assignment_user_complete($course, $user, $mod, $assignment) { if ($submission = assignment_get_submission($assignment, $user)) { if ($basedir = assignment_file_area($assignment, $user)) { if ($files = get_directory_list($basedir)) { $countfiles = count($files)." ".get_string("uploadedfiles", "assignment"); foreach ($files as $file) { $countfiles .= "; $file"; } } } print_simple_box_start(); echo "

"; echo get_string("lastmodified").": "; echo userdate($submission->timemodified); echo assignment_print_difference($assignment->timedue - $submission->timemodified); echo "

"; assignment_print_user_files($assignment, $user); echo "
"; assignment_print_feedback($course, $submission); print_simple_box_end(); } else { print_string("notsubmittedyet", "assignment"); } } function assignment_cron () { // Function to be run periodically according to the moodle cron // Finds all assignment notifications that have yet to be mailed out, and mails them global $CFG, $USER; $cutofftime = time() - $CFG->maxeditingtime; if ($submissions = get_records_sql("SELECT s.*, a.course, a.name FROM assignment_submissions s, assignment a WHERE s.mailed = '0' AND s.timemarked < '$cutofftime' AND s.timemarked > 0 AND s.assignment = a.id")) { $timenow = time(); foreach ($submissions as $submission) { echo "Processing assignment submission $submission->id\n"; if (! $user = get_record("user", "id", "$submission->user")) { echo "Could not find user $post->user\n"; continue; } $USER->lang = $user->lang; if (! $course = get_record("course", "id", "$submission->course")) { echo "Could not find course $submission->course\n"; continue; } if (! isstudent($course->id, $user->id) and !isteacher($course->id, $user->id)) { continue; // Not an active participant } if (! $teacher = get_record("user", "id", "$submission->teacher")) { echo "Could not find teacher $submission->teacher\n"; continue; } if (! $mod = get_coursemodule_from_instance("assignment", $submission->assignment, $course->id)) { echo "Could not find course module for assignment id $submission->assignment\n"; continue; } $strassignments = get_string("modulenameplural", "assignment"); $strassignment = get_string("modulename", "assignment"); $postsubject = "$course->shortname: $strassignments: $submission->name"; $posttext = "$course->shortname -> $strassignments -> $submission->name\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= "$teacher->firstname $teacher->lastname has posted some feedback on your\n"; $posttext .= "assignment submission for '$submission->name'\n\n"; $posttext .= "You can see it appended to your assignment submission:\n"; $posttext .= " $CFG->wwwroot/mod/assignment/view.php?id=$mod->id\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($user->mailformat == 1) { // HTML $posthtml = "

". "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". "wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments ->". "wwwroot/mod/assignment/view.php?id=$mod->id\">$submission->name

"; $posthtml .= "
"; $posthtml .= "

$teacher->firstname $teacher->lastname has posted some feedback on your"; $posthtml .= " assignment submission for '$submission->name'

"; $posthtml .= "

You can see it wwwroot/mod/assignment/view.php?id=$mod->id\">"; $posthtml .= "appended to your assignment submission.


"; } else { $posthtml = ""; } if (! email_to_user($user, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: assignment cron: Could not send out mail for id $submission->id to user $user->id ($user->email)\n"; } if (! set_field("assignment_submissions", "mailed", "1", "id", "$submission->id")) { echo "Could not update the mailed field for id $submission->id\n"; } } } return true; } function assignment_print_recent_activity(&$logs, $isteacher=false) { global $CFG, $COURSE_TEACHER_COLOR; $content = false; $assignments = NULL; foreach ($logs as $log) { if ($log->module == "assignment" and $log->action == "upload") { $assignments[$log->info] = get_record_sql("SELECT a.name, u.firstname, u.lastname FROM assignment a, user u WHERE a.id = '$log->info' AND u.id = '$log->user'"); $assignments[$log->info]->time = $log->time; $assignments[$log->info]->url = $log->url; } } if ($assignments) { $content = true; print_headline(get_string("newsubmissions", "assignment").":"); foreach ($assignments as $assignment) { $date = userdate($assignment->time, "%e %b, %H:%M"); echo "

$date - $assignment->firstname $assignment->lastname
"; echo "\"wwwroot/mod/assignment/$assignment->url\">"; echo "$assignment->name"; echo "\"

"; } } return $content; } function assignment_grades($assignmentid) { /// Must return an array of grades, indexed by user, and a max grade. $return->grades = get_records_sql_menu("SELECT user,grade FROM assignment_submissions WHERE assignment = '$assignmentid'"); $return->maxgrade = get_field("assignment", "grade", "id", "$assignmentid"); return $return; } ////////////////////////////////////////////////////////////////////////////////////// function assignment_file_area_name($assignment, $user) { // Creates a directory file name, suitable for make_upload_directory() global $CFG; return "$assignment->course/$CFG->moddata/assignment/$assignment->id/$user->id"; } function assignment_file_area($assignment, $user) { return make_upload_directory( assignment_file_area_name($assignment, $user) ); } function assignment_get_submission($assignment, $user) { return get_record_sql("SELECT * from assignment_submissions WHERE assignment = '$assignment->id' AND user = '$user->id'"); } function assignment_get_all_submissions($assignment) { // Return all assignment submissions by ENROLLED students return get_records_sql("SELECT a.* FROM assignment_submissions a, user_students s WHERE a.user = s.user AND s.course = '$assignment->course' AND a.assignment = '$assignment->id' ORDER BY a.timemodified DESC"); } function assignment_get_users_done($assignment) { return get_records_sql("SELECT u.* FROM user u, user_students s, assignment_submissions a WHERE s.course = '$assignment->course' AND s.user = u.id AND u.id = a.user AND a.assignment = '$assignment->id' ORDER BY a.timemodified DESC"); } function assignment_print_difference($time) { if ($time < 0) { $timetext = get_string("late", "assignment", format_time($time)); return " ($timetext)"; } else { $timetext = get_string("early", "assignment", format_time($time)); return " ($timetext)"; } } function assignment_print_submission($assignment, $user, $submission, $teachers, $grades) { global $THEME; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; if ($submission) { echo "\n"; echo ""; } echo "
body\" WIDTH=35 VALIGN=TOP>"; print_user_picture($user->id, $assignment->course, $user->picture); echo "cellheading\">$user->firstname $user->lastname"; if ($submission) { echo "  ".get_string("lastmodified").": "; echo userdate($submission->timemodified); echo assignment_print_difference($assignment->timedue - $submission->timemodified); echo ""; } echo "
cellcontent\">"; if ($submission) { assignment_print_user_files($assignment, $user); } else { print_string("notsubmittedyet", "assignment"); } echo "
"; if (!$submission->teacher) { $submission->teacher = $USER->id; } print_user_picture($submission->teacher, $assignment->course, $teachers[$submission->teacher]->picture); echo "cellheading\">Teacher Feedback:"; choose_from_menu($grades, "g$submission->id", $submission->grade, get_string("grade")."..."); if ($submission->timemarked) { echo "  ".userdate($submission->timemarked).""; } echo "

"; echo "

\n"; } function assignment_print_feedback($course, $submission) { global $CFG, $THEME, $RATING; if (! $teacher = get_record("user", "id", $submission->teacher)) { error("Weird assignment error"); } echo "\n
"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n
body\" WIDTH=35 VALIGN=TOP>"; print_user_picture($teacher->id, $course->id, $teacher->picture); echo "cellheading\">$teacher->firstname $teacher->lastname"; echo "  ".userdate($submission->timemarked).""; echo "
cellcontent\">"; echo "

"; if ($submission->grade) { echo get_string("grade").": $submission->grade"; } else { echo get_string("nograde"); } echo "

"; echo text_to_html($submission->comment); echo "
"; echo "
"; } function assignment_print_user_files($assignment, $user) { // Arguments are objects global $CFG; $filearea = assignment_file_area_name($assignment, $user); if ($basedir = assignment_file_area($assignment, $user)) { if ($files = get_directory_list($basedir)) { foreach ($files as $file) { $icon = mimeinfo("icon", $file); if ($CFG->slasharguments) { $ffurl = "file.php/$filearea/$file"; } else { $ffurl = "file.php?file=/$filearea/$file"; } echo "wwwroot/files/pix/$icon\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"File\">"; echo " wwwroot/$ffurl\">$file"; echo "
"; } } } } function assignment_delete_user_files($assignment, $user, $exception) { // Deletes all the user files in the assignment area for a user // EXCEPT for any file named $exception if ($basedir = assignment_file_area($assignment, $user)) { if ($files = get_directory_list($basedir)) { foreach ($files as $file) { if ($file != $exception) { unlink("$basedir/$file"); notify("Existing file '$file' has been deleted!"); } } } } } function assignment_print_upload_form($assignment) { // Arguments are objects echo "
"; echo "
"; echo " maxfilesize\">"; echo " id\">"; echo " "; echo " "; echo "
"; echo "
"; } ?>