# 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/course/category.php
--- moodle/course/category.php Base (1.183)
+++ moodle/course/category.php Locally Modified (Based On 1.183)
@@ -321,7 +321,7 @@
             if ($editingon) {
                 echo '<td>';
                 if (has_capability('moodle/course:update', $coursecontext)) {
-                    echo '<a title="'.$strsettings.'" href="'.$CFG->wwwroot.'/course/edit.php?id='.$acourse->id.'">'.
+                    echo '<a title="'.$strsettings.'" href="'.$CFG->wwwroot.'/course/edit.php?id='.$acourse->id.'&categoryedit='.$categoryedit.'&sesskey='.sesskey().'">'.
                             '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.$stredit.'" /></a> ';
                 } else {
                     echo $spacer;
Index: moodle/course/edit.php
--- moodle/course/edit.php Base (1.133)
+++ moodle/course/edit.php Locally Modified (Based On 1.133)
@@ -29,6 +29,7 @@
 
 $id         = optional_param('id', 0, PARAM_INT);       // course id
 $categoryid = optional_param('category', 0, PARAM_INT); // course category - can be changed in edit form
+$categoryedit = optional_param('categoryedit', 0, PARAM_BOOL); // navigation flag to mark if from course/category.php, maybe improved to use context based nav aid?
 
 $PAGE->set_pagelayout('admin');
 $PAGE->set_url('/course/edit.php');
@@ -81,14 +82,18 @@
 }
 
 // first create the form
-$editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$category, 'editoroptions'=>$editoroptions));
+$editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$category, 'editoroptions'=>$editoroptions, 'categoryedit'=>$categoryedit));
 
 if ($editform->is_cancelled()) {
     if (empty($course->id)) {
         redirect($CFG->wwwroot.'/course');
     } else {
+        if($categoryedit){
+            redirect($CFG->wwwroot.'/course/category.php?id='.$course->category.'&categoryedit='.$categoryedit.'&sesskey='.sesskey());
+        } else {
         redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
     }
+    }
 
 } else if ($data = $editform->get_data()) {
     // process data if submitted
@@ -115,14 +120,22 @@
             }
         }
 
-        redirect($CFG->wwwroot."/course/view.php?id=$course->id");
+        if($categoryedit){
+            redirect($CFG->wwwroot.'/course/category.php?id='.$course->category.'&categoryedit='.$categoryedit.'&sesskey='.sesskey());
+        } else {
+            redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
+        }
 
     } else {
         // Save any changes to the files used in the editor
         update_course($data, $editoroptions);
-        redirect($CFG->wwwroot."/course/view.php?id=$course->id");
+        if($categoryedit){
+            redirect($CFG->wwwroot.'/course/category.php?id='.$course->category.'&categoryedit='.$categoryedit.'&sesskey='.sesskey());
+        } else {
+            redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
     }
 }
+}
 
 
 // Print the form
Index: moodle/course/edit_form.php
--- moodle/course/edit_form.php Base (1.86)
+++ moodle/course/edit_form.php Locally Modified (Based On 1.86)
@@ -16,6 +16,7 @@
         $course        = $this->_customdata['course']; // this contains the data of this form
         $category      = $this->_customdata['category'];
         $editoroptions = $this->_customdata['editoroptions'];
+        $categoryedit = $this->_customdata['categoryedit']; //navigation flag to send user back to category editing screen.
 
         $systemcontext   = get_context_instance(CONTEXT_SYSTEM);
         $categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
@@ -37,6 +38,10 @@
 //--------------------------------------------------------------------------------
         $mform->addElement('header','general', get_string('general', 'form'));
 
