### Eclipse Workspace Patch 1.0
#P moodle19
Index: mod/assignment/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/lib.php,v
retrieving revision 1.277.2.40
diff -u -r1.277.2.40 lib.php
--- mod/assignment/lib.php	27 Mar 2008 08:38:27 -0000	1.277.2.40
+++ mod/assignment/lib.php	1 Apr 2008 20:54:03 -0000
@@ -1684,12 +1684,7 @@
                 foreach ($files as $key => $file) {
 
                     $icon = mimeinfo('icon', $file);
-
-                    if ($CFG->slasharguments) {
-                        $ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
-                    } else {
-                        $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
-                    }
+                    $ffurl = get_file_url("$filearea/$file", array('forcedownload'=>1));
 
                     $output .= '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
                             '<a href="'.$ffurl.'" >'.$file.'</a><br />';
Index: lib/filelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/filelib.php,v
retrieving revision 1.50.2.11
diff -u -r1.50.2.11 filelib.php
--- lib/filelib.php	31 Mar 2008 12:17:59 -0000	1.50.2.11
+++ lib/filelib.php	1 Apr 2008 20:54:00 -0000
@@ -2,6 +2,40 @@
 
 define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7'); //unique string constant
 
+function get_file_url($path, $options=null, $type='coursefile') {
+    global $CFG;
+
+    $path = trim($path, '/'); // no leading and trailing slashes
+
+    // type of file
+    switch ($type) {
+        case 'coursefile':
+        default:
+            $url = "$CFG->wwwroot/file.php";
+    }
+
+    if ($CFG->slasharguments) {
+        $parts = explode('/', $path);
+        $parts = array_map('urlencode', $parts);
+        $path  = implode('/', $parts);
+        $ffurl = "$CFG->wwwroot/file.php/$path";
+        $separator = '?';
+    } else {
+        $path = urlencode("/$path");
+        $ffurl = "$CFG->wwwroot/file.php?file=$path";
+        $separator = '&amp;';
+    }
+
+    if ($options) {
+        foreach ($options as $name=>$value) {
+            $ffurl = $ffurl.$separator.$name.'='.$value;
+            $separator = '&amp;';
+        }
+    }
+
+    return $ffurl;
+}
+
 /**
  * Fetches content of file from Internet (using proxy if defined). Uses cURL extension if present.
  * Due to security concerns only downloads from http(s) sources are supported.
Index: mod/assignment/type/uploadsingle/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/uploadsingle/assignment.class.php,v
retrieving revision 1.33.2.4
diff -u -r1.33.2.4 assignment.class.php
--- mod/assignment/type/uploadsingle/assignment.class.php	19 Mar 2008 22:33:18 -0000	1.33.2.4
+++ mod/assignment/type/uploadsingle/assignment.class.php	1 Apr 2008 20:54:04 -0000
@@ -16,17 +16,12 @@
 
         if ($basedir = $this->file_area($userid)) {
             if ($files = get_directory_list($basedir)) {
-
+                require_once($CFG->libdir.'/filelib.php');
                 foreach ($files as $key => $file) {
-                    require_once($CFG->libdir.'/filelib.php');
 
                     $icon = mimeinfo('icon', $file);
+                    $ffurl = get_file_url("$filearea/$file");
 
-                    if ($CFG->slasharguments) {
-                        $ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
-                    } else {
-                        $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
-                    }
                     //died right here
                     //require_once($ffurl);
                     $output = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
Index: mod/assignment/type/upload/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/upload/assignment.class.php,v
retrieving revision 1.32.2.12
diff -u -r1.32.2.12 assignment.class.php
--- mod/assignment/type/upload/assignment.class.php	19 Mar 2008 22:33:19 -0000	1.32.2.12
+++ mod/assignment/type/upload/assignment.class.php	1 Apr 2008 20:54:04 -0000
@@ -300,10 +300,10 @@
             }
 
             if ($files = get_directory_list($basedir, 'responses')) {
+                require_once($CFG->libdir.'/filelib.php');
                 foreach ($files as $key => $file) {
-                    require_once($CFG->libdir.'/filelib.php');
                     $icon = mimeinfo('icon', $file);
-                    $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
+                    $ffurl = get_file_url("$filearea/$file");
                     $output .= '<a href="'.$ffurl.'" ><img class="icon" src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$file.'</a>&nbsp;';
                 }
             }
@@ -361,9 +361,7 @@
                 foreach ($files as $key => $file) {
 
                     $icon = mimeinfo('icon', $file);
-
-                    $ffurl   = "$CFG->wwwroot/file.php?file=/$filearea/$file";
-
+                    $ffurl = get_file_url("$filearea/$file");
 
                     $output .= '<a href="'.$ffurl.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.$file.'</a>';
 
@@ -419,7 +417,7 @@
 
                     $icon = mimeinfo('icon', $file);
 
-                    $ffurl   = "$CFG->wwwroot/file.php?file=/$filearea/$file";
+                    $ffurl = get_file_url("$filearea/$file");
 
                     $output .= '<a href="'.$ffurl.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$file.'</a>';
 
