From 1d9541e9bf9baf9742d1ecf833cd4aaaf4d42f02 Mon Sep 17 00:00:00 2001
From: Martin Langhoff <martin@catalyst.net.nz>
Date: Tue, 26 Feb 2008 12:25:59 +1300
Subject: [PATCH] filelib: Work around IE/Powerpoint2007 download bug

When IE tries to download any powerpoint file, force an
application/x-download MIME type. We cannot make the special-case
narrower because it is *any* IE version, interacting with Powerpoint
(which we don't get to see a version of in the agent string).

The proper fix is to install Office 2007 SP1 - as per
http://support.microsoft.com/kb/935869

MDL-10538 tracks this bug in the Moodle tracker.
---
 lib/filelib.php |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/lib/filelib.php b/lib/filelib.php
index 92a8e70..2a592aa 100644
--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -507,6 +507,7 @@ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=
     // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
     // only Firefox saves all files locally before opening when content-disposition: attachment stated
     $isFF         = check_browser_version('Firefox', '1.5'); // only FF > 1.5 properly tested
+    $isIE         = check_browser_version('MSIE');
     $mimetype     = ($forcedownload and !$isFF) ? 'application/x-forcedownload' :
                          ($mimetype ? $mimetype : mimeinfo('type', $filename));
     $lastmodified = $pathisstring ? time() : filemtime($path);
@@ -533,6 +534,12 @@ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=
         ini_set('zlib.output_compression', 'Off');
     }
 
+    // Some mimetypes are mishandled by IE + Powerpoint 2007
+    // workaround is to force-download
+    if ($isIE && $mimetype === 'application/vnd.ms-powerpoint') {
+        $mimetype = 'application/x-forcedownload';
+    }
+
     //try to disable automatic sid rewrite in cookieless mode
     @ini_set("session.use_trans_sid", "false");
 
-- 
1.5.4.34.g053d9

