Index: documentation/trunk/php/gs-manual-export.php
===================================================================
--- documentation/trunk/php/gs-manual-export.php	(revision 25026)
+++ documentation/trunk/php/gs-manual-export.php	(revision 27507)
@@ -19,5 +19,5 @@
 
 // 0. Initialization
-$xml_source_path = '/research/jmt12/gsdl-docs/temp';
+
 // - we have a counter to assign identifiers to text blocks etc without ids
 $text_id_counter = 1;
@@ -44,4 +44,16 @@
 {
   $_REQUEST['a'] = 'store'; // Try to store the file to disk
+}
+
+$var_path = filecat(array($base_path, 'var'));
+$timestamp = time();
+//$xml_source_path = '**PATH TO GSDL MANUALS**'
+$xml_source_path = '/tmp';
+if ($_REQUEST['a'] == 'download')
+{
+  // Clear out previous exports
+  recursiveRemove($var_path, '/greenstone/greenstone-documentation/php/var');
+  // New export
+  $xml_source_path = fileCat(array($var_path, $timestamp));
 }
 
@@ -66,25 +78,18 @@
 echo '<p><b>Manual:</b> ' . $_REQUEST['m'] . ' <b>Language:</b> ' . $_REQUEST['l'] . "</p>\n<hr/>\n";
 // 1. Create the XML output file handle
-$xml_file_path = '';
-if ($_REQUEST['a'] == 'download')
-{
-  $xml_file_path = fileCat(array($base_path, 'var', ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml'));
-}
-else
-{
-  // - construct the path using the information we've been provided as arguments
-  $xml_file_dir = $xml_source_path . '/' . $_REQUEST['l'];
-  mkAllDir($xml_file_dir, 0755);
-  $xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml';
-  // - backup any existing file
-  if (file_exists($xml_file_path))
-  {
-    $xml_backup_file_path = $xml_file_path . '.bak';
-    if (!rename($xml_file_path, $xml_backup_file_path))
-    {
-      printError('Failed to rename existing manual file for backup');
-    }
-  }
-}
+// - construct the path using the information we've been provided as arguments
+$xml_file_dir = $xml_source_path . '/' . $_REQUEST['l'];
+mkAllDir($xml_file_dir);
+$xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml';
+// - backup any existing file
+if (file_exists($xml_file_path))
+{
+  $xml_backup_file_path = $xml_file_path . '.bak';
+  if (!rename($xml_file_path, $xml_backup_file_path))
+  {
+    printError('Failed to rename existing manual file for backup');
+  }
+}
+
 // - and create a handle to the new file
 $xml_out = fopen($xml_file_path, 'w');
@@ -226,4 +231,5 @@
 fwrite($xml_out, '</Manual>' . "\n");
 fclose($xml_out);
+chmod($xml_file_path, 0664);
 
 // 6. Complete!
@@ -231,5 +237,22 @@
 if ($_REQUEST['a'] == 'download')
 {
-  echo '<p>Click <a href="var/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml">here</a> to download XML file</p>' . "\n";
+  // Zip up the manual files
+  $zip_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.zip';
+  $zip_path = fileCat(array($xml_source_path, $zip_file));
+  $zip_command = 'zip -r "' . $zip_path . '" . > /dev/null 2>&1';
+  //cho '<p><b>[DEBUG]</b> zip_command:' . $zip_command . '</p>';
+  $tgz_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.tgz';
+  $tgz_path = fileCat(array($xml_source_path, $tgz_file));
+  $tgz_command = 'tar -czf "' . $tgz_path . '" * > /dev/null 2>&1';
+  //cho '<p><b>[DEBUG]</b> tgz_command:' . $tgz_command . '</p>';
+  // We need to move to the document folder so that archives have sensible paths
+  $original_cwd = getcwd();
+  chdir($xml_file_dir);
+  system($zip_command);
+  system($tgz_command);
+  // Go back
+  chdir($original_cwd);
+  // Links are ready
+  echo '<p>Download XML file plus images as: <a href="var/' . $timestamp . '/' . $zip_file . '">ZIP</a> or <a href="var/' . $timestamp . '/' . $tgz_file . '">TGZ</a></p>' . "\n";
 }
 echo '<p>Click <a href="' . $dokuwiki_url . '/doku.php?id=' . $_REQUEST['l'] . ':manuals:' . $_REQUEST['m'] . '">here</a> to return to dokuwiki</p>' . "\n";
@@ -1205,9 +1228,10 @@
     $image_source_path = $dokuwiki_path . '/data/media/' . $_REQUEST['l'] . '/manuals/images/' . strtolower($filename);
     $image_destination_dir = $xml_source_path . '/' . $_REQUEST['l'] . '/images';
-    mkAllDir($image_destination_dir, 0755);
+    mkAllDir($image_destination_dir);
     $image_destination_path = $image_destination_dir . '/' . $filename;
     if (copy($image_source_path, $image_destination_path))
     {
       echo '[copying file: ' . $filename . "] \n";
+      chmod($image_destination_path, 0664);
     }
     else
