1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-05-15 20:53:08 +0000 (Mon, 15 May 2006) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 1308 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | /** |
---|
29 | * Management of elements set. Elements can belong to a category or to the |
---|
30 | * user caddie. |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | if (!defined('PHPWG_ROOT_PATH')) |
---|
35 | { |
---|
36 | die('Hacking attempt!'); |
---|
37 | } |
---|
38 | |
---|
39 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
40 | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | // | Check Access and exit when user status is not ok | |
---|
43 | // +-----------------------------------------------------------------------+ |
---|
44 | check_status(ACCESS_ADMINISTRATOR); |
---|
45 | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | // | global mode form submission | |
---|
48 | // +-----------------------------------------------------------------------+ |
---|
49 | |
---|
50 | if (isset($_POST['submit'])) |
---|
51 | { |
---|
52 | $collection = array(); |
---|
53 | |
---|
54 | // echo '<pre>'; |
---|
55 | // print_r($_POST); |
---|
56 | // echo '</pre>'; |
---|
57 | // exit(); |
---|
58 | |
---|
59 | switch ($_POST['target']) |
---|
60 | { |
---|
61 | case 'all' : |
---|
62 | { |
---|
63 | $collection = $page['cat_elements_id']; |
---|
64 | break; |
---|
65 | } |
---|
66 | case 'selection' : |
---|
67 | { |
---|
68 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
69 | { |
---|
70 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | $collection = $_POST['selection']; |
---|
75 | } |
---|
76 | break; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | if (isset($_POST['add_tags']) and count($collection) > 0) |
---|
81 | { |
---|
82 | add_tags($_POST['add_tags'], $collection); |
---|
83 | } |
---|
84 | |
---|
85 | if (isset($_POST['del_tags']) and count($collection) > 0) |
---|
86 | { |
---|
87 | $query = ' |
---|
88 | DELETE |
---|
89 | FROM '.IMAGE_TAG_TABLE.' |
---|
90 | WHERE image_id IN ('.implode(',', $collection).') |
---|
91 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
92 | ;'; |
---|
93 | pwg_query($query); |
---|
94 | } |
---|
95 | |
---|
96 | if ($_POST['associate'] != 0 and count($collection) > 0) |
---|
97 | { |
---|
98 | associate_images_to_categories( |
---|
99 | $collection, |
---|
100 | array($_POST['associate']) |
---|
101 | ); |
---|
102 | } |
---|
103 | |
---|
104 | if ($_POST['dissociate'] != 0 and count($collection) > 0) |
---|
105 | { |
---|
106 | // physical links must not be broken, so we must first retrieve image_id |
---|
107 | // which create virtual links with the category to "dissociate from". |
---|
108 | $query = ' |
---|
109 | SELECT id |
---|
110 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
111 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
112 | WHERE category_id = '.$_POST['dissociate'].' |
---|
113 | AND id IN ('.implode(',', $collection).') |
---|
114 | AND category_id != storage_category_id |
---|
115 | ;'; |
---|
116 | $dissociables = array_from_query($query, 'id'); |
---|
117 | |
---|
118 | $query = ' |
---|
119 | DELETE |
---|
120 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
121 | WHERE category_id = '.$_POST['dissociate'].' |
---|
122 | AND image_id IN ('.implode(',', $dissociables).') |
---|
123 | '; |
---|
124 | pwg_query($query); |
---|
125 | |
---|
126 | update_category($_POST['dissociate']); |
---|
127 | } |
---|
128 | |
---|
129 | $datas = array(); |
---|
130 | $dbfields = array('primary' => array('id'), 'update' => array()); |
---|
131 | |
---|
132 | $formfields = array('author', 'name', 'date_creation'); |
---|
133 | foreach ($formfields as $formfield) |
---|
134 | { |
---|
135 | if ($_POST[$formfield.'_action'] != 'leave') |
---|
136 | { |
---|
137 | array_push($dbfields['update'], $formfield); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | // updating elements is useful only if needed... |
---|
142 | if (count($dbfields['update']) > 0 and count($collection) > 0) |
---|
143 | { |
---|
144 | $query = ' |
---|
145 | SELECT id |
---|
146 | FROM '.IMAGES_TABLE.' |
---|
147 | WHERE id IN ('.implode(',', $collection).') |
---|
148 | ;'; |
---|
149 | $result = pwg_query($query); |
---|
150 | |
---|
151 | while ($row = mysql_fetch_array($result)) |
---|
152 | { |
---|
153 | $data = array(); |
---|
154 | $data['id'] = $row['id']; |
---|
155 | |
---|
156 | if ('set' == $_POST['author_action']) |
---|
157 | { |
---|
158 | $data['author'] = $_POST['author']; |
---|
159 | |
---|
160 | if ('' == $data['author']) |
---|
161 | { |
---|
162 | unset($data['author']); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | if ('set' == $_POST['name_action']) |
---|
167 | { |
---|
168 | $data['name'] = $_POST['name']; |
---|
169 | |
---|
170 | if ('' == $data['name']) |
---|
171 | { |
---|
172 | unset($data['name']); |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | if ('set' == $_POST['date_creation_action']) |
---|
177 | { |
---|
178 | $data['date_creation'] = |
---|
179 | $_POST['date_creation_year'] |
---|
180 | .'-'.$_POST['date_creation_month'] |
---|
181 | .'-'.$_POST['date_creation_day'] |
---|
182 | ; |
---|
183 | } |
---|
184 | |
---|
185 | array_push($datas, $data); |
---|
186 | } |
---|
187 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
188 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | // +-----------------------------------------------------------------------+ |
---|
193 | // | template init | |
---|
194 | // +-----------------------------------------------------------------------+ |
---|
195 | $template->set_filenames( |
---|
196 | array('element_set_global' => 'admin/element_set_global.tpl')); |
---|
197 | |
---|
198 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
199 | |
---|
200 | // $form_action = $base_url.'?page=element_set_global'; |
---|
201 | |
---|
202 | $template->assign_vars( |
---|
203 | array( |
---|
204 | 'CATEGORIES_NAV'=>$page['title'], |
---|
205 | |
---|
206 | 'L_SUBMIT'=>$lang['submit'], |
---|
207 | |
---|
208 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
209 | |
---|
210 | 'U_UNIT_MODE' |
---|
211 | => |
---|
212 | $base_url |
---|
213 | .get_query_string_diff(array('mode','display')) |
---|
214 | .'&mode=unit', |
---|
215 | |
---|
216 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
217 | ) |
---|
218 | ); |
---|
219 | |
---|
220 | // +-----------------------------------------------------------------------+ |
---|
221 | // | caddie options | |
---|
222 | // +-----------------------------------------------------------------------+ |
---|
223 | |
---|
224 | if ('caddie' == $_GET['cat']) |
---|
225 | { |
---|
226 | $template->assign_block_vars('in_caddie', array()); |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | $template->assign_block_vars('not_in_caddie', array()); |
---|
231 | } |
---|
232 | |
---|
233 | // +-----------------------------------------------------------------------+ |
---|
234 | // | global mode form | |
---|
235 | // +-----------------------------------------------------------------------+ |
---|
236 | |
---|
237 | // Virtualy associate a picture to a category |
---|
238 | $blockname = 'associate_option'; |
---|
239 | |
---|
240 | $template->assign_block_vars( |
---|
241 | $blockname, |
---|
242 | array('SELECTED' => '', |
---|
243 | 'VALUE'=> 0, |
---|
244 | 'OPTION' => '------------' |
---|
245 | )); |
---|
246 | |
---|
247 | $query = ' |
---|
248 | SELECT id,name,uppercats,global_rank |
---|
249 | FROM '.CATEGORIES_TABLE.' |
---|
250 | ;'; |
---|
251 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
252 | |
---|
253 | // Dissociate from a category : categories listed for dissociation can |
---|
254 | // only represent virtual links. Links to physical categories can't be |
---|
255 | // broken |
---|
256 | $blockname = 'dissociate_option'; |
---|
257 | |
---|
258 | $template->assign_block_vars( |
---|
259 | $blockname, |
---|
260 | array('SELECTED' => '', |
---|
261 | 'VALUE'=> 0, |
---|
262 | 'OPTION' => '------------' |
---|
263 | )); |
---|
264 | |
---|
265 | if (count($page['cat_elements_id']) > 0) |
---|
266 | { |
---|
267 | $query = ' |
---|
268 | SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank |
---|
269 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic, |
---|
270 | '.CATEGORIES_TABLE.' AS c, |
---|
271 | '.IMAGES_TABLE.' AS i |
---|
272 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
273 | AND ic.category_id = c.id |
---|
274 | AND ic.image_id = i.id |
---|
275 | AND ic.category_id != i.storage_category_id |
---|
276 | ;'; |
---|
277 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
278 | } |
---|
279 | |
---|
280 | // add tags |
---|
281 | $template->assign_vars( |
---|
282 | array( |
---|
283 | 'ADD_TAG_SELECTION' => get_html_tag_selection(get_all_tags(), 'add_tags'), |
---|
284 | ) |
---|
285 | ); |
---|
286 | |
---|
287 | if (count($page['cat_elements_id']) > 0) |
---|
288 | { |
---|
289 | // remove tags |
---|
290 | $query = ' |
---|
291 | SELECT tag_id, name, url_name, count(*) counter |
---|
292 | FROM '.IMAGE_TAG_TABLE.' |
---|
293 | INNER JOIN '.TAGS_TABLE.' ON tag_id = id |
---|
294 | WHERE image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
295 | GROUP BY tag_id |
---|
296 | ORDER BY name ASC |
---|
297 | ;'; |
---|
298 | $result = pwg_query($query); |
---|
299 | |
---|
300 | $tags = array(); |
---|
301 | while($row = mysql_fetch_array($result)) |
---|
302 | { |
---|
303 | array_push($tags, $row); |
---|
304 | } |
---|
305 | |
---|
306 | $template->assign_vars( |
---|
307 | array( |
---|
308 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
309 | ) |
---|
310 | ); |
---|
311 | } |
---|
312 | // creation date |
---|
313 | $day = |
---|
314 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
315 | get_day_list('date_creation_day', $day); |
---|
316 | |
---|
317 | if (!empty($_POST['date_creation_month'])) |
---|
318 | { |
---|
319 | $month = $_POST['date_creation_month']; |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | $month = date('n'); |
---|
324 | } |
---|
325 | get_month_list('date_creation_month', $month); |
---|
326 | |
---|
327 | if (!empty($_POST['date_creation_year'])) |
---|
328 | { |
---|
329 | $year = $_POST['date_creation_year']; |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | $year = date('Y'); |
---|
334 | } |
---|
335 | $template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year)); |
---|
336 | |
---|
337 | // +-----------------------------------------------------------------------+ |
---|
338 | // | global mode thumbnails | |
---|
339 | // +-----------------------------------------------------------------------+ |
---|
340 | |
---|
341 | // how many items to display on this page |
---|
342 | if (!empty($_GET['display'])) |
---|
343 | { |
---|
344 | if ('all' == $_GET['display']) |
---|
345 | { |
---|
346 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
347 | } |
---|
348 | else |
---|
349 | { |
---|
350 | $page['nb_images'] = intval($_GET['display']); |
---|
351 | } |
---|
352 | } |
---|
353 | else |
---|
354 | { |
---|
355 | $page['nb_images'] = 20; |
---|
356 | } |
---|
357 | |
---|
358 | if (count($page['cat_elements_id']) > 0) |
---|
359 | { |
---|
360 | $nav_bar = create_navigation_bar( |
---|
361 | $base_url.get_query_string_diff(array('start')), |
---|
362 | count($page['cat_elements_id']), |
---|
363 | $page['start'], |
---|
364 | $page['nb_images'] |
---|
365 | ); |
---|
366 | $template->assign_vars(array('NAV_BAR' => $nav_bar)); |
---|
367 | |
---|
368 | $query = ' |
---|
369 | SELECT id,path,tn_ext |
---|
370 | FROM '.IMAGES_TABLE.' |
---|
371 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
372 | '.$conf['order_by'].' |
---|
373 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
---|
374 | ;'; |
---|
375 | //echo '<pre>'.$query.'</pre>'; |
---|
376 | $result = pwg_query($query); |
---|
377 | |
---|
378 | // template thumbnail initialization |
---|
379 | if (mysql_num_rows($result) > 0) |
---|
380 | { |
---|
381 | $template->assign_block_vars('thumbnails', array()); |
---|
382 | } |
---|
383 | |
---|
384 | while ($row = mysql_fetch_array($result)) |
---|
385 | { |
---|
386 | $src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
387 | |
---|
388 | $template->assign_block_vars( |
---|
389 | 'thumbnails.thumbnail', |
---|
390 | array( |
---|
391 | 'ID' => $row['id'], |
---|
392 | 'SRC' => $src, |
---|
393 | 'ALT' => 'TODO', |
---|
394 | 'TITLE' => 'TODO' |
---|
395 | ) |
---|
396 | ); |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | //----------------------------------------------------------- sending html code |
---|
401 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
402 | ?> |
---|