### Eclipse Workspace Patch 1.0
#P moodle18
Index: lang/en_utf8/assignment.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/assignment.php,v
retrieving revision 1.12
diff -u -r1.12 assignment.php
--- lang/en_utf8/assignment.php	20 Nov 2006 16:56:39 -0000	1.12
+++ lang/en_utf8/assignment.php	12 Feb 2008 14:29:55 -0000
@@ -51,6 +51,7 @@
 $string['feedback'] = 'Feedback';
 $string['feedbackfromteacher'] = 'Feedback from the $a';
 $string['feedbackupdated'] = 'Submissions feedback updated for $a people';
+$string['finalize'] = 'No more submissions';
 $string['graded'] = 'Graded';
 $string['guestnosubmit'] = 'Sorry, guests are not allowed to submit an assignment. You have to log in/ register before you can submit your answer';
 $string['guestnoupload'] = 'Sorry, guests are not allowed to upload';
Index: mod/assignment/type/upload/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/upload/assignment.class.php,v
retrieving revision 1.29.2.4
diff -u -r1.29.2.4 assignment.class.php
--- mod/assignment/type/upload/assignment.class.php	11 Jan 2008 11:47:23 -0000	1.29.2.4
+++ mod/assignment/type/upload/assignment.class.php	12 Feb 2008 14:29:56 -0000
@@ -343,11 +343,14 @@
                     }
                 }
             }
-            if (has_capability('mod/assignment:grade', $this->context)
-              and $this->can_unfinalize($submission)
-              and $mode != '') { // we do not want it on view.php page
-                $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset);
-                $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true);
+            if (has_capability('mod/assignment:grade', $this->context) and $mode != '') { // we do not want it on view.php page
+                if ($this->can_unfinalize($submission)) {
+                    $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'unfinalize', 'mode'=>$mode, 'offset'=>$offset);
+                    $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true);
+                } else if ($this->can_finalize($submission)) {
+                    $options = array ('id'=>$this->cm->id, 'userid'=>$userid, 'action'=>'finalize', 'mode'=>$mode, 'offset'=>$offset);
+                    $output .= print_single_button('upload.php', $options, get_string('finalize', 'assignment'), 'post', '_self', true);
+                }
             }
 
             $output = '<div class="files">'.$output.'</div>';
@@ -577,10 +580,20 @@
     function finalize() {
         global $USER;
 
-        $confirm = optional_param('confirm', 0, PARAM_BOOL);
+        $userid = optional_param('userid', 0, PARAM_INT);
 
-        $returnurl = 'view.php?id='.$this->cm->id;
-        $submission = $this->get_submission($USER->id);
+        if ($userid) {
+            $mode       = required_param('mode', PARAM_ALPHA);
+            $offset     = required_param('offset', PARAM_INT);
+            $returnurl  = "submissions.php?id={$this->cm->id}&amp;userid=$userid&amp;mode=$mode&amp;offset=$offset&amp;forcerefresh=1";
+            $confirm    = true;
+            $submission = $this->get_submission($userid);
+
+        } else {
+            $confirm    = optional_param('confirm', 0, PARAM_BOOL);
+            $returnurl  = 'view.php?id='.$this->cm->id;
+            $submission = $this->get_submission($USER->id);
+        }
 
         if (!$this->can_finalize($submission)) {
             redirect($returnurl); // probably already graded, erdirect to assignment page, the reason should be obvious
@@ -597,8 +610,8 @@
 
         } else {
             $updated = new object();
-            $updated->id = $submission->id;
-            $updated->data2 = ASSIGNMENT_STATUS_SUBMITTED;
+            $updated->id           = $submission->id;
+            $updated->data2        = ASSIGNMENT_STATUS_SUBMITTED;
             $updated->timemodified = time();
             if (update_record('assignment_submissions', $updated)) {
                 add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finilize action to log
@@ -788,7 +801,6 @@
 
         if (has_capability('mod/assignment:submit', $this->context)           // can submit
           and $this->isopen()                                                 // assignment not closed yet
-          and (empty($submission) or $submission->grade == -1)                // not graded
           and (empty($submission) or $submission->userid == $USER->id)        // his/her own submission
           and $this->count_user_files($USER->id) < $this->assignment->var1    // file limit not reached
           and !$this->is_finalized($submission)) {                            // no uploading after final submission
@@ -815,7 +827,6 @@
 
         if (has_capability('mod/assignment:submit', $this->context)
           and $this->isopen()                                      // assignment not closed yet
-          and (!empty($submission) and $submission->grade == -1)   // not graded
           and $this->assignment->resubmit                          // deleting allowed
           and $USER->id == $submission->userid                     // his/her own submission
           and !$this->is_finalized($submission)) {                 // no deleting after final submission
@@ -826,8 +837,7 @@
     }
 
     function is_finalized($submission) {
-        if (!empty($submission)
-          and $submission->data2 == ASSIGNMENT_STATUS_SUBMITTED) {
+        if ($submission->data2 == ASSIGNMENT_STATUS_SUBMITTED) {
             return true;
         } else {
             return false;
@@ -836,9 +846,8 @@
 
     function can_unfinalize($submission) {
         if (has_capability('mod/assignment:grade', $this->context)
-          and !empty($submission)
-          and $this->is_finalized($submission)
-          and $submission->grade == -1) {
+          and $this->isopen()
+          and $this->is_finalized($submission)) {
             return true;
         } else {
             return false;
@@ -848,14 +857,19 @@
     function can_finalize($submission) {
         global $USER;
 
-        if (has_capability('mod/assignment:submit', $this->context)           // can submit
+		if ($this->is_finalized($submission)) {
+		    return false;
+		}
+
+        if (has_capability('mod/assignment:grade', $this->context)) {
+            return true;
+
+        } else if (has_capability('mod/assignment:submit', $this->context)    // can submit
           and $this->isopen()                                                 // assignment not closed yet
           and !empty($submission)                                             // submission must exist
-          and $submission->data2 != ASSIGNMENT_STATUS_SUBMITTED               // not graded
           and $submission->userid == $USER->id                                // his/her own submission
-          and $submission->grade == -1                                        // no reason to finalize already graded submission
           and ($this->count_user_files($USER->id)
-            or ($this->notes_allowed() and !empty($submission->data1)))) { // something must be submitted
+            or ($this->notes_allowed() and !empty($submission->data1)))) {    // something must be submitted
 
             return true;
         } else {
@@ -867,9 +881,8 @@
         global $USER;
 
         if (has_capability('mod/assignment:submit', $this->context)
-          and $this->notes_allowed()                                               // notesd must be allowed
+          and $this->notes_allowed()                                          // notesd must be allowed
           and $this->isopen()                                                 // assignment not closed yet
-          and (empty($submission) or $submission->grade == -1)                // not graded
           and (empty($submission) or $USER->id == $submission->userid)        // his/her own submission
           and !$this->is_finalized($submission)) {                            // no updateingafter final submission
             return true;

