1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11$section = 'sheet';
12require_once('tiki-setup.php');
13require_once('lib/sheet/grid.php');
14$sheetlib = TikiLib::lib('sheet');
15$auto_query_args = [
16	'sheetId',
17	'readdate',
18];
19
20$access->check_feature('feature_sheet');
21
22$info = TikiLib::lib("sheet")->get_sheet_info($_REQUEST['sheetId']);
23if (empty($info)) {
24	$smarty->assign('msg', tra('Incorrect parameter'));
25	$smarty->display('error.tpl');
26	die;
27}
28
29$objectperms = Perms::get('sheet', $_REQUEST['sheetId']);
30if ($tiki_p_admin != 'y' && ! $objectperms->view_sheet && ! ($user && $info['author'] == $user)) {
31	$smarty->assign('msg', tra('Permission denied'));
32	$smarty->display('error.tpl');
33	die;
34}
35
36$encoding = new Encoding();
37$charsetList = $encoding->get_input_supported_encodings();
38$smarty->assign_by_ref("charsets", $charsetList);
39
40$smarty->assign('title', $info['title']);
41$smarty->assign('description', $info['description']);
42
43$smarty->assign('page_mode', 'form');
44$smarty->assign('sheetId', $_REQUEST['sheetId']);
45
46// Process the insertion or modification of a gallery here
47$grid = new TikiSheet;
48
49$history = $sheetlib->sheet_history($_REQUEST['sheetId']);
50$smarty->assign_by_ref('history', $history);
51
52if (isset($_REQUEST['encoding'])) {
53	$smarty->assign('page_mode', 'submit');
54
55	$handler = new TikiSheetDatabaseHandler($_REQUEST['sheetId'], $_REQUEST['readdate']);
56	$grid->import($handler);
57
58	$handler = $_REQUEST['handler'];
59
60	if (! in_array($handler, TikiSheet::getHandlerList())) {
61		$smarty->assign('msg', "Handler is not allowed.");
62		$smarty->display("error.tpl");
63		die;
64	}
65
66	$handler = new $handler("php://stdout", 'UTF-8', $_REQUEST['encoding']);
67	$grid->export($handler);
68
69	header("Content-type: text/comma-separated-values");
70	header("Content-Disposition: attachment; filename=export.csv");
71	header("Expires: 0");
72	header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
73	header("Pragma: public");
74
75	echo $handler->output;
76	exit;
77} else {
78	$list = [];
79
80	$handlers = TikiSheet::getHandlerList();
81
82	foreach ($handlers as $key => $handler) {
83		$temp = new $handler;
84		if (! $temp->supports(TIKISHEET_SAVE_DATA | TIKISHEET_SAVE_CALC)) {
85			continue;
86		}
87
88		$list[$key] = [
89			"name" => $temp->name(),
90			"version" => $temp->version(),
91			"class" => $handler
92		];
93	}
94
95	$smarty->assign_by_ref("handlers", $list);
96}
97
98$cat_type = 'sheet';
99$cat_objid = $_REQUEST["sheetId"];
100include_once("categorize_list.php");
101
102include_once('tiki-section_options.php');
103ask_ticket('sheet');
104// Display the template
105$smarty->assign('mid', 'tiki-export-sheets.tpl');
106$smarty->display("tiki.tpl");
107