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//this script may only be included - so its better to err & die if called directly.
12//smarty is not there - we need setup
13if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
14	header("location: index.php");
15	exit;
16}
17
18// Fill the display configuration array
19$fgal_listing_conf = [
20	'id' => ['name' => tra('ID')],
21	'type' => ['name' => tra('Type'), 'key' => 'show_icon'],
22	'name' => ['name' => tra('Name')],
23	'parentId' => ['name' => tra('Parent Gallery'), 'key' => 'parentId'],
24	'description' => ['name' => tra('Description')],
25	'size' => ['name' => tra('Size')],
26	'created' => ['name' => tra('Created') . ' / ' . tra('Uploaded')],
27	'lastModif' => ['name' => tra('Last modified'), 'key' => 'show_modified'],
28	'creator' => ['name' => tra('Uploaded by')], //this used to be Creator but updated Nov2010
29	'author' => ['name' => tra('Creator')],  //this used to be Author but updated Nov2010
30	'last_user' => ['name' => tra('Last modified by')], //this used to be 'Last editor' but updated Nov2010
31	'comment' => ['name' => tra('Comment')],
32	'files' => ['name' => tra('Files')],
33	'hits' => ['name' => tra('Hits')],
34	'lastDownload' => ['name' => tra('Last download')],
35	'lockedby' => ['name' => tra('Locked by'), 'icon' => 'lock'],
36	'ocr_state' => ['name' => tra('OCR Status')],
37	'backlinks' => ['name' => tra('Backlinks')],
38	'deleteAfter' => ['name' => tra('Delete after')],
39	'share' => ['name' => tra('Share')],
40	'source' => ['name' => tra('Source')],
41];
42
43if (isset($section) && $section == 'admin') {
44	foreach ($fgal_listing_conf as $k => $v) {
45		$fgal_listing_conf_admin[$k . '_admin'] = $v;
46	}
47}
48foreach ($fgal_listing_conf as $k => $v) {
49	if ($k == 'type') {
50		$show_k = 'icon';
51	} elseif ($k == 'lastModif') {
52		$show_k = 'modified';
53	} else {
54		$show_k = $k;
55	}
56
57	if (isset($_REQUEST['fgal_list_' . $k])) {
58		$fgal_listing_conf[$k]['value'] = $_REQUEST['fgal_list_' . $k];
59	} elseif (isset($gal_info) && isset($gal_info['show_' . $show_k])) {
60		$fgal_listing_conf[$k]['value'] = $gal_info['show_' . $show_k];
61	} else {
62		if (isset($prefs['fgal_list_' . $k])) {
63			$fgal_listing_conf[$k]['value'] = $prefs['fgal_list_' . $k];
64		}
65	}
66}
67// If feature_status is disabled remove hits field.
68if (isset($prefs) && $prefs['feature_stats'] != 'y') {
69	unset($fgal_listing_conf['hits']);
70}
71// Do not show "Locked by" info if the gallery is not lockable
72if (isset($gal_info) && isset($gal_info['galleryId']) && isset($gal_info['lockable']) && $gal_info['lockable'] != 'y') {
73	$fgal_listing_conf['lockedby']['value'] = 'n';
74}
75
76$smarty = TikiLib::lib('smarty');
77$smarty->assign_by_ref('fgal_listing_conf', $fgal_listing_conf);
78
79if (isset($section) && $section == 'admin') {
80	foreach ($fgal_listing_conf_admin as $k => $v) {
81		if (isset($prefs['fgal_list_' . $k])) {
82			$fgal_listing_conf_admin[$k]['value'] = $prefs['fgal_list_' . $k];
83		}
84	}
85	$smarty->assign_by_ref('fgal_listing_conf_admin', $fgal_listing_conf_admin);
86}
87
88$fgal_options = [
89	'show_explorer' => ['name' => tra('Explorer')],
90	'show_path' => ['name' => tra('Path')],
91	'show_slideshow' => ['name' => tra('Slideshow')],
92	'icon_fileId' => ['name' => tra('Gallery icon')],
93];
94
95if (! array_key_exists('view', get_defined_vars())) {
96	if (isset($_REQUEST['view'])) {
97		$view = $_REQUEST['view'];
98	} else {
99		$view = null;
100	}
101}
102if ($view == 'admin') {
103	$fgal_options['show_explorer'] = 'n';
104	$fgal_options['show_path'] = 'n';
105	$fgal_options['show_slideshow'] = 'n';
106	$fgal_options['default_view'] = 'list';
107	$fgal_options['icon_fileId'] = '';
108} else {
109	foreach ($fgal_options as $k_gal => $v) {
110		// Validate that option exists.
111		if (! isset($fgal_options[$k_gal])) {
112			continue;
113		}
114
115		$k_prefs = 'fgal_' . $k_gal;
116
117		if (isset($_REQUEST['edit_mode'])) {
118			// We are in the edit file gallery page
119			$fgal_options[$k_gal]['value'] = isset($gal_info[$k_gal]) ? $gal_info[$k_gal] : null;
120		} else {
121			// normal gallery view
122			$fgal_options[$k_gal]['value'] = ( isset($gal_info) && isset($gal_info[$k_gal]) ) ? $gal_info[$k_gal] : isset($prefs[$k_prefs]) ? $prefs[$k_prefs] : null;
123		}
124	}
125}
126
127$smarty->assign_by_ref('fgal_options', $fgal_options);
128