MDL-15911: support in odslib to write the file out rather than just send it
authormjollnir_ <mjollnir_>
Fri, 1 Aug 2008 12:12:57 +0000 (12:12 +0000)
committermjollnir_ <mjollnir_>
Fri, 1 Aug 2008 12:12:57 +0000 (12:12 +0000)
lib/odslib.class.php

index 4d70c1b8d16e73153799c02074f5387e981385e4..59832780fb87fddf9ff5600b721df044426c7f1f 100644 (file)
 class MoodleODSWorkbook {
     var $worksheets = array();
     var $filename;
+    var $send;
 
-    function MoodleODSWorkbook($filename) {
+    function MoodleODSWorkbook($filename, $send=true) {
         $this->filename = $filename;
+        $this->send = $send;
     }
 
     /* Create one Moodle Worksheet
@@ -95,15 +97,22 @@ class MoodleODSWorkbook {
         $files[] = "$dir/META-INF";
 
         $filename = "$dir/result.ods";
+        if (!$this->send) {
+            $filename = $this->filename;
+        }
         zip_files($files, $filename);
 
-        $handle = fopen($filename, 'rb');
-        $contents = fread($handle, filesize($filename));
-        fclose($handle);
+        if ($this->send) {
+            $handle = fopen($filename, 'rb');
+            $contents = fread($handle, filesize($filename));
+            fclose($handle);
 
-        remove_dir($dir); // cleanup the temp directory
+            remove_dir($dir); // cleanup the temp directory
 
-        send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet');
+            send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet');
+            return;
+        }
+        return $this->filename;
     }
 
     /* Not required to use