From: martin Date: Sun, 4 Aug 2002 16:19:37 +0000 (+0000) Subject: New assignment module finally complete! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d699cd1e5475f692d61282760b686eef462c97bc;p=moodle.git New assignment module finally complete! --- diff --git a/lang/en/assignment.php b/lang/en/assignment.php index 9745b20d31..bc2bfa9b9a 100644 --- a/lang/en/assignment.php +++ b/lang/en/assignment.php @@ -6,5 +6,18 @@ $string[modulenameplural] = "Assignments"; #------------------------------------------------------------ +$string[assignmentdetails] = "Assignment details"; +$string[duedate] = "Assignment due"; +$string[early] = "\$a early"; +$string[late] = "\$a late"; +$string[notsubmittedyet] = "Not submitted yet"; +$string[overwritewarning] = "Warning: uploading again will REPLACE your current submission"; +$string[submissionfeedback] = "Submission feedback"; +$string[submissions] = "Submissions"; +$string[failedupdatefeedback] = "Failed to update submission feedback for user \$a"; +$string[feedbackupdated] = "Submissions feedback updated for \$a people"; +$string[viewsubmissions] = "View \$a submitted assignments"; +$string[yoursubmission] = "Your submission"; + ?> diff --git a/lang/en/moodle.php b/lang/en/moodle.php index ec942b167a..2c1e62f44b 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -40,6 +40,7 @@ $string[deletecourse] = "Delete a course"; $string[deleted] = "Deleted"; $string[deletedcourse] = "\$a has been completely deleted"; $string[deletingcourse] = "Deleting \$a"; +$string[description] = "Description"; $string[edit] = "Edit \$a"; $string[editcoursesettings] = "Edit course settings"; $string[editmyprofile] = "Edit my profile"; @@ -84,6 +85,7 @@ $string[format] = "Format"; $string[fulllistofcourses] = "Full list of courses"; $string[fullprofile] = "Full profile"; $string[fullname] = "Full name"; +$string[grade] = "Grade"; $string[guestsno] = "No, do not allow guests in"; $string[guestsyes] = "Yes, allow 'guest' student in"; $string[helppicture] = "How to upload a picture"; @@ -96,6 +98,7 @@ $string[idnumber] = "ID number"; $string[invalidlogin] = "Invalid login, please try again"; $string[invalidemail] = "Invalid email address"; $string[lastaccess] = "Last access"; +$string[lastmodified] = "Last modified"; $string[lastname] = "Last name"; $string[location] = "Location"; $string[loggedinas] = "You are logged in as \$a."; @@ -127,6 +130,7 @@ $string[loginsteps] = "Hi! For full access to courses you'll need to take $string[logout] = "Logout"; $string[mainmenu] = "Main menu"; $string[maximumchars] = "Maximum of \$a characters"; +$string[maximumgrade] = "Maximum grade"; $string[missingcategory] = "You need to choose a category"; $string[missingcity] = "Missing city/town"; $string[missingcountry] = "Missing country"; @@ -172,8 +176,12 @@ $string[newsitem] = "news item"; $string[newsitems] = "news items"; $string[newsitemsnumber] = "News items to show"; $string[no] = "No"; +$string[nograde] = "No grade"; +$string[nostudentsyet] = "No students enrolled in this course yet"; +$string[noteachersyet] = "No teachers in this course yet"; $string[nosuchemail] = "No such email address"; $string[notenrolled] = "\$a is not enrolled in this course."; +$string[now] = "now"; $string[numberweeks] = "Number of weeks/topics"; $string[ok] = "OK"; $string[opentoguests] = "Open to guests?"; @@ -220,6 +228,8 @@ $string[unenrolme] = "Unenrol me from \$a"; $string[update] = "Update"; $string[updatemyprofile] = "Update my profile"; $string[updatethiscourse] = "Update this course"; +$string[upload] = "Upload"; +$string[uploadthisfile] = "Upload this file"; $string[userdescription] = "Description"; $string[username] = "Username"; $string[usernameexists] = "This username already exists, choose another"; diff --git a/mod/assignment/README b/mod/assignment/README deleted file mode 100644 index 0e47ab9707..0000000000 --- a/mod/assignment/README +++ /dev/null @@ -1,6 +0,0 @@ -Describes the assignment (eg an essay) that needs to be completed -then collects and datestamps it. Later, shows the grade. - -Teacher view, show class list, allows download and grades. - - diff --git a/mod/assignment/db/mysql.sql b/mod/assignment/db/mysql.sql index e69de29bb2..cd9e2c818d 100644 --- a/mod/assignment/db/mysql.sql +++ b/mod/assignment/db/mysql.sql @@ -0,0 +1,45 @@ +# +# Table structure for table `assignment` +# + +CREATE TABLE `assignment` ( + `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `name` varchar(255) NOT NULL default '', + `description` text NOT NULL, + `type` int(10) unsigned NOT NULL default '1', + `maxbytes` int(10) unsigned NOT NULL default '100000', + `timedue` int(10) unsigned NOT NULL default '0', + `grade` int(10) NOT NULL default '0', + `timemodified` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id`) +) COMMENT='Defines assignments'; +# -------------------------------------------------------- + +# +# Table structure for table `assignment_submissions` +# + +CREATE TABLE `assignment_submissions` ( + `id` int(10) unsigned NOT NULL default '0', + `assignment` int(10) unsigned NOT NULL default '0', + `user` int(10) unsigned NOT NULL default '0', + `timecreated` int(10) unsigned NOT NULL default '0', + `timemodified` int(10) unsigned NOT NULL default '0', + `numfiles` int(10) unsigned NOT NULL default '0', + `grade` int(11) NOT NULL default '0', + `comment` text NOT NULL, + `teacher` int(10) unsigned NOT NULL default '0', + `timemarked` int(10) unsigned NOT NULL default '0', + `mailed` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`id`) +) COMMENT='Info about submitted assignments'; +# -------------------------------------------------------- + + +INSERT INTO log_display VALUES ('assignment', 'view', 'assignment', 'name'); +INSERT INTO log_display VALUES ('assignment', 'add', 'assignment', 'name'); +INSERT INTO log_display VALUES ('assignment', 'update', 'assignment', 'name'); +INSERT INTO log_display VALUES ('assignment', 'view submissions', 'assignment', 'name'); +INSERT INTO log_display VALUES ('assignment', 'upload', 'assignment', 'name'); + diff --git a/mod/assignment/icon.gif b/mod/assignment/icon.gif new file mode 100755 index 0000000000..fa433fae37 Binary files /dev/null and b/mod/assignment/icon.gif differ diff --git a/mod/assignment/index.php b/mod/assignment/index.php new file mode 100644 index 0000000000..ad036ea3fb --- /dev/null +++ b/mod/assignment/index.php @@ -0,0 +1,67 @@ +id); + add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", ""); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strassignments = get_string("modulenameplural", "assignment"); + $strassignment = get_string("modulename", "assignment"); + + print_header("$course->shortname: $strassignments", "$course->fullname", "$navigation $strassignments", ""); + + if (! $assignments = get_all_instances_in_course("assignment", $course->id, "cw.section ASC")) { + notice("There are no assignments", "../../course/view.php?id=$course->id"); + die; + } + + $timenow = time(); + + if ($course->format == "weeks") { + $table->head = array ("Week", "Name", "Due", "Submitted"); + $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT"); + } else if ($course->format == "topics") { + $table->head = array ("Topic", "Name", "Due", "Submitted"); + $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT"); + } else { + $table->head = array ("Name", "Due", "Submitted"); + $table->align = array ("LEFT", "LEFT", "LEFT"); + } + + foreach ($assignments as $assignment) { + if ($submission = assignment_get_submission($assignment->id, $USER->id)) { + if ($submission->timemodified <= $assignment->timedue) { + $submitted = userdate($submission->timemodified); + } else { + $submitted = "".userdate($submission->timemodified).""; + } + } else { + $submitted = get_string("no"); + } + $due = userdate($assignment->timedue); + $link = "coursemodule\">$assignment->name"; + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($assignment->section, $link, $due, $submitted); + } else { + $table->data[] = array ($link, $due, $submitted); + } + } + + echo "
"; + + print_table($table); + + print_footer($course); +?> diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 6a8c9958c7..e5e23c9f27 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1,5 +1,9 @@ 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 @@ -7,6 +11,9 @@ function assignment_add_instance($assignment) { // 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); } @@ -18,6 +25,8 @@ function assignment_update_instance($assignment) { // 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); @@ -46,5 +55,248 @@ function assignment_delete_instance($id) { return $result; } +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; + + $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; + } + + 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_file_area_name($assignment, $user) { +// Creates a directory file name, suitable for make_upload_directory() + return "$assignment->course/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 get_records("assignment_submissions", "assignment", $assignment->id, "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 ""; + + 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 "
"; +} + + +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); + echo "wwwroot/files/pix/$icon\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"File\">"; + echo " wwwroot/file.php/$filearea/$file\">$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 "
"; +} ?> diff --git a/mod/assignment/mod.html b/mod/assignment/mod.html index d24841bc05..e225e96415 100644 --- a/mod/assignment/mod.html +++ b/mod/assignment/mod.html @@ -12,12 +12,47 @@ + +

Assignment Type:

+ + + Upload a single file, worth between 0 - 100 marks + + + +

Maximum grade:

+ + =0; $i--) { + $grades[$i] = $i; + } + choose_from_menu($grades, "grade", "$form->grade"); + ?> + + + +