+        $mform->addElement('hidden', 'categoryedit', null);
+        $mform->setType('categoryedit', PARAM_BOOL);
+        $mform->setConstant('categoryedit', $categoryedit);
+
         // verify permissions to change course category or keep current
         if (empty($course->id)) {
             if (has_capability('moodle/course:create', $categorycontext)) {
Index: moodle/mod/assignment/renderer.php
--- moodle/mod/assignment/renderer.php No Base Revision
+++ moodle/mod/assignment/renderer.php Locally New
@@ -0,0 +1,84 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * A custom renderer class that extends the plugin_renderer_base and
+ * is used by the assignment module.
+ *
+ * @package mod-forum
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ **/
+class mod_assignment_renderer extends plugin_renderer_base {
+
+    /**
+     * Prints private files tree view
+     * @return string
+     */
+    public function assignment_files($context, $itemid) {
+        return $this->render(new assignment_files($context, $itemid));
+    }
+
+    public function render_assignment_files(assignment_files $tree) {
+        $module = array('name'=>'block_private_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview'));
+        $htmlid = 'assignment_files_tree_'.uniqid();
+        $this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $htmlid));
+        $html = '<div id="'.$htmlid.'">';
+        $html .= $this->htmllize_tree($tree, $tree->dir);
+        $html .= '</div>';
+        return $html;
+    }
+
+    /**
+     * Internal function - creates htmls structure suitable for YUI tree.
+     */
+    protected function htmllize_tree($tree, $dir) {
+        global $CFG;
+        $yuiconfig = array();
+        $yuiconfig['type'] = 'html';
+
+        if (empty($dir['subdirs']) and empty($dir['files'])) {
+            return '';
+        }
+        $result = '<ul>';
+        foreach ($dir['subdirs'] as $subdir) {
+            $image = $this->output->pix_icon("/f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
+        }
+        foreach ($dir['files'] as $file) {
+            $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
+            $filename = $file->get_filename();
+            $icon = substr(mimeinfo("icon", $filename), 0, -4);
+            $image = $this->output->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
+        }
+        $result .= '</ul>';
+
+        return $result;
+    }
+}
+
+class assignment_files implements renderable {
+    public $context;
+    public $dir;
+    public function __construct($context, $itemid) {
+        global $USER;
+        $this->context = $context;
+        $fs = get_file_storage();
+        $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', 'submission', $itemid);
+    }
+}
Index: moodle/mod/assignment/type/upload/upload.php
--- moodle/mod/assignment/type/upload/upload.php No Base Revision
+++ moodle/mod/assignment/type/upload/upload.php Locally New
@@ -0,0 +1,76 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ *
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
+require_once(dirname(__FILE__).'/upload_form.php');
+require_once(dirname(__FILE__).'/assignment.class.php');
+require_once("$CFG->dirroot/repository/lib.php");
+
+$contextid = required_param('contextid', PARAM_INT);
+
+$url = new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$contextid));
+
+list($context, $course, $cm) = get_context_info_array($contextid);
+
+require_login($course, true, $cm);
+if (isguestuser()) {
+    die();
+}
+
+$PAGE->set_url($url);
+if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
+    print_error('invalidid', 'assignment');
+}
+
+$instance = new assignment_upload($cm->id, $assignment, $cm, $course);
+$submission = $instance->get_submission($USER->id, true);
+
+$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+
+$mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'options'=>$filemanager_options));
+
+if ($mform->is_cancelled()) {
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+} else if ($formdata = $mform->get_data()) {
+    $instance->upload($mform, $filemanager_options);
+    die;
+}
+
+echo $OUTPUT->header();
+
+echo $OUTPUT->box_start('generalbox');
+if ($instance->can_upload_file($submission)) {
+    $data = new stdclass;
+    // move submission files to user draft area
+    $data = file_prepare_standard_filemanager($data, 'files', $filemanager_options, $context, 'mod_assignment', 'submission', $submission->id);
+    // set file manager itemid, so it will find the files in draft area
+    $mform->set_data($data);
+    $mform->display();
+} else {
+    echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
+    echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+}
+echo $OUTPUT->box_end();
+
+echo $OUTPUT->footer();
Index: moodle/mod/assignment/type/upload/upload_form.php
--- moodle/mod/assignment/type/upload/upload_form.php No Base Revision
+++ moodle/mod/assignment/type/upload/upload_form.php Locally New
@@ -0,0 +1,40 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_assignment_upload_form extends moodleform {
+    function definition() {
+        $mform = $this->_form;
+        $instance = $this->_customdata;
+
+        // visible elements
+        $mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
+
+        // hidden params
+        $mform->addElement('hidden', 'contextid', $instance['contextid']);
+        $mform->setType('contextid', PARAM_INT);
+        $mform->addElement('hidden', 'action', 'uploadfile');
+        $mform->setType('action', PARAM_ALPHA);
+
+        // buttons
+        $this->add_action_buttons(true, get_string('savechanges', 'admin'));
+    }
+}
Index: moodle/mod/assignment/type/uploadsingle/upload.php
--- moodle/mod/assignment/type/uploadsingle/upload.php No Base Revision
+++ moodle/mod/assignment/type/uploadsingle/upload.php Locally New
@@ -0,0 +1,63 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ *
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
+require_once(dirname(__FILE__).'/upload_form.php');
+require_once(dirname(__FILE__).'/assignment.class.php');
+require_once("$CFG->dirroot/repository/lib.php");
+
+$contextid = required_param('contextid', PARAM_INT);
+
+$url = new moodle_url('/mod/assignment/type/uploadsingle/upload.php', array('contextid'=>$contextid));
+
+list($context, $course, $cm) = get_context_info_array($contextid);
+
+if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
+    print_error('invalidid', 'assignment');
+}
+
+require_login($course, true, $cm);
+if (isguestuser()) {
+    die();
+}
+$instance = new assignment_uploadsingle($cm->id, $assignment, $cm, $course);
+
+$PAGE->set_url($url);
+
+$options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+
+$mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'options'=>$options));
+
+if ($mform->is_cancelled()) {
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+} else if ($formdata = $mform->get_data()) {
+    $instance->upload($mform, $options);
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+}
+
+echo $OUTPUT->header();
+echo $OUTPUT->box_start('generalbox');
+$mform->display();
+echo $OUTPUT->box_end();
+echo $OUTPUT->footer();
Index: moodle/mod/assignment/type/uploadsingle/upload_form.php
--- moodle/mod/assignment/type/uploadsingle/upload_form.php No Base Revision
+++ moodle/mod/assignment/type/uploadsingle/upload_form.php Locally New
@@ -0,0 +1,42 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package   mod-assignment
+ * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_assignment_uploadsingle_form extends moodleform {
+    function definition() {
+        $mform = $this->_form;
+        $instance = $this->_customdata;
+
+        // visible elements
+        //$mform->addElement('filemanager', 'newfile', get_string('uploadafile'));
+        //$mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
+        $mform->addElement('filepicker', 'assignment_file', get_string('uploadafile'), null, $instance['options']);
+
+        // hidden params
+        $mform->addElement('hidden', 'contextid', $instance['contextid']);
+        $mform->setType('contextid', PARAM_INT);
+        $mform->addElement('hidden', 'action', 'uploadfile');
+        $mform->setType('action', PARAM_ALPHA);
+
+        // buttons
+        $this->add_action_buttons(true, get_string('savechanges', 'admin'));
+    }
+}
Index: moodle/renderer.php
--- moodle/renderer.php No Base Revision
+++ moodle/renderer.php Locally New
@@ -0,0 +1,84 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * A custom renderer class that extends the plugin_renderer_base and
+ * is used by the assignment module.
+ *
+ * @package mod-forum
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ **/
+class mod_assignment_renderer extends plugin_renderer_base {
+
+    /**
+     * Prints private files tree view
+     * @return string
+     */
+    public function assignment_files($context, $itemid) {
+        return $this->render(new assignment_files($context, $itemid));
+    }
+
+    public function render_assignment_files(assignment_files $tree) {
+        $module = array('name'=>'block_private_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview'));
+        $htmlid = 'assignment_files_tree_'.uniqid();
+        $this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $htmlid));
+        $html = '<div id="'.$htmlid.'">';
+        $html .= $this->htmllize_tree($tree, $tree->dir);
+        $html .= '</div>';
+        return $html;
+    }
+
+    /**
+     * Internal function - creates htmls structure suitable for YUI tree.
+     */
+    protected function htmllize_tree($tree, $dir) {
+        global $CFG;
+        $yuiconfig = array();
+        $yuiconfig['type'] = 'html';
+
+        if (empty($dir['subdirs']) and empty($dir['files'])) {
+            return '';
+        }
+        $result = '<ul>';
+        foreach ($dir['subdirs'] as $subdir) {
+            $image = $this->output->pix_icon("/f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
+            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
+        }
+        foreach ($dir['files'] as $file) {
+            $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
+            $filename = $file->get_filename();
+            $icon = substr(mimeinfo("icon", $filename), 0, -4);
+            $image = $this->output->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));
+            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
+        }
+        $result .= '</ul>';
+
+        return $result;
+    }
+}
+
+class assignment_files implements renderable {
+    public $context;
+    public $dir;
+    public function __construct($context, $itemid) {
+        global $USER;
+        $this->context = $context;
+        $fs = get_file_storage();
+        $this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', 'submission', $itemid);
+    }
+}
Index: moodle/type/upload/upload.php
--- moodle/type/upload/upload.php No Base Revision
+++ moodle/type/upload/upload.php Locally New
@@ -0,0 +1,76 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ *
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
+require_once(dirname(__FILE__).'/upload_form.php');
+require_once(dirname(__FILE__).'/assignment.class.php');
+require_once("$CFG->dirroot/repository/lib.php");
+
+$contextid = required_param('contextid', PARAM_INT);
+
+$url = new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$contextid));
+
+list($context, $course, $cm) = get_context_info_array($contextid);
+
+require_login($course, true, $cm);
+if (isguestuser()) {
+    die();
+}
+
+$PAGE->set_url($url);
+if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
+    print_error('invalidid', 'assignment');
+}
+
+$instance = new assignment_upload($cm->id, $assignment, $cm, $course);
+$submission = $instance->get_submission($USER->id, true);
+
+$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+
+$mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'options'=>$filemanager_options));
+
+if ($mform->is_cancelled()) {
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+} else if ($formdata = $mform->get_data()) {
+    $instance->upload($mform, $filemanager_options);
+    die;
+}
+
+echo $OUTPUT->header();
+
+echo $OUTPUT->box_start('generalbox');
+if ($instance->can_upload_file($submission)) {
+    $data = new stdclass;
+    // move submission files to user draft area
+    $data = file_prepare_standard_filemanager($data, 'files', $filemanager_options, $context, 'mod_assignment', 'submission', $submission->id);
+    // set file manager itemid, so it will find the files in draft area
+    $mform->set_data($data);
+    $mform->display();
+} else {
+    echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
+    echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+}
+echo $OUTPUT->box_end();
+
+echo $OUTPUT->footer();
Index: moodle/type/upload/upload_form.php
--- moodle/type/upload/upload_form.php No Base Revision
+++ moodle/type/upload/upload_form.php Locally New
@@ -0,0 +1,40 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_assignment_upload_form extends moodleform {
+    function definition() {
+        $mform = $this->_form;
+        $instance = $this->_customdata;
+
+        // visible elements
+        $mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
+
+        // hidden params
+        $mform->addElement('hidden', 'contextid', $instance['contextid']);
+        $mform->setType('contextid', PARAM_INT);
+        $mform->addElement('hidden', 'action', 'uploadfile');
+        $mform->setType('action', PARAM_ALPHA);
+
+        // buttons
+        $this->add_action_buttons(true, get_string('savechanges', 'admin'));
+    }
+}
Index: moodle/type/uploadsingle/upload.php
--- moodle/type/uploadsingle/upload.php No Base Revision
+++ moodle/type/uploadsingle/upload.php Locally New
@@ -0,0 +1,63 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ *
+ * @package   mod-assignment
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
+require_once(dirname(__FILE__).'/upload_form.php');
+require_once(dirname(__FILE__).'/assignment.class.php');
+require_once("$CFG->dirroot/repository/lib.php");
+
+$contextid = required_param('contextid', PARAM_INT);
+
+$url = new moodle_url('/mod/assignment/type/uploadsingle/upload.php', array('contextid'=>$contextid));
+
+list($context, $course, $cm) = get_context_info_array($contextid);
+
+if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
+    print_error('invalidid', 'assignment');
+}
+
+require_login($course, true, $cm);
+if (isguestuser()) {
+    die();
+}
+$instance = new assignment_uploadsingle($cm->id, $assignment, $cm, $course);
+
+$PAGE->set_url($url);
+
+$options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+
+$mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'options'=>$options));
+
+if ($mform->is_cancelled()) {
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+} else if ($formdata = $mform->get_data()) {
+    $instance->upload($mform, $options);
+    redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
+}
+
+echo $OUTPUT->header();
+echo $OUTPUT->box_start('generalbox');
+$mform->display();
+echo $OUTPUT->box_end();
+echo $OUTPUT->footer();
Index: moodle/type/uploadsingle/upload_form.php
--- moodle/type/uploadsingle/upload_form.php No Base Revision
+++ moodle/type/uploadsingle/upload_form.php Locally New
@@ -0,0 +1,42 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package   mod-assignment
+ * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mod_assignment_uploadsingle_form extends moodleform {
+    function definition() {
+        $mform = $this->_form;
+        $instance = $this->_customdata;
+
+        // visible elements
+        //$mform->addElement('filemanager', 'newfile', get_string('uploadafile'));
+        //$mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
+        $mform->addElement('filepicker', 'assignment_file', get_string('uploadafile'), null, $instance['options']);
+
+        // hidden params
+        $mform->addElement('hidden', 'contextid', $instance['contextid']);
+        $mform->setType('contextid', PARAM_INT);
+        $mform->addElement('hidden', 'action', 'uploadfile');
+        $mform->setType('action', PARAM_ALPHA);
+
+        // buttons
+        $this->add_action_buttons(true, get_string('savechanges', 'admin'));
+    }
+}
