1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | // +-----------------------------------------------------------------------+ |
---|
24 | // | PhpWebGallery - a PHP based picture gallery | |
---|
25 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
26 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | file : $Id: element_set.php 2297 2008-04-04 22:57:23Z plg $ |
---|
29 | // | last update : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $ |
---|
30 | // | last modifier : $Author: plg $ |
---|
31 | // | revision : $Revision: 2297 $ |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | This program is free software; you can redistribute it and/or modify | |
---|
34 | // | it under the terms of the GNU General Public License as published by | |
---|
35 | // | the Free Software Foundation | |
---|
36 | // | | |
---|
37 | // | This program is distributed in the hope that it will be useful, but | |
---|
38 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
39 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
40 | // | General Public License for more details. | |
---|
41 | // | | |
---|
42 | // | You should have received a copy of the GNU General Public License | |
---|
43 | // | along with this program; if not, write to the Free Software | |
---|
44 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
45 | // | USA. | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | /** |
---|
49 | * Management of elements set. Elements can belong to a category or to the |
---|
50 | * user caddie. |
---|
51 | * |
---|
52 | */ |
---|
53 | |
---|
54 | if (!defined('PHPWG_ROOT_PATH')) |
---|
55 | { |
---|
56 | die('Hacking attempt!'); |
---|
57 | } |
---|
58 | |
---|
59 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
60 | |
---|
61 | // +-----------------------------------------------------------------------+ |
---|
62 | // | Check Access and exit when user status is not ok | |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | check_status(ACCESS_ADMINISTRATOR); |
---|
65 | |
---|
66 | // +-----------------------------------------------------------------------+ |
---|
67 | // | caddie management | |
---|
68 | // +-----------------------------------------------------------------------+ |
---|
69 | |
---|
70 | if (isset($_POST['submit_caddie'])) |
---|
71 | { |
---|
72 | if (isset($_POST['caddie_action'])) |
---|
73 | { |
---|
74 | switch ($_POST['caddie_action']) |
---|
75 | { |
---|
76 | case 'empty_all' : |
---|
77 | { |
---|
78 | $query = ' |
---|
79 | DELETE FROM '.CADDIE_TABLE.' |
---|
80 | WHERE user_id = '.$user['id'].' |
---|
81 | ;'; |
---|
82 | pwg_query($query); |
---|
83 | break; |
---|
84 | } |
---|
85 | case 'empty_selected' : |
---|
86 | { |
---|
87 | if (isset($_POST['selection']) and count($_POST['selection']) > 0) |
---|
88 | { |
---|
89 | $query = ' |
---|
90 | DELETE |
---|
91 | FROM '.CADDIE_TABLE.' |
---|
92 | WHERE element_id IN ('.implode(',', $_POST['selection']).') |
---|
93 | AND user_id = '.$user['id'].' |
---|
94 | ;'; |
---|
95 | pwg_query($query); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | // TODO : add error |
---|
100 | } |
---|
101 | break; |
---|
102 | } |
---|
103 | case 'add_selected' : |
---|
104 | { |
---|
105 | if (isset($_POST['selection']) and count($_POST['selection']) > 0) |
---|
106 | { |
---|
107 | fill_caddie($_POST['selection']); |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | // TODO : add error |
---|
112 | } |
---|
113 | break; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | // TODO : add error |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | // +-----------------------------------------------------------------------+ |
---|
124 | // | initialize info about category | |
---|
125 | // +-----------------------------------------------------------------------+ |
---|
126 | |
---|
127 | // To element_set_(global|unit).php, we must provide the elements id of the |
---|
128 | // managed category in $page['cat_elements_id'] array. |
---|
129 | |
---|
130 | if (is_numeric($_GET['cat'])) |
---|
131 | { |
---|
132 | $page['title'] = |
---|
133 | get_cat_display_name_from_id( |
---|
134 | $_GET['cat'], |
---|
135 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=', |
---|
136 | false |
---|
137 | ); |
---|
138 | |
---|
139 | $query = ' |
---|
140 | SELECT image_id |
---|
141 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
142 | WHERE category_id = '.$_GET['cat'].' |
---|
143 | ;'; |
---|
144 | $page['cat_elements_id'] = array_from_query($query, 'image_id'); |
---|
145 | } |
---|
146 | else if ('caddie' == $_GET['cat']) |
---|
147 | { |
---|
148 | $page['title'] = l10n('caddie'); |
---|
149 | |
---|
150 | $query = ' |
---|
151 | SELECT element_id |
---|
152 | FROM '.CADDIE_TABLE.' |
---|
153 | WHERE user_id = '.$user['id'].' |
---|
154 | ;'; |
---|
155 | $page['cat_elements_id'] = array_from_query($query, 'element_id'); |
---|
156 | } |
---|
157 | else if ('not_linked' == $_GET['cat']) |
---|
158 | { |
---|
159 | $page['title'] = l10n('Elements_not_linked'); |
---|
160 | |
---|
161 | // we are searching elements not linked to any virtual category |
---|
162 | $query = ' |
---|
163 | SELECT id |
---|
164 | FROM '.CATEGORIES_TABLE.' |
---|
165 | WHERE dir IS NULL |
---|
166 | ;'; |
---|
167 | $virtual_categories = array_from_query($query, 'id'); |
---|
168 | |
---|
169 | if (!empty($virtual_categories)) |
---|
170 | { |
---|
171 | $query = ' |
---|
172 | SELECT DISTINCT(image_id) |
---|
173 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
174 | ;'; |
---|
175 | $all_elements = array_from_query($query, 'image_id'); |
---|
176 | |
---|
177 | $query = ' |
---|
178 | SELECT DISTINCT(image_id) |
---|
179 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
180 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
181 | ;'; |
---|
182 | $linked_to_virtual = array_from_query($query, 'image_id'); |
---|
183 | |
---|
184 | $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual); |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | $page['cat_elements_id'] = array(); |
---|
189 | } |
---|
190 | } |
---|
191 | else if ('duplicates' == $_GET['cat']) |
---|
192 | { |
---|
193 | $page['title'] = l10n('Duplicates'); |
---|
194 | |
---|
195 | // we are searching related elements twice or more to physical categories |
---|
196 | // 1 - Retrieve Files |
---|
197 | $query = ' |
---|
198 | SELECT DISTINCT(file) |
---|
199 | FROM '.IMAGES_TABLE.' |
---|
200 | GROUP BY file |
---|
201 | HAVING COUNT(DISTINCT storage_category_id) > 1 |
---|
202 | ;'; |
---|
203 | |
---|
204 | $duplicate_files = array_from_query($query, 'file'); |
---|
205 | $duplicate_files[]='Nofiles'; |
---|
206 | // 2 - Retrives related picture ids |
---|
207 | $query = ' |
---|
208 | SELECT id, file |
---|
209 | FROM '.IMAGES_TABLE.' |
---|
210 | WHERE file IN (\''.implode("','", $duplicate_files).'\') |
---|
211 | ORDER BY file, id |
---|
212 | ;'; |
---|
213 | |
---|
214 | $page['cat_elements_id'] = array_from_query($query, 'id'); |
---|
215 | $page['cat_elements_id'][] = 0; |
---|
216 | } |
---|
217 | // +-----------------------------------------------------------------------+ |
---|
218 | // | first element to display | |
---|
219 | // +-----------------------------------------------------------------------+ |
---|
220 | |
---|
221 | // $page['start'] contains the number of the first element in its |
---|
222 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
223 | // and $page['nb_images'] next elements |
---|
224 | |
---|
225 | if (!isset($_GET['start']) |
---|
226 | or !is_numeric($_GET['start']) |
---|
227 | or $_GET['start'] < 0 |
---|
228 | or (isset($_GET['display']) and 'all' == $_GET['display'])) |
---|
229 | { |
---|
230 | $page['start'] = 0; |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | $page['start'] = $_GET['start']; |
---|
235 | } |
---|
236 | |
---|
237 | // +-----------------------------------------------------------------------+ |
---|
238 | // | open specific mode | |
---|
239 | // +-----------------------------------------------------------------------+ |
---|
240 | |
---|
241 | $_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global'; |
---|
242 | |
---|
243 | switch ($_GET['mode']) |
---|
244 | { |
---|
245 | case 'global' : |
---|
246 | { |
---|
247 | include(PHPWG_ROOT_PATH.'admin/element_set_global.php'); |
---|
248 | break; |
---|
249 | } |
---|
250 | case 'unit' : |
---|
251 | { |
---|
252 | include(PHPWG_ROOT_PATH.'admin/element_set_unit.php'); |
---|
253 | break; |
---|
254 | } |
---|
255 | } |
---|
256 | ?> |
---|