diff --git a/backup/moodle2/backup_assignment_stepslib.php b/backup/moodle2/backup_assignment_stepslib.php
index 8d75887..32f45c2 100755
--- a/backup/moodle2/backup_assignment_stepslib.php
+++ b/backup/moodle2/backup_assignment_stepslib.php
@@ -42,7 +42,7 @@ class backup_assignment_activity_structure_step extends backup_activity_structur
             'resubmit', 'preventlate', 'emailteachers', 'var1',
             'var2', 'var3', 'var4', 'var5',
             'maxbytes', 'timedue', 'timeavailable', 'grade',
-            'timemodified'));
+            'timemodified', file_suffixes_permitted, file_rename_template));
 
         $submissions = new backup_nested_element('submissions');
 
diff --git a/db/upgrade.php b/db/upgrade.php
index 4136a76..bfee632 100755
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -154,8 +154,63 @@ function xmldb_assignment_upgrade($oldversion) {
         upgrade_mod_savepoint(true, 2009042001, 'assignment');
     }
 
-    // Moodle v2.1.0 release upgrade line
-    // Put any upgrade step following this
+
+
+	if ($oldversion < 2011072800) {
+		
+        // Define field restrict_file_suffixes to be added to assignment
+        $table = new xmldb_table('assignment');
+        $field = new xmldb_field('restrict_file_suffixes', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, 'timemodified');
+
+        // Conditionally launch add field restrict_file_suffixes
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+
+        // assignment savepoint reached
+    
+      // Define field file_suffixes_permitted to be added to assignment
+        $table = new xmldb_table('assignment');
+        $field = new xmldb_field('file_suffixes_permitted', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'restrict_file_suffixes');
+
+        // Conditionally launch add field file_suffixes_permitted
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // assignment savepoint reached
+        upgrade_mod_savepoint(true, 2011072800, 'assignment');
+    }
+    
+    
+     if ($oldversion < 2011080300) {
+
+        // Define field file_rename_template to be added to assignment
+        $table = new xmldb_table('assignment');
+        $field = new xmldb_field('file_rename_template', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'file_suffixes_permitted');
+
+        // Conditionally launch add field file_rename_template
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Define field file_suffixes_permitted to be dropped from assignment
+        $table = new xmldb_table('assignment');
+        $field = new xmldb_field('restrict_file_suffixes');
+
+        // Conditionally launch drop field file_suffixes_permitted
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->drop_field($table, $field);
+        }
+
+        // assignment savepoint reached
+        upgrade_mod_savepoint(true, 2011080300, 'assignment');
+    }
+
+    
+
+
 
     return true;
 }
diff --git a/lang/en/assignment.php b/lang/en/assignment.php
index b7f559e..8d29bb1 100755
--- a/lang/en/assignment.php
+++ b/lang/en/assignment.php
@@ -214,3 +214,19 @@ $string['viewfeedback'] = 'View assignment grades and feedback';
 $string['viewmysubmission'] = 'View my submission';
 $string['viewsubmissions'] = 'View {$a} submitted assignments';
 $string['yoursubmission'] = 'Your submission';
