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.
11 // | There are only two ways to violate the license:
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).
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).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
30 import('ttExportHelper');
31 import('ttOrgExportHelper');
35 if (!ttAccessAllowed('export_data')) {
36 header('Location: access_denied.php');
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');
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')));
49 if ($request->isPost()) {
51 $filename = 'group_data.xml';
52 $mime_type = 'text/xml';
54 if ('bzip' == $cl_compression) {
57 $mime_type = 'application/x-bzip2';
60 //if (defined('SUBGROUP_DEBUG') && isTrue(SUBGROUP_DEBUG)) {
61 $exportHelper = new ttOrgExportHelper();
63 // $exportHelper = new ttExportHelper();
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);
73 if ($file_pointer = fopen($exportHelper->getFileName(), 'r')) {
74 while ($data = fread($file_pointer, 4096)) {
77 fclose($file_pointer);
78 unlink($exportHelper->getFileName());
82 $err->add($i18n->get('error.sys'));
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');