# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/mod/assignment/lang/en/assignment.php
--- moodle/mod/assignment/lang/en/assignment.php Base (1.16)
+++ moodle/mod/assignment/lang/en/assignment.php Locally Modified (Based On 1.16)
@@ -154,6 +154,7 @@
 $string['optionalsettings'] = 'Optional settings';
 $string['overwritewarning'] = 'Warning: uploading again will REPLACE your current submission';
 $string['pagesize'] = 'Submissions shown per page';
+$string['popupinnewwindow'] = 'Open in a popup window';
 $string['pluginadministration'] = 'Assignment administration';
 $string['pluginname'] = 'Assignment';
 $string['preventlate'] = 'Prevent late submissions';
Index: moodle/mod/assignment/lib.php
--- moodle/mod/assignment/lib.php Base (1.486)
+++ moodle/mod/assignment/lib.php Locally Modified (Based On 1.486)
@@ -899,10 +899,11 @@
      * @global object
      * @param string $extra_javascript
      */
-    function display_submission($offset=-1,$userid =-1) {
+    function display_submission($offset=-1,$userid =-1, $display=true) {
         global $CFG, $DB, $PAGE, $OUTPUT;
         require_once($CFG->libdir.'/gradelib.php');
         require_once($CFG->libdir.'/tablelib.php');
+        require_once("$CFG->dirroot/repository/lib.php");
         if ($userid==-1) {
             $userid = required_param('userid', PARAM_INT);
         }
@@ -1010,9 +1011,21 @@
         $mformdata->submissioncommentformat= FORMAT_HTML;
         $mformdata->submission_content= $this->print_user_files($user->id,true);
         $mformdata->filter = $filter;
+         if ($assignment->assignmenttype == 'upload') {
+            $mformdata->fileui_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+        } elseif ($assignment->assignmenttype == 'uploadsingle') {
+            $mformdata->fileui_options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+        }
 
         $submitform = new mod_assignment_grading_form( null, $mformdata );
 
+         if (!$display) {
+            $ret_data = new stdClass();
+            $ret_data->mform = $submitform;
+            $ret_data->fileui_options = $mformdata->fileui_options;
+            return $ret_data;
+        }
+
         if ($submitform->is_cancelled()) {
             redirect('submissions.php?id='.$this->cm->id);
         }
@@ -1021,7 +1034,8 @@
 
         $PAGE->set_title($this->course->fullname . ': ' .get_string('feedback', 'assignment').' - '.fullname($user, true));
         $PAGE->set_heading($this->course->fullname);
-        $PAGE->navbar->add( get_string('submissions', 'assignment') );
+        $PAGE->navbar->add(get_string('submissions', 'assignment'), new moodle_url('/mod/assignment/submissions.php', array('id'=>$cm->id)));
+        $PAGE->navbar->add(fullname($user, true));
 
         echo $OUTPUT->header();
         echo $OUTPUT->heading(get_string('feedback', 'assignment').': '.fullname($user, true));
@@ -1491,7 +1505,7 @@
      * @global object
      * @return object|bool The updated submission object or false
      */
-    function process_feedback() {
+    function process_feedback($formdata=null) {
         global $CFG, $USER, $DB;
         require_once($CFG->libdir.'/gradelib.php');
 
@@ -1545,7 +1559,13 @@
 
             add_to_log($this->course->id, 'assignment', 'update grades',
                        'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
+             if (!is_null($formdata)) {
+                    if ($this->type == 'upload' || $this->type == 'uploadsingle') {
+                        $mformdata = $formdata->mform->get_data();
+                        $mformdata = file_postupdate_standard_filemanager($mformdata, 'files', $formdata->fileui_options, $this->context, 'mod_assignment', 'response', $submission->id);
         }
+             }
+        }
 
         return $submission;
 
@@ -2168,21 +2188,21 @@
                                                 userdate($this->_customdata->submission->timemodified) .
                                                 $this->_customdata->lateness );
 
+        $this->add_submission_content();
         $this->add_grades_section();
 
         $this->add_feedback_section();
 
         if ($this->_customdata->submission->timemarked) {
+            $datestring = userdate($this->_customdata->submission->timemarked)."&nbsp; (".format_time(time() - $this->_customdata->submission->timemarked).")";
             $mform->addElement('header', 'Last Grade', get_string('lastgrade', 'assignment'));
             $mform->addElement('static', 'picture', $OUTPUT->user_picture($this->_customdata->teacher) ,
                                                     fullname($this->_customdata->teacher,true).
-                                                    '<br/>'.
-                                                    userdate($this->_customdata->submission->timemarked));
+                                                    '<br/>'.$datestring);
         }
         // buttons
         $this->add_action_buttons();
 
-        $this->add_submission_content();
     }
 
     function add_grades_section() {
@@ -2245,7 +2265,14 @@
             $mform->setType('submissioncomment_editor', PARAM_RAW); // to be cleaned before display
             $mform->setDefault('submissioncomment_editor', $this->_customdata->submission->submissioncomment);
             //$mform->addRule('submissioncomment', get_string('required'), 'required', null, 'client');
-
+            switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $mform->addElement('filemanager', 'files_filemanager', get_string('responsefiles', 'assignment'). ':', null, $this->_customdata->fileui_options);
+                    break;
+                default :
+                    break;
+            }
             $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? array('checked'=>'checked') : array();
             $mform->addElement('hidden', 'mailinfo_h', "0");
             $mform->setType('mailinfo_h', PARAM_INT);
@@ -2258,7 +2285,6 @@
 
     function add_action_buttons() {
         $mform =& $this->_form;
-        $mform->addElement('header', 'Operation', get_string('operation', 'assignment'));
         //if there are more to be graded.
         if ($this->_customdata->nextid>0) {
             $buttonarray=array();
@@ -2273,6 +2299,7 @@
             $buttonarray[] = &$mform->createElement('cancel');
         }
         $mform->addGroup($buttonarray, 'grading_buttonar', '', array(' '), false);
+        $mform->closeHeaderBefore('grading_buttonar');
         $mform->setType('grading_buttonar', PARAM_RAW);
     }
 
@@ -2309,6 +2336,15 @@
             $itemid = null;
         }
 
