Rolling back old import-export due to a problem with undeclared entities during XML...
[timetracker.git] / export.php
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
10 // |
11 // | There are only two ways to violate the license:
12 // |
13 // | 1. To redistribute this code in source form, with the copyright
14 // |    notice or license removed or altered. (Distributing in compiled
15 // |    forms without embedded copyright notices is permitted).
16 // |
17 // | 2. To redistribute modified versions of this code in *any* form
18 // |    that bears insufficient indications that the modifications are
19 // |    not the work of the original author(s).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 require_once('initialize.php');
30 import('ttExportHelper');
31 import('ttOrgExportHelper');
32 import('form.Form');
33
34 // Access check.
35 if (!ttAccessAllowed('export_data')) {
36   header('Location: access_denied.php');
37   exit();
38 }
39
40 $cl_compression = $request->getParameter('compression');
41 $compressors = array('' => $i18n->get('form.export.compression_none'));
42 if (function_exists('bzcompress'))
43   $compressors['bzip'] = $i18n->get('form.export.compression_bzip');
44
45 $form = new Form('exportForm');
46 $form->addInput(array('type'=>'combobox','name'=>'compression','value'=>$cl_compression,'data'=>$compressors));
47 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.export')));
48
49 if ($request->isPost()) {
50
51   $filename = 'group_data.xml';
52   $mime_type = 'text/xml';
53   $compress = false;
54   if ('bzip' == $cl_compression) {
55     $compress = true;
56     $filename  .= '.bz2';
57     $mime_type = 'application/x-bzip2';
58   }
59
60   if (defined('SUBGROUP_DEBUG') && isTrue(SUBGROUP_DEBUG)) {
61     $exportHelper = new ttOrgExportHelper();
62   } else {
63       $exportHelper = new ttExportHelper();
64   }
65   if ($exportHelper->createDataFile($compress)) {
66     header('Pragma: public'); // This is needed for IE8 to download files over https.
67     header('Content-Type: '.$mime_type);
68     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
69     header('Content-Disposition: attachment; filename="'.$filename.'"');
70     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
71     header('Cache-Control: private', false);
72
73     if ($file_pointer = fopen($exportHelper->getFileName(), 'r')) {
74       while ($data = fread($file_pointer, 4096)) {
75         echo $data;
76       }
77       fclose($file_pointer);
78       unlink($exportHelper->getFileName());
79     }
80     exit;
81   } else
82     $err->add($i18n->get('error.sys'));
83 } // isPost
84
85 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
86 $smarty->assign('title', $i18n->get('title.export'));
87 $smarty->assign('content_page_name', 'export.tpl');
88 $smarty->display('index.tpl');