Maximum size:

+ + maxbytes) { + $form->maxbytes = 500000; + } + choose_from_menu($filesize, "maxbytes", "$form->maxbytes"); + ?> + +

Due date: dueday, $form->duemonth, $form->dueyear); - echo "-"; - print_time_selector("duehour", "dueminute", $form->duehour, $form->dueminute); + print_date_selector("dueday", "duemonth", "dueyear", $form->timedue); + echo " - "; + print_time_selector("duehour", "dueminute", $form->timedue); formerr($err["duedate"]); ?> diff --git a/mod/assignment/submissions.php b/mod/assignment/submissions.php new file mode 100644 index 0000000000..cb780c151f --- /dev/null +++ b/mod/assignment/submissions.php @@ -0,0 +1,122 @@ +course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + require_login($course->id); + + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strassignments = get_string("modulenameplural", "assignment"); + $strassignment = get_string("modulename", "assignment"); + $strsubmissions = get_string("submissions", "assignment"); + + print_header("$course->shortname: $assignment->name", "$course->fullname", + "$navigation id>$strassignments -> + id\">$assignment->name -> $strsubmissions", + "", "", true, update_module_icon($cm->id, $course->id)); + + // Some easy ways to reference submissions + if ($submissions = assignment_get_all_submissions($assignment)) { + foreach ($submissions as $submission) { + $submissionbyuser[$submission->user] = $submission; + $submissionbyid[$submission->id] = $submission; + } + } + + if (match_referer() && isset($HTTP_POST_VARS)) { // Feedback submitted + + $feedback = array(); + + // Peel out all the data from variable names. + foreach ($HTTP_POST_VARS as $key => $val) { + if ($key <> "id") { + $type = substr($key,0,1); + $num = substr($key,1); + $feedback[$num][$type] = $val; + } + } + + $timenow = time(); + $count = 0; + foreach ($feedback as $num => $vals) { + $submission = $submissionbyid[$num]; + // Only update entries where feedback has actually changed. + if (($vals[g] <> $submission->grade) || ($vals[c] <> addslashes($submission->comment))) { + $newsubmission->grade = $vals[g]; + $newsubmission->comment = $vals[c]; + $newsubmission->teacher = $USER->id; + $newsubmission->timemarked = $timenow; + $newsubmission->mailed = 0; // Make sure mail goes out (again, even) + $newsubmission->id = $num; + if (! update_record("assignment_submissions", $newsubmission)) { + notify(get_string("failedupdatefeedback", "assignment", $submission->user)); + } else { + $count++; + } + $submissionbyuser[$submission->user]->grade = $vals[g]; + $submissionbyuser[$submission->user]->comment = $vals[c]; + $submissionbyuser[$submission->user]->teacher = $USER->id; + $submissionbyuser[$submission->user]->timemarked = $timenow; + } + } + add_to_log($course->id, "assignment", "update grades", "submissions.php?id=$assignment->id", "$count users"); + notify(get_string("feedbackupdated", "assignment", $count)); + } else { + add_to_log($course->id, "assignment", "view submissions", "submissions.php?id=$assignment->id", "$assignment->id"); + } + + for ($i=$assignment->grade; $i>=0; $i--) { + $grades[$i] = $i; + } + + $teachers = get_course_teachers($course->id); + if (! $users = get_course_students($course->id)) { + print_heading(get_string("nostudentsyet")); + + } else { + echo "