+        switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $data = file_prepare_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
+                    break;
+                default :
+                    break;
+        }
+
         $data = file_prepare_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
         return parent::set_data($data);
     }
@@ -2324,8 +2360,15 @@
 
         if ($data) {
             $editoroptions = $this->get_editor_options();
+            switch ($this->_customdata->assignment->assignmenttype) {
+                case 'upload' :
+                case 'uploadsingle' :
+                    $data = file_postupdate_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
+                    break;
+                default :
+                    break;
+            }
             $data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
-            $data->format = $data->textformat;
         }
         return $data;
     }
Index: moodle/mod/assignment/styles.css
--- moodle/mod/assignment/styles.css Base (1.4)
+++ moodle/mod/assignment/styles.css Locally Modified (Based On 1.4)
@@ -15,6 +15,7 @@
 .path-mod-assignment .late {color: red;}
 
 /** Styles for submissions.php **/
+#page-mod-assignment-submissions fieldset.felement {margin-left: 16%;}
 #page-mod-assignment-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;}
 #page-mod-assignment-submissions .header .commands {display: inline;}
 #page-mod-assignment-submissions .picture {width: 35px;}
Index: moodle/mod/assignment/type/online/assignment.class.php
--- moodle/mod/assignment/type/online/assignment.class.php Base (1.100)
+++ moodle/mod/assignment/type/online/assignment.class.php Locally Modified (Based On 1.100)
@@ -214,19 +214,19 @@
 
         $link = new moodle_url("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}");
         $action = new popup_action('click', $link, 'file'.$userid, array('height' => 450, 'width' => 580));
-        $popup = $OUTPUT->action_link($link, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), $action, array('title'=>get_string('submission', 'assignment')));
+        $popup = $OUTPUT->action_link($link, get_string('popupinnewwindow','assignment'), $action, array('title'=>get_string('submission', 'assignment')));
 
         $output = '<div class="files">'.
                   '<img align="middle" src="'.$OUTPUT->pix_url('f/html') . '" height="16" width="16" alt="html" />'.
                   $popup .
                   '</div>';
 
-        $wordcount = '<p id="wordcount">';
+        $wordcount = '<p id="wordcount">'. $popup . '&nbsp;';
     /// Decide what to count
         if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
-            $wordcount .= ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')';
+            $wordcount .= '('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')';
         } else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
-            $wordcount .= ' ('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')';
+            $wordcount .= '('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')';
         }
         $wordcount .= '</p>';
 
Index: moodle/mod/assignment/type/upload/assignment.class.php
--- moodle/mod/assignment/type/upload/assignment.class.php Base (1.123)
+++ moodle/mod/assignment/type/upload/assignment.class.php Locally Modified (Based On 1.123)
@@ -264,42 +264,6 @@
         return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable));
     }
 
-    function custom_feedbackform($submission, $return=false) {
-        global $CFG, $OUTPUT;
-
-        $mode         = optional_param('mode', '', PARAM_ALPHA);
-        $offset       = optional_param('offset', 0, PARAM_INT);
-        $forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL);
-
-        if ($this->count_responsefiles($submission->userid) > 0) {
-            $str = get_string('editthesefiles', 'assignment');
-        } else {
-            $str = get_string('uploadfiles', 'assignment');
-        }
-
-        $output = get_string('responsefiles', 'assignment').': ';
-
-        $output .= $OUTPUT->single_button(new moodle_url('/mod/assignment/type/upload/upload.php',
-                    array('contextid'=>$this->context->id,'id'=>$this->cm->id, 'offset'=>$offset,
-                          'forcerefresh'=>$forcerefresh, 'userid'=>$submission->userid, 'mode'=>$mode)), $str, 'get');
-
-        if ($forcerefresh) {
-            $output .= $this->update_main_listing($submission);
-        }
-
-        $responsefiles = $this->print_responsefiles($submission->userid, true);
-        if (!empty($responsefiles)) {
-            $output .= $responsefiles;
-        }
-
-        if ($return) {
-            return $output;
-        }
-        echo $output;
-        return;
-    }
-
-
     function print_student_answer($userid, $return=false){
         global $CFG, $OUTPUT, $PAGE;
 
@@ -400,6 +364,16 @@
         parent::submissions($mode);
     }
 
