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 = 'galleries';
12require_once('tiki-setup.php');
13$categlib = TikiLib::lib('categ');
14$imagegallib = TikiLib::lib('imagegal');
15$access->check_feature('feature_galleries');
16if (empty($_REQUEST["galleryId"]) && $_REQUEST["galleryId"] != '0') {
17	$smarty->assign('msg', tra("No gallery indicated"));
18	$smarty->display("error.tpl");
19	die;
20}
21if ($_REQUEST["galleryId"] != '0' && $imagegallib->get_gallery($_REQUEST["galleryId"]) === false) {
22	$smarty->assign('msg', tra("This gallery does not exist"));
23	$smarty->display("error.tpl");
24	die;
25}
26
27$tikilib->get_perm_object($_REQUEST['galleryId'], 'image gallery');
28$access->check_permission('tiki_p_view_image_gallery');
29/*
30if ($tiki_p_upload_images != 'y') {
31$smarty->assign('errortype', 401);
32$smarty->assign('msg',tra("You do not have permission to upload images"));
33$smarty->display("error.tpl");
34die;
35}
36*/
37if ($_REQUEST["galleryId"] != 0) {
38	// To browse the gallery the user has to be admin, the owner or the gallery has to be public
39	$gal_info = $imagegallib->get_gallery($_REQUEST["galleryId"]);
40	//$smarty->assign_by_ref('theme',$gal_info["theme"]);
41	//$smarty->assign('use_theme','y');
42	/*
43	if ( $tiki_p_admin != 'y' && $user!=$gal_info["user"] && $gal_info["public"]!='y') {
44	$smarty->assign('errortype', 401);
45	$smarty->assign('msg',tra("You do not have permission to browse this gallery"));
46	$smarty->display("error.tpl");
47	die;
48	}
49	*/
50} else {
51	$gal_info["galleryId"] = 0;
52	$gal_info["user"] = 'admin';
53	$gal_info["name"] = tra('System');
54	$gal_info["public"] = 'y';
55	$gal_info["description"] = tra('System Gallery');
56	$gal_info["sortdirection"] = 'desc';
57	$gal_info["sortorder"] = 'created';
58}
59$smarty->assign_by_ref('owner', $gal_info["user"]);
60$smarty->assign_by_ref('public', $gal_info["public"]);
61$smarty->assign_by_ref('galleryId', $_REQUEST["galleryId"]);
62$imagegallib->add_gallery_hit($_REQUEST["galleryId"]);
63if (isset($_REQUEST["remove"])) {
64	// To remove an image the user must be the owner or admin
65	if ($tiki_p_admin_galleries != 'y' && (! $user || $user != $gal_info["user"])) {
66		$smarty->assign('errortype', 401);
67		$smarty->assign('msg', tra("You do not have permission to remove images from this gallery"));
68		$smarty->display("error.tpl");
69		die;
70	}
71	$access->check_authenticity();
72	$imagegallib->remove_image($_REQUEST["remove"], $user);
73}
74if (isset($_REQUEST["rebuild"])) {
75	check_ticket('list-gal');
76	// To remove an image the user must be the owner or admin
77	if ($tiki_p_admin_galleries != 'y' && (! $user || $user != $gal_info["user"])) {
78		$smarty->assign('errortype', 401);
79		$smarty->assign('msg', tra("You do not have permission to remove images from this gallery"));
80		$smarty->display("error.tpl");
81		die;
82	}
83	$imagegallib->rebuild_thumbnails($_REQUEST["rebuild"]);
84}
85$smarty->assign('system', 'n');
86if ($_REQUEST["galleryId"] == 0) {
87	$info["thumbSizeX"] = 100;
88	$info["thumbSizeY"] = 100;
89	$info["galleryId"] = 0;
90	$info["user"] = 'admin';
91	$info["name"] = tra('System');
92	$info["public"] = 'y';
93	$info["description"] = tra('System Gallery');
94	$info["sortdirection"] = 'desc';
95	$info["sortorder"] = 'created';
96	$smarty->assign('system', 'y');
97} else {
98	$info = $imagegallib->get_gallery($_REQUEST["galleryId"]);
99}
100if (! isset($info["maxRows"])) {
101	$info["maxRows"] = 10;
102}
103if (! isset($info["rowImages"])) {
104	$info["rowImages"] = 5;
105}
106if ($info["maxRows"] == 0) {
107	$info["maxRows"] = 10;
108}
109if ($info["rowImages"] == 0) {
110	$info["rowImages"] = 6;
111}
112$maxRecords = $info["maxRows"] * $info["rowImages"];
113$smarty->assign_by_ref('rowImages', $info["rowImages"]);
114$smarty->assign('rowImages2', $info["rowImages"] - 1);
115$smarty->assign_by_ref('thx', $info["thumbSizeX"]);
116$smarty->assign_by_ref('thy', $info["thumbSizeY"]);
117$smarty->assign_by_ref('name', $info["name"]);
118$smarty->assign_by_ref('description', $info["description"]);
119if (! isset($_REQUEST["sort_mode"])) {
120	$sort_mode = $info['sortorder'] . '_' . $info['sortdirection'];
121} else {
122	$sort_mode = $_REQUEST["sort_mode"];
123}
124$smarty->assign_by_ref('sort_mode', $sort_mode);
125// If offset is set use it if not then use offset =0
126// use the maxRecords php variable to set the limit
127// if sortMode is not set then use lastModif_desc
128if (! isset($_REQUEST["offset"])) {
129	$offset = 0;
130} else {
131	$offset = $_REQUEST["offset"];
132}
133$smarty->assign_by_ref('offset', $offset);
134if (isset($_REQUEST["find"])) {
135	$find = $_REQUEST["find"];
136} else {
137	$find = '';
138}
139$images = $imagegallib->get_images($offset, $maxRecords, $sort_mode, $find, $_REQUEST["galleryId"]);
140$cant_pages = ceil($images["cant"] / $maxRecords);
141$smarty->assign_by_ref('cant_pages', $cant_pages);
142$smarty->assign('actual_page', 1 + ($offset / $maxRecords));
143if ($images["cant"] > ($offset + $maxRecords)) {
144	$smarty->assign('next_offset', $offset + $maxRecords);
145} else {
146	$smarty->assign('next_offset', -1);
147}
148// If offset is > 0 then prev_offset
149if ($offset > 0) {
150	$smarty->assign('prev_offset', $offset - $maxRecords);
151} else {
152	$smarty->assign('prev_offset', -1);
153}
154$smarty->assign_by_ref('images', $images["data"]);
155$smarty->assign_by_ref('cant', $images["cant"]);
156$cat_type = 'image gallery';
157$cat_objid = $_REQUEST["galleryId"];
158include_once('tiki-section_options.php');
159ask_ticket('list-gal');
160if ($prefs['feature_actionlog'] == 'y') {
161	$logslib->add_action('Viewed', $_REQUEST['galleryId'], 'image gallery');
162}
163// Display the template
164$smarty->assign('mid', 'tiki-list_gallery.tpl');
165$smarty->display("tiki.tpl");
166