posaune
[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('ttOrgExportHelper');
31 import('form.Form');
32
33 // Access check.
34 if (!ttAccessAllowed('export_data')) {
35   header('Location: access_denied.php');
36   exit();
37 }
38
39 $cl_compression = $request->getParameter('compression');
40 $compressors = array('' => $i18n->get('form.export.compression_none'));
41 if (function_exists('bzcompress'))
42   $compressors['bzip'] = $i18n->get('form.export.compression_bzip');
43
44 $form = new Form('exportForm');
45 $form->addInput(array('type'=>'combobox','name'=>'compression','value'=>$cl_compression,'data'=>$compressors));
46 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.export')));
47
48 if ($request->isPost()) {
49
50   $filename = 'group_data.xml';
51   $mime_type = 'text/xml';
52   $compress = false;
53   if ('bzip' == $cl_compression) {
54     $compress = true;
55     $filename  .= '.bz2';
56     $mime_type = 'application/x-bzip2';
57   }
58
59   $exportHelper = new ttOrgExportHelper();
60   if ($exportHelper->createDataFile($compress)) {
61     header('Pragma: public'); // This is needed for IE8 to download files over https.
62     header('Content-Type: '.$mime_type);
63     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
64     header('Content-Disposition: attachment; filename="'.$filename.'"');
65     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
66     header('Cache-Control: private', false);
67
68     if ($file_pointer = fopen($exportHelper->getFileName(), 'r')) {
69       while ($data = fread($file_pointer, 4096)) {
70         echo $data;
71       }
72       fclose($file_pointer);
73       unlink($exportHelper->getFileName());
74     }
75     exit;
76   } else
77     $err->add($i18n->get('error.sys'));
78 } // isPost
79
80 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
81 $smarty->assign('title', $i18n->get('title.export'));
82 $smarty->assign('content_page_name', 'export.tpl');
83 $smarty->display('index.tpl');