+    function process_feedback() {
+        if (!$feedback = data_submitted() or !confirm_sesskey()) {      // No incoming data?
+            return false;
+        }
+        $userid = required_param('userid', PARAM_INT);
+        $offset = required_param('offset', PARAM_INT);
+        $mform = $this->display_submission($offset, $userid, false);
+        parent::process_feedback($mform);
+    }
+
     function print_responsefiles($userid, $return=false) {
         global $CFG, $USER, $OUTPUT, $PAGE;
 
Index: moodle/mod/assignment/type/upload/upload.php
--- moodle/mod/assignment/type/upload/upload.php Base (1.3)
+++ moodle/mod/assignment/type/upload/upload.php Locally Modified (Based On 1.3)
@@ -61,22 +61,10 @@
 
 $filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
 
-if ($id==null) {
     $mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$filemanager_options));
-} else {
-    $formdata->cm->id = $id;
-    $formdata->contextid = $contextid;
-    $formdata->options = $filemanager_options;
-    $mform = new mod_assignment_upload_response_form(null, $formdata);
-}
 
 if ($mform->is_cancelled()) {
-    if ($id==null) {
         redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
-    } else {
-        $instance->display_submission($formdata->offset, $formdata->userid);
-        die();
-    }
 } else if ($formdata = $mform->get_data()) {
     $instance->upload($mform, $filemanager_options);
     die;
@@ -92,13 +80,7 @@
     // set file manager itemid, so it will find the files in draft area
     $mform->set_data($data);
     $mform->display();
-} else if ($instance->can_manage_responsefiles() && !($id==null)) { //a 'response' files upload
-    // move submission files to user draft area
-    $formdata = file_prepare_standard_filemanager($formdata, 'files', $filemanager_options, $context, 'mod_assignment', 'response', $submission->id);
-    // set file manager itemid, so it will find the files in draft area
-    $mform->set_data($formdata);
-    $mform->display();
-} else {
+}else {
     echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
     echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
 }
Index: moodle/mod/assignment/type/uploadsingle/assignment.class.php
--- moodle/mod/assignment/type/uploadsingle/assignment.class.php Base (1.72)
+++ moodle/mod/assignment/type/uploadsingle/assignment.class.php Locally Modified (Based On 1.72)
@@ -90,37 +90,17 @@
         $this->view_footer();
     }
 
-    function custom_feedbackform($submission, $return=false) {
-        global $CFG, $OUTPUT;
 
-        $mode         = optional_param('mode', '', PARAM_ALPHA);
-        $offset       = optional_param('offset', 0, PARAM_INT);
-
-        $fs = get_file_storage();
-        if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'response', $submission->id, "timemodified", false)) {
-            $str = get_string('editthisfile', 'assignment');
-        } else {
-            $str = get_string('uploadafile', 'assignment');
+    function process_feedback() {
+        if (!$feedback = data_submitted() or !confirm_sesskey()) {      // No incoming data?
+            return false;
         }
-
-        $output = get_string('responsefiles', 'assignment').': ';
-
-        $output .= $OUTPUT->single_button(new moodle_url('/mod/assignment/type/uploadsingle/upload.php',
-                    array('contextid'=>$this->context->id,'id'=>$this->cm->id, 'offset'=>$offset,
-                          'userid'=>$submission->userid, 'mode'=>$mode)), $str, 'get');
-
-        $responsefiles = $this->print_responsefiles($submission->userid, true);
-        if (!empty($responsefiles)) {
-            $output .= $responsefiles;
+        $userid = required_param('userid', PARAM_INT);
+        $offset = required_param('offset', PARAM_INT);
+        $mform = $this->display_submission($offset, $userid, false);
+        parent::process_feedback($mform);
         }
 
-        if ($return) {
-            return $output;
-        }
-        echo $output;
-        return;
-    }
-
\ No newline at end of file
     function print_responsefiles($userid, $return=false) {
         global $CFG, $USER, $OUTPUT, $PAGE;
 
Index: moodle/mod/assignment/type/uploadsingle/upload.php
--- moodle/mod/assignment/type/uploadsingle/upload.php Base (1.5)
+++ moodle/mod/assignment/type/uploadsingle/upload.php Locally Modified (Based On 1.5)
@@ -59,22 +59,10 @@
 
 $options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
 
-if ($id==null) {
     $mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$options));
-} else {
-    $formdata->cm->id = $id;
-    $formdata->contextid = $contextid;
-    $formdata->options = $options;
-    $mform = new mod_assignment_uploadsingle_response_form(null, $formdata);
-}
 
 if ($mform->is_cancelled()) {
-    if ($id==null) {
         redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
-    } else {
-        $instance->display_submission($formdata->offset, $formdata->userid);
-        die();
-    }
 } else if ($mform->get_data()) {
     $instance->upload($mform);
     die();