+$string['restrict_file_suffixes'] = 'Restrict file suffixes';
+$string['file_suffixes_permitted'] = 'Permitted file suffixes';
+$string['file_rename_template'] = 'Template for assignment filenames';
+$string['invalid_file_suffixes'] = 'Input must be a comma separated list of permitted file suffixes';
+$string['invalid_rename_template'] = 'Input must be a list of user or assigment properties, each surrounded by square brackets';
+$string['file_suffixes_permitted_help'] = 'Add a list of permitted file extensions, if you want to restrict the file types users can upload. Leave blank to allow all kinds of files';
+$string['file_rename_template_help'] = 'Add a pattern for filenames. You may type any combination of strings and a set of [variables] in square brackets. Allowed variables are: <br>
+[group] Name of the group if activity is in group mode<br>
+[username] Moodle user name, for most students equal to "Matrikelnummer" <br>
+[lastname]<br>
+[firstname]<br>
+[course] Shortname of the course<br>
+[assigment] Name of the assignment activity<br>
+Example: If you put in here: homework[username]march011[assignment], and username is "r30003", assignment name is "Sonographiekurs 1", the file will be renamed as "homework_r30003_march011_Sonographiekurs 1.doc"';
+
+  
diff --git a/lib.php b/lib.php
index 86c5832..da3588b 100755
--- a/lib.php
+++ b/lib.php
@@ -430,9 +430,20 @@ class assignment_base {
      * See lib/formslib.php, 'validation' function for details
      */
     function form_validation($data, $files) {
-        return array();
+		$errors = array();
+		// empty or whitespaces or comma separated list of file extensions
+		$comma_separated_list_for_suffixes = '/(^\s*$)|(^(\s*\.?\w+\s*,\s*)+(\s*\.?\w+\s*)?$)/';
+		$bracket_pattern_for_filenames = '/^((\s*[\w\-]+\s*)|(\s*\[\s*\w+\s*\]\s*))+$/';
+		if (!preg_match($comma_separated_list_for_suffixes, $data['file_suffixes_permitted'])) {
+			$errors['file_suffixes_permitted'] = get_string('invalid_file_suffixes', 'assignment');
+		}
+		if (!preg_match($bracket_pattern_for_filenames, $data['file_rename_template'])) {
+			$errors['file_rename_template'] = get_string('invalid_rename_template', 'assignment');
+		}
+        return $errors;
     }
 
+
     /**
      * Create a new assignment activity
      *
@@ -2147,6 +2158,62 @@ class assignment_base {
         return false;
     }
 
+
+    /** UW: file types:
+    */
+    function permitted_filetypes() {
+        if ($this->assignment->file_suffixes_permitted && !preg_match('/^\s*$/', $this->assignment->file_suffixes_permitted )) {
+            $filetypes = explode(',' , $this->assignment->file_suffixes_permitted);
+            array_walk($filetypes, function(&$val) {
+            $val = trim($val);
+            $val = (strpos($val, '.') === 0) ? $val : '.' . $val;
+            });
+            return $filetypes;
+        
+        } else {
+            return '*';
+        }
+    }
+                
+    function rename_assigned_file($filename) {
+        global $USER;
+        
+        if (!empty($this->assignment->file_rename_template) && !preg_match('/^\s*$/', $this->assignment->file_rename_template)) {
+            $filename_components = array();
+            $currentgroup = groups_get_activity_group($this->cm);
+            if ($currentgroup) {
+                $group = groups_get_group($currentgroup);
+                $filename_components['group'] =	$group->name; 
+            }
+            $filename_components['course'] = $this->course->shortname;
+            $filename_components['lastname'] = $USER->lastname;
+            $filename_components['firstname'] = $USER->firstname;
+            $filename_components['username'] = $USER->username;
+            $filename_components['assignment'] = $this->assignment->name;
+            $filename_suffix = end(explode('.', $filename));
+            // $reg_split_filename = '/\[|\]/';
+            $reg_split_filename = '/\s*([\w\-]+)\s*|\[\s*(\w+)\s*\]\s*/';
+    
+            preg_match_all($reg_split_filename, $this->assignment->file_rename_template, $matches, PREG_SET_ORDER);
+            $newname ='';
+            foreach($matches as $match) {
+                if (isset($match[2])) {
+                
+                    if (array_key_exists($match[2], $filename_components)) {
+                        $newname .= "{$filename_components[$match[2]]}_";
+                    }
+                } else {
+                    $newname .= "{$match[1]}_";
+                }
+            }
+            $newname = ($newname == '') ? $filename : rtrim($newname, '_') . '.' . $filename_suffix;
+            return $newname;
+        } else {
+            return $filename;
+        }
+    }
+    
+
     /**
      * base implementation for backing up subtype specific information
      * for one single module
diff --git a/type/uploadsingle/assignment.class.php b/type/uploadsingle/assignment.class.php
index d0278ac..1eeae55 100755
--- a/type/uploadsingle/assignment.class.php
+++ b/type/uploadsingle/assignment.class.php
@@ -194,7 +194,7 @@ class assignment_uploadsingle extends assignment_base {
 
                 if ($newfilename = $mform->get_new_filename('assignment_file')) {
                     $file = $mform->save_stored_file('assignment_file', $this->context->id, 'mod_assignment', 'submission',
-                        $submission->id, '/', $newfilename);
+                        $submission->id, '/', $this->rename_assigned_file($newfilename));
 
                     $updates = new stdClass(); //just enough data for updating the submission
                     $updates->timemodified = time();
@@ -266,7 +266,13 @@ class assignment_uploadsingle extends assignment_base {
         $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
         $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
         $mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
-
+	
+	//UW: form input for file type restriction and renaming template
+        $mform->addElement('text', 'file_suffixes_permitted', get_string('file_suffixes_permitted', 'assignment'), array('size'=>'64'));
+        $mform->addHelpButton('file_suffixes_permitted', 'file_suffixes_permitted', 'assignment');
+        $mform->addElement('text', 'file_rename_template', get_string('file_rename_template', 'assignment'), array('size'=>'64'));
+        $mform->addhelpButton('file_rename_template', 'file_rename_template', 'assignment'); 
+	
         $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
         plagiarism_get_form_elements_module($mform, $course_context);
     }
@@ -422,4 +428,4 @@ class mod_assignment_uploadsingle_response_form extends moodleform {
         // buttons
         $this->add_action_buttons(false, get_string('uploadthisfile'));
     }
-}
\ No newline at end of file
+}
diff --git a/type/uploadsingle/upload.php b/type/uploadsingle/upload.php
index b531e00..f93a692 100755
--- a/type/uploadsingle/upload.php
+++ b/type/uploadsingle/upload.php
@@ -57,7 +57,7 @@ $title = strip_tags($course->fullname.': '.get_string('modulename', 'assignment'
 $PAGE->set_title($title);
 $PAGE->set_heading($title);
 
-$options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
+$options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes), 'maxfiles'=>1, 'accepted_types'=> $instance->permitted_filetypes(), 'return_types'=>FILE_INTERNAL);
 
     $mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$options));
 
diff --git a/version.php b/version.php
index 8bcda08..2b609cc 100755
--- a/version.php
+++ b/version.php
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2010102600;
+$module->version  = 2011080800;
 $module->requires = 2010102600;  // Requires this Moodle version
 $module->cron     = 60;
 
