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
11require_once('tiki-setup.php');
12
13$sheetlib = TikiLib::lib("sheet");
14
15$access->check_feature('feature_sheet');
16
17$auto_query_args = ['sheetId'];
18
19$cookietab = 2;
20if (! isset($_REQUEST["sheetId"])) {
21	$cookietab = 1;
22	$_REQUEST["sheetId"] = 0;
23	$info = [];
24	$smarty->assign('headtitle', tra('Spreadsheets'));
25} else {
26	if (isset($_REQUEST['edit_mode']) && $_REQUEST['edit_mode'] == 1) {
27		$cookietab = 2;
28	}
29	$info = $sheetlib->get_sheet_info($_REQUEST["sheetId"]);
30	if ($tiki_p_admin == 'y' || $tiki_p_admin_sheet == 'y' || $tikilib->user_has_perm_on_object($user, $_REQUEST['sheetId'], 'sheet', 'tiki_p_view_sheet')) {
31		$tiki_p_view_sheet = 'y';
32	} else {
33		$tiki_p_view_sheet = 'n';
34	}
35	$smarty->assign('tiki_p_view_sheet', $tiki_p_view_sheet);
36	if ($tiki_p_admin == 'y' || $tiki_p_admin_sheet == 'y' || ($user && $user == $info['author']) || $tikilib->user_has_perm_on_object($user, $_REQUEST['sheetId'], 'sheet', 'tiki_p_edit_sheet')) {
37		$tiki_p_edit_sheet = 'y';
38	} else {
39		$tiki_p_edit_sheet = 'n';
40	}
41	$smarty->assign('tiki_p_edit_sheet', $tiki_p_edit_sheet);
42	if ($tiki_p_admin == 'y' || $tiki_p_admin_sheet == 'y' || ($user && $user == $info['author']) || $tikilib->user_has_perm_on_object($user, $_REQUEST['sheetId'], 'sheet', 'tiki_p_view_sheet_history')) {
43		$tiki_p_view_sheet_history = 'y';
44	} else {
45		$tiki_p_view_sheet_history = 'n';
46	}
47	$smarty->assign('tiki_p_view_sheet_history', $tiki_p_view_sheet_history);
48	$smarty->assign('headtitle', tra('Spreadsheet - ') . $info['title']);
49}
50
51$access->check_permission('tiki_p_view_sheet');
52
53if (isset($_REQUEST["find"])) {
54	$find = $_REQUEST["find"];
55} else {
56	$find = '';
57}
58$smarty->assign('find', $find);
59$smarty->assign('sheetId', $_REQUEST["sheetId"]);
60// Init smarty variables to blank values
61$smarty->assign('title', '');
62$smarty->assign('description', '');
63$smarty->assign('edit_mode', 'n');
64$smarty->assign('chart_enabled', (function_exists('imagepng') || function_exists('pdf_new')) ? 'y' : 'n');
65// If we are editing an existing sheet prepare smarty variables
66if (isset($_REQUEST["edit_mode"]) && $_REQUEST["edit_mode"]) {
67	$access->check_permission('tiki_p_edit_sheet');
68	check_ticket('sheet');
69	// Get information about this sheetId and fill smarty variables
70	$smarty->assign('edit_mode', 'y');
71	if ($_REQUEST["sheetId"] > 0) {
72		$smarty->assign('title', $info["title"]);
73		$smarty->assign('description', $info["description"]);
74		$smarty->assign('creator', $info['author']);
75		$smarty->assign('parentSheetId', isset($info['parentSheetId']) ? $info['parentSheetId'] : 0);
76		$info = $sheetlib->get_sheet_layout($_REQUEST["sheetId"]);
77		$smarty->assign('className', $info["className"]);
78		$smarty->assign('headerRow', $info["headerRow"]);
79		$smarty->assign('footerRow', $info["footerRow"]);
80		$smarty->assign('parseValues', $info["parseValues"]);
81	} else {
82		$smarty->assign('className', 'default');
83		$smarty->assign('headerRow', '0');
84		$smarty->assign('footerRow', '0');
85		$smarty->assign('parseValues', 'n');
86		$smarty->assign('creator', $user);
87		$smarty->assign('parentSheetId', 0);
88	}
89}
90$cat_type = 'sheet';
91
92// Process the insertion or modification of a sheet here
93if (isset($_REQUEST["edit"])) {
94	$access->check_permission('tiki_p_edit_sheet');
95	check_ticket('sheet');
96	// Everything is ok so we proceed to edit the gallery
97	$smarty->assign('edit_mode', 'y');
98	$smarty->assign_by_ref('title', $_REQUEST["title"]);
99	$smarty->assign_by_ref('description', $_REQUEST["description"]);
100	$smarty->assign_by_ref('className', $_REQUEST["className"]);
101	$smarty->assign_by_ref('headerRow', $_REQUEST["headerRow"]);
102	$smarty->assign_by_ref('footerRow', $_REQUEST["footerRow"]);
103	if (isset($_REQUEST['parseValues'])) {
104		$_REQUEST['parseValues'] = 'y';
105	} else {
106		$_REQUEST['parseValues'] = 'n';
107	}
108	$smarty->assign_by_ref('parseValues', $_REQUEST['parseValues']);
109	$gid = $sheetlib->replace_sheet(
110		$_REQUEST["sheetId"],
111		$_REQUEST["title"],
112		$_REQUEST["description"],
113		isset($_REQUEST['creator']) ? $_REQUEST['creator'] : $user,
114		$_REQUEST['parentSheetId'],
115		$_REQUEST
116	);
117	$cat_objid = $gid;
118	$cat_desc = substr($_REQUEST["description"], 0, 200);
119	$cat_name = $_REQUEST["title"];
120	$cat_href = "tiki-view_sheets.php?sheetId=" . $cat_objid;
121	include_once("categorize.php");
122	$smarty->assign('edit_mode', 'n');
123}
124if (isset($_REQUEST["removesheet"])) {
125	$access->check_permission('tiki_p_edit_sheet');
126	$access->check_authenticity(tra("Are you sure you want to delete this spreadsheet?"));
127	$sheetlib->remove_sheet($_REQUEST["sheetId"]);
128	header("Location: tiki-sheets.php");
129}
130$cat_objid = $_REQUEST['sheetId'];
131include_once('categorize_list.php');
132
133if (! isset($_REQUEST["sort_mode"])) {
134	$sort_mode = 'title_asc';
135} else {
136	$sort_mode = $_REQUEST["sort_mode"];
137}
138$smarty->assign_by_ref('sort_mode', $sort_mode);
139// If offset is set use it if not then use offset =0
140// use the maxRecords php variable to set the limit
141// if sortMode is not set then use lastModif_desc
142if (! isset($_REQUEST["offset"])) {
143	$offset = 0;
144} else {
145	$offset = $_REQUEST["offset"];
146}
147$smarty->assign_by_ref('offset', $offset);
148// Get the list of sheets available for this user (or public galleries)
149$sheets = $sheetlib->list_sheets($offset, $maxRecords, $sort_mode, $find);
150$smarty->assign_by_ref('cant_pages', $sheets["cant"]);
151$smarty->assign_by_ref('sheets', $sheets["data"]);
152
153include_once('tiki-section_options.php');
154ask_ticket('sheet');
155// Display the template
156$smarty->assign('mid', 'tiki-sheets.tpl');
157$smarty->display("tiki.tpl");
158