#------------------------------------------------------------
+$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";
+
?>
$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";
$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";
$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.";
$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";
$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?";
$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";
+++ /dev/null
-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.
-
-
+#
+# 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');
+
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id); // course
+
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID is incorrect");
+ }
+
+ require_login($course->id);
+ add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
+
+ if ($course->category) {
+ $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+
+ $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 = "<FONT COLOR=red>".userdate($submission->timemodified)."</FONT>";
+ }
+ } else {
+ $submitted = get_string("no");
+ }
+ $due = userdate($assignment->timedue);
+ $link = "<A HREF=\"view.php?id=$assignment->coursemodule\">$assignment->name</A>";
+
+ if ($course->format == "weeks" or $course->format == "topics") {
+ $table->data[] = array ($assignment->section, $link, $due, $submitted);
+ } else {
+ $table->data[] = array ($link, $due, $submitted);
+ }
+ }
+
+ echo "<BR>";
+
+ print_table($table);
+
+ print_footer($course);
+?>
<?PHP // $Id$
+include_once("$CFG->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
// 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);
}
// 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);
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 = "<P><FONT FACE=sans-serif>".
+ "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments</A> ->".
+ "<A HREF=\"$CFG->wwwroot/mod/assignment/view.php?id=$mod->id\">$submission->name</A></FONT></P>";
+ $posthtml .= "<HR><FONT FACE=sans-serif>";
+ $posthtml .= "<P>$teacher->firstname $teacher->lastname has posted some feedback on your";
+ $posthtml .= " assignment submission for '<B>$submission->name</B>'</P>";
+ $posthtml .= "<P>You can see it <A HREF=\"$CFG->wwwroot/mod/assignment/view.php?id=$mod->id\">";
+ $posthtml .= "appended to your assignment submission</A>.</P></FONT><HR>";
+ } 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 " (<FONT COLOR=RED>$timetext</FONT>)";
+ } else {
+ $timetext = get_string("early", "assignment", format_time($time));
+ return " ($timetext)";
+ }
+}
+
+function assignment_print_submission($assignment, $user, $submission, $teachers, $grades) {
+ global $THEME;
+
+ echo "\n<TABLE BORDER=1 CELLSPACING=0 valign=top cellpadding=10>";
+
+ echo "\n<TR>";
+ echo "\n<TD ROWSPAN=2 BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
+ print_user_picture($user->id, $assignment->course, $user->picture);
+ echo "</TD>";
+ echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">$user->firstname $user->lastname";
+ if ($submission) {
+ echo " <FONT SIZE=1>".get_string("lastmodified").": ";
+ echo userdate($submission->timemodified);
+ echo assignment_print_difference($assignment->timedue - $submission->timemodified);
+ echo "</FONT>";
+ }
+ echo "</TR>";
+
+ echo "\n<TR><TD WIDTH=100% BGCOLOR=\"$THEME->cellcontent\">";
+ if ($submission) {
+ assignment_print_user_files($assignment, $user);
+ } else {
+ print_string("notsubmittedyet", "assignment");
+ }
+ echo "</TD></TR>";
+
+ if ($submission) {
+ echo "\n<TR>";
+ echo "<TD WIDTH=35 VALIGN=TOP>";
+ if (!$submission->teacher) {
+ $submission->teacher = $USER->id;
+ }
+ print_user_picture($submission->teacher, $assignment->course, $teachers[$submission->teacher]->picture);
+ echo "<TD BGCOLOR=\"$THEME->cellheading\">Teacher Feedback:";
+ choose_from_menu($grades, "g$submission->id", $submission->grade, get_string("grade")."...");
+ if ($submission->timemarked) {
+ echo " <FONT SIZE=1>".userdate($submission->timemarked)."</FONT>";
+ }
+ echo "<BR><TEXTAREA NAME=\"c$submission->id\" ROWS=6 COLS=60 WRAP=virtual>";
+ p($submission->comment);
+ echo "</TEXTAREA><BR>";
+ echo "</TD></TR>";
+ }
+ echo "</TABLE><BR CLEAR=ALL>\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<TABLE BORDER=1 CELLSPACING=0 valign=top cellpadding=10>";
+
+ echo "\n<TR>";
+ echo "\n<TD ROWSPAN=3 BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
+ print_user_picture($teacher->id, $course->id, $teacher->picture);
+ echo "</TD>";
+ echo "<TD NOWRAP WIDTH=100% BGCOLOR=\"$THEME->cellheading\">$teacher->firstname $teacher->lastname";
+ echo " <FONT SIZE=2><I>".userdate($submission->timemarked)."</I>";
+ echo "</TR>";
+
+ echo "\n<TR><TD WIDTH=100% BGCOLOR=\"$THEME->cellcontent\">";
+
+ echo "<P ALIGN=RIGHT><FONT SIZE=-1><I>";
+ if ($submission->grade) {
+ echo get_string("grade").": $submission->grade";
+ } else {
+ echo get_string("nograde");
+ }
+ echo "</I></FONT></P>";
+
+ echo text_to_html($submission->comment);
+ echo "</TD></TR></TABLE>";
+}
+
+
+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 "<IMG SRC=\"$CFG->wwwroot/files/pix/$icon\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"File\">";
+ echo " <A TARGET=\"uploadedfile\" HREF=\"$CFG->wwwroot/file.php/$filearea/$file\">$file</A>";
+ echo "<BR>";
+ }
+ }
+ }
+}
+
+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 "<DIV ALIGN=CENTER>";
+ echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=upload.php>";
+ echo " <INPUT TYPE=hidden NAME=MAX_FILE_SIZE value=\"$assignment->maxfilesize\">";
+ echo " <INPUT TYPE=hidden NAME=id VALUE=\"$assignment->id\">";
+ echo " <INPUT NAME=\"newfile\" TYPE=\"file\" size=\"50\">";
+ echo " <INPUT TYPE=submit NAME=save VALUE=\"".get_string("uploadthisfile")."\">";
+ echo "</FORM>";
+ echo "</DIV>";
+}
?>
<textarea name="description" rows=15 cols=30 wrap="virtual"><? p($form->description) ?></textarea>
</td>
</tr>
+<tr valign=top>
+ <td align=right><P><B>Assignment Type:</B></P></TD>
+ <td>
+ <input type="hidden" name=type value="<? p($form->type) ?>">
+ Upload a single file, worth between 0 - 100 marks
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B>Maximum grade:</B></P></TD>
+ <td>
+ <?
+ for ($i=100; $i>=0; $i--) {
+ $grades[$i] = $i;
+ }
+ choose_from_menu($grades, "grade", "$form->grade");
+ ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><P><B>Maximum size:</B></P></TD>
+ <td>
+ <?
+ $filesize[10000] = "10kb";
+ $filesize[50000] = "50kb";
+ $filesize[100000] = "100kb";
+ $filesize[500000] = "500kb";
+ $filesize[1000000] = "1000Kb (1Mb)";
+ $filesize[2000000] = "2000Kb (2Mb)";
+ if (!$form->maxbytes) {
+ $form->maxbytes = 500000;
+ }
+ choose_from_menu($filesize, "maxbytes", "$form->maxbytes");
+ ?>
+ </td>
+</tr>
<tr valign=top>
<td align=right><P><B>Due date:</B></td>
<td><?
- print_date_selector("dueday", "duemonth", "dueyear", $form->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"]);
?></td>
</tr>
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id); // Assignment
+
+ if (! $assignment = get_record("assignment", "id", $id)) {
+ 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);
+
+ if (!isteacher($course->id)) {
+ error("Only teachers can look at this page");
+ }
+
+
+ if ($course->category) {
+ $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+
+ $strassignments = get_string("modulenameplural", "assignment");
+ $strassignment = get_string("modulename", "assignment");
+ $strsubmissions = get_string("submissions", "assignment");
+
+ print_header("$course->shortname: $assignment->name", "$course->fullname",
+ "$navigation <A HREF=index.php?id=$course->id>$strassignments</A> ->
+ <A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $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 "<FORM ACTION=submissions.php METHOD=post>\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 "<CENTER>";
+ echo "<INPUT TYPE=hidden NAME=id VALUE=\"$assignment->id\">";
+ echo "<INPUT TYPE=submit VALUE=\"Save all my feedback\">";
+ echo "</CENTER>";
+ echo "</FORM>";
+ }
+
+ print_footer($course);
+
+?>
+
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ require_variable($id); // Assignment ID
+
+ $newfile = $HTTP_POST_FILES["newfile"];
+
+ if (! $assignment = get_record("assignment", "id", $id)) {
+ error("Not a valid assignment ID");
+ }
+
+ if (! $course = get_record("course", "id", $assignment->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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+ $strassignments = get_string("modulenameplural", "assignment");
+ $strassignment = get_string("modulename", "assignment");
+ $strupload = get_string("upload");
+
+ print_header("$course->shortname: $assignment->name : $strupload", "$course->fullname",
+ "$navigation <A HREF=index.php?id=$course->id>$strassignments</A> ->
+ <A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $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);
+
+?>
// 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;
}
--- /dev/null
+<?PHP // $Id$
+
+ require("../../config.php");
+ require("lib.php");
+
+ optional_variable($id); // Course Module ID
+ optional_variable($a); // Assignment ID
+
+ if ($id) {
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $cm->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 = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+
+ $strassignments = get_string("modulenameplural", "assignment");
+ $strassignment = get_string("modulename", "assignment");
+
+ print_header("$course->shortname: $assignment->name", "$course->fullname",
+ "$navigation <A HREF=index.php?id=$course->id>$strassignments</A> -> $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 "<P align=right><A HREF=\"submissions.php?id=$assignment->id\">".
+ get_string("viewsubmissions", "assignment", $count)."</A></P>";
+ }
+
+ $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 "<B>".get_string("duedate", "assignment")."</B>: $strduedate<BR>";
+ echo "<B>".get_string("maximumgrade")."</B>: $assignment->grade<BR>";
+ print_simple_box_end();
+ echo "<BR>";
+ echo text_to_html($assignment->description);
+ print_simple_box_end();
+ echo "<BR>";
+
+ if (!isteacher($course->id)) {
+ if ($submission = assignment_get_submission($assignment, $USER)) {
+ print_simple_box_start("center");
+ echo "<CENTER>";
+ print_heading(get_string("yoursubmission","assignment").":", "CENTER");
+ echo "<P><FONT SIZE=-1><B>".get_string("lastmodified")."</B>: ".userdate($submission->timemodified)."</FONT></P>";
+ assignment_print_user_files($assignment, $USER);
+ print_simple_box_end();
+ } else {
+ print_heading(get_string("notsubmittedyet","assignment"));
+ }
+
+ echo "<HR SIZE=1 NOSHADE>";
+
+ if ($submission->grade) {
+ print_heading(get_string("submissionfeedback", "assignment").":", "CENTER");
+ assignment_print_feedback($course, $submission);
+ } else {
+ if ($submission) {
+ echo "<P ALIGN=CENTER>".get_string("overwritewarning", "assignment")."</P>";
+ }
+ assignment_print_upload_form($assignment);
+ }
+ }
+
+ print_footer($course);
+
+?>