\n"; + + if ($usersdone = assignment_get_users_done($assignment)) { + foreach ($usersdone as $user) { + $submission = $submissionbyuser[$user->id]; + assignment_print_submission($assignment, $user, $submission, $teachers, $grades); + } + } + + $submission = NULL; + foreach ($users as $user) { + if (! $usersdone[$user->id]) { + assignment_print_submission($assignment, $user, $submission, $teachers, $grades); + } + } + echo "
"; + echo "id\">"; + echo ""; + echo "
"; + echo "
"; + } + + print_footer($course); + +?> + diff --git a/mod/assignment/upload.php b/mod/assignment/upload.php new file mode 100644 index 0000000000..e1e7a41c3e --- /dev/null +++ b/mod/assignment/upload.php @@ -0,0 +1,86 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + add_to_log($course->id, "assignment", "upload", "view.php?a=$assignment->id", "$assignment->id"); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + $strassignments = get_string("modulenameplural", "assignment"); + $strassignment = get_string("modulename", "assignment"); + $strupload = get_string("upload"); + + print_header("$course->shortname: $assignment->name : $strupload", "$course->fullname", + "$navigation id>$strassignments -> + id\">$assignment->name -> $strupload", + "", "", true); + + if ($submission = assignment_get_submission($assignment, $USER)) { + if ($submission->grade) { + error("You've already been graded - there's no point in uploading anything"); + } + } + + if (! $dir = assignment_file_area($assignment, $USER)) { + error("Sorry, an error in the system prevents you from uploading files: contact your teacher or system administrator"); + } + + if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) { + if ($newfile['size'] > $assignment->maxbytes) { + notify("Sorry, but that file is too big (limit is $assignment->maxbytes bytes)"); + } else { + $newfile_name = clean_filename($newfile['name']); + if ($newfile_name) { + if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) { + assignment_delete_user_files($assignment, $USER, $newfile_name); + if ($submission) { + $submission->timemodified = time(); + if (update_record("assignment_submissions", $submission)) { + print_heading("Uploaded '$newfile_name' successfully."); + } else { + notify("File was uploaded OK but could not update your submission!"); + } + } else { + $submission->assignment = $assignment->id; + $submission->user = $USER->id; + $submission->timecreated = time(); + $submission->timemodified = time(); + $submission->numfiles = 1; + if (insert_record("assignment_submissions", $submission)) { + print_heading("Uploaded '$newfile_name' successfully."); + } else { + notify("'$newfile_name' was uploaded OK but submission did not register!"); + } + } + } else { + notify("An error happened while saving the file on the server"); + } + } else { + notify("This file had a wierd filename and couldn't be uploaded"); + } + } + } else { + notify("No file was found - are you sure you selected one?"); + } + + print_continue("view.php?a=$assignment->id"); + + print_footer($course); + +?> diff --git a/mod/assignment/version.php b/mod/assignment/version.php index 31d8d73e86..0b32fcc31d 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,13 +5,54 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 20020801; +$module->version = 2002080500; $module->cron = 60; function assignment_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality + if ($oldversion < 2002080500) { + + execute_sql(" + CREATE TABLE `assignment` ( + `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `name` varchar(255) NOT NULL default '', + `description` text NOT NULL, + `type` int(10) unsigned NOT NULL default '1', + `maxbytes` int(10) unsigned NOT NULL default '100000', + `timedue` int(10) unsigned NOT NULL default '0', + `grade` int(10) NOT NULL default '0', + `timemodified` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id`) + ) COMMENT='Defines assignments' + "); + + execute_sql(" + CREATE TABLE `assignment_submissions` ( + `id` int(10) unsigned NOT NULL default '0', + `assignment` int(10) unsigned NOT NULL default '0', + `user` int(10) unsigned NOT NULL default '0', + `timecreated` int(10) unsigned NOT NULL default '0', + `timemodified` int(10) unsigned NOT NULL default '0', + `numfiles` int(10) unsigned NOT NULL default '0', + `grade` int(11) NOT NULL default '0', + `comment` text NOT NULL, + `teacher` int(10) unsigned NOT NULL default '0', + `timemarked` int(10) unsigned NOT NULL default '0', + `mailed` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`id`) + ) COMMENT='Info about submitted assignments' + "); + + execute_sql(" INSERT INTO log_display VALUES ('assignment', 'view', 'assignment', 'name') "); + execute_sql(" INSERT INTO log_display VALUES ('assignment', 'add', 'assignment', 'name') "); + execute_sql(" INSERT INTO log_display VALUES ('assignment', 'update', 'assignment', 'name') "); + execute_sql(" INSERT INTO log_display VALUES ('assignment', 'view submissions', 'assignment', 'name') "); + execute_sql(" INSERT INTO log_display VALUES ('assignment', 'upload', 'assignment', 'name') "); + + } return true; } diff --git a/mod/assignment/view.php b/mod/assignment/view.php new file mode 100644 index 0000000000..7d43fbf955 --- /dev/null +++ b/mod/assignment/view.php @@ -0,0 +1,100 @@ +course)) { + error("Course is misconfigured"); + } + + if (! $assignment = get_record("assignment", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + } else { + if (! $assignment = get_record("assignment", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $assignment->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id); + + add_to_log($course->id, "assignment", "view", "view.php?id=$cm->id", "$assignment->id"); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strassignments = get_string("modulenameplural", "assignment"); + $strassignment = get_string("modulename", "assignment"); + + print_header("$course->shortname: $assignment->name", "$course->fullname", + "$navigation id>$strassignments -> $assignment->name", + "", "", true, update_module_icon($cm->id, $course->id)); + + if (isteacher($course->id)) { + if ($submissions = assignment_get_all_submissions($assignment)) { + $count = count($submissions); + } else { + $count = 0; + } + echo "

id\">". + get_string("viewsubmissions", "assignment", $count)."

"; + } + + $strdifference = format_time($assignment->timedue - time()); + $strduedate = userdate($assignment->timedue)." ($strdifference)"; + + print_simple_box_start("CENTER"); + print_heading(get_string("assignmentdetails", "assignment").":", "CENTER"); + print_simple_box_start("CENTER"); + echo "".get_string("duedate", "assignment").": $strduedate
"; + echo "".get_string("maximumgrade").": $assignment->grade
"; + print_simple_box_end(); + echo "
"; + echo text_to_html($assignment->description); + print_simple_box_end(); + echo "
"; + + if (!isteacher($course->id)) { + if ($submission = assignment_get_submission($assignment, $USER)) { + print_simple_box_start("center"); + echo "
"; + print_heading(get_string("yoursubmission","assignment").":", "CENTER"); + echo "

".get_string("lastmodified").": ".userdate($submission->timemodified)."

"; + assignment_print_user_files($assignment, $USER); + print_simple_box_end(); + } else { + print_heading(get_string("notsubmittedyet","assignment")); + } + + echo "
"; + + if ($submission->grade) { + print_heading(get_string("submissionfeedback", "assignment").":", "CENTER"); + assignment_print_feedback($course, $submission); + } else { + if ($submission) { + echo "

".get_string("overwritewarning", "assignment")."

"; + } + assignment_print_upload_form($assignment); + } + } + + print_footer($course); + +?>