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: 2005-10-25 20:50:14 +0000 (Tue, 25 Oct 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 916 $ |
---|
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 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | functions | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | /** |
---|
45 | * returns the list of uniq keywords among given elements |
---|
46 | * |
---|
47 | * @param array element_ids |
---|
48 | */ |
---|
49 | function get_elements_keywords($element_ids) |
---|
50 | { |
---|
51 | if (0 == count($element_ids)) |
---|
52 | { |
---|
53 | return array(); |
---|
54 | } |
---|
55 | |
---|
56 | $keywords = array(); |
---|
57 | |
---|
58 | $query = ' |
---|
59 | SELECT keywords |
---|
60 | FROM '.IMAGES_TABLE.' |
---|
61 | WHERE id IN ('.implode(',', $element_ids).') |
---|
62 | ;'; |
---|
63 | $result = pwg_query($query); |
---|
64 | while ($row = mysql_fetch_array($result)) |
---|
65 | { |
---|
66 | if (isset($row['keywords']) and !empty($row['keywords'])) |
---|
67 | { |
---|
68 | $keywords = array_merge($keywords, explode(',', $row['keywords'])); |
---|
69 | } |
---|
70 | } |
---|
71 | return array_unique($keywords); |
---|
72 | } |
---|
73 | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | // | global mode form submission | |
---|
76 | // +-----------------------------------------------------------------------+ |
---|
77 | |
---|
78 | if (isset($_POST['submit'])) |
---|
79 | { |
---|
80 | $collection = array(); |
---|
81 | |
---|
82 | // echo '<pre>'; |
---|
83 | // print_r($_POST); |
---|
84 | // echo '</pre>'; |
---|
85 | // exit(); |
---|
86 | |
---|
87 | switch ($_POST['target']) |
---|
88 | { |
---|
89 | case 'all' : |
---|
90 | { |
---|
91 | $collection = $page['cat_elements_id']; |
---|
92 | break; |
---|
93 | } |
---|
94 | case 'selection' : |
---|
95 | { |
---|
96 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
97 | { |
---|
98 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | $collection = $_POST['selection']; |
---|
103 | } |
---|
104 | break; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | if ($_POST['associate'] != 0 and count($collection) > 0) |
---|
109 | { |
---|
110 | $datas = array(); |
---|
111 | |
---|
112 | $query = ' |
---|
113 | SELECT image_id |
---|
114 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
115 | WHERE category_id = '.$_POST['associate'].' |
---|
116 | ;'; |
---|
117 | $associated = array_from_query($query, 'image_id'); |
---|
118 | |
---|
119 | $associable = array_diff($collection, $associated); |
---|
120 | |
---|
121 | if (count($associable) != 0) |
---|
122 | { |
---|
123 | foreach ($associable as $item) |
---|
124 | { |
---|
125 | array_push( |
---|
126 | $datas, |
---|
127 | array( |
---|
128 | 'category_id' => $_POST['associate'], |
---|
129 | 'image_id' => $item |
---|
130 | ) |
---|
131 | ); |
---|
132 | } |
---|
133 | |
---|
134 | mass_inserts( |
---|
135 | IMAGE_CATEGORY_TABLE, |
---|
136 | array('image_id', 'category_id'), |
---|
137 | $datas |
---|
138 | ); |
---|
139 | |
---|
140 | update_category(array($_POST['associate'])); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | if ($_POST['dissociate'] != 0 and count($collection) > 0) |
---|
145 | { |
---|
146 | // physical links must not be broken, so we must first retrieve image_id |
---|
147 | // which create virtual links with the category to "dissociate from". |
---|
148 | $query = ' |
---|
149 | SELECT id |
---|
150 | FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
151 | WHERE category_id = '.$_POST['dissociate'].' |
---|
152 | AND category_id != storage_category_id |
---|
153 | AND id IN ('.implode(',', $collection).') |
---|
154 | ;'; |
---|
155 | $dissociables = array_from_query($query, 'id'); |
---|
156 | |
---|
157 | $query = ' |
---|
158 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
159 | WHERE category_id = '.$_POST['dissociate'].' |
---|
160 | AND image_id IN ('.implode(',', $dissociables).') |
---|
161 | '; |
---|
162 | pwg_query($query); |
---|
163 | |
---|
164 | update_category(array($_POST['dissociate'])); |
---|
165 | } |
---|
166 | |
---|
167 | $datas = array(); |
---|
168 | $dbfields = array('primary' => array('id'), 'update' => array()); |
---|
169 | |
---|
170 | if (!empty($_POST['add_keywords']) or $_POST['remove_keyword'] != '0') |
---|
171 | { |
---|
172 | array_push($dbfields['update'], 'keywords'); |
---|
173 | } |
---|
174 | |
---|
175 | $formfields = array('author', 'name', 'date_creation'); |
---|
176 | foreach ($formfields as $formfield) |
---|
177 | { |
---|
178 | if ($_POST[$formfield.'_action'] != 'leave') |
---|
179 | { |
---|
180 | array_push($dbfields['update'], $formfield); |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | // updating elements is useful only if needed... |
---|
185 | if (count($dbfields['update']) > 0 and count($collection) > 0) |
---|
186 | { |
---|
187 | $query = ' |
---|
188 | SELECT id, keywords |
---|
189 | FROM '.IMAGES_TABLE.' |
---|
190 | WHERE id IN ('.implode(',', $collection).') |
---|
191 | ;'; |
---|
192 | $result = pwg_query($query); |
---|
193 | |
---|
194 | while ($row = mysql_fetch_array($result)) |
---|
195 | { |
---|
196 | $data = array(); |
---|
197 | $data['id'] = $row['id']; |
---|
198 | |
---|
199 | if (!empty($_POST['add_keywords'])) |
---|
200 | { |
---|
201 | $data['keywords'] = |
---|
202 | implode( |
---|
203 | ',', |
---|
204 | array_unique( |
---|
205 | array_merge( |
---|
206 | get_keywords(empty($row['keywords']) ? '' : $row['keywords']), |
---|
207 | get_keywords($_POST['add_keywords']) |
---|
208 | ) |
---|
209 | ) |
---|
210 | ); |
---|
211 | } |
---|
212 | |
---|
213 | if ($_POST['remove_keyword'] != '0') |
---|
214 | { |
---|
215 | if (!isset($data['keywords'])) |
---|
216 | { |
---|
217 | $data['keywords'] = empty($row['keywords']) ? '' : $row['keywords']; |
---|
218 | } |
---|
219 | |
---|
220 | $data['keywords'] = |
---|
221 | implode( |
---|
222 | ',', |
---|
223 | array_unique( |
---|
224 | array_diff( |
---|
225 | get_keywords($data['keywords']), |
---|
226 | array($_POST['remove_keyword']) |
---|
227 | ) |
---|
228 | ) |
---|
229 | ); |
---|
230 | |
---|
231 | if ($data['keywords'] == '') |
---|
232 | { |
---|
233 | unset($data['keywords']); |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | if ('set' == $_POST['author_action']) |
---|
238 | { |
---|
239 | $data['author'] = $_POST['author']; |
---|
240 | |
---|
241 | if ('' == $data['author']) |
---|
242 | { |
---|
243 | unset($data['author']); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | if ('set' == $_POST['name_action']) |
---|
248 | { |
---|
249 | $data['name'] = $_POST['name']; |
---|
250 | |
---|
251 | if ('' == $data['name']) |
---|
252 | { |
---|
253 | unset($data['name']); |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | if ('set' == $_POST['date_creation_action']) |
---|
258 | { |
---|
259 | $data['date_creation'] = |
---|
260 | $_POST['date_creation_year'] |
---|
261 | .'-'.$_POST['date_creation_month'] |
---|
262 | .'-'.$_POST['date_creation_day'] |
---|
263 | ; |
---|
264 | } |
---|
265 | |
---|
266 | array_push($datas, $data); |
---|
267 | } |
---|
268 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
269 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | // +-----------------------------------------------------------------------+ |
---|
274 | // | template init | |
---|
275 | // +-----------------------------------------------------------------------+ |
---|
276 | $template->set_filenames( |
---|
277 | array('element_set_global' => 'admin/element_set_global.tpl')); |
---|
278 | |
---|
279 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
280 | |
---|
281 | // $form_action = $base_url.'?page=element_set_global'; |
---|
282 | |
---|
283 | $template->assign_vars( |
---|
284 | array( |
---|
285 | 'CATEGORIES_NAV'=>$page['title'], |
---|
286 | |
---|
287 | 'L_SUBMIT'=>$lang['submit'], |
---|
288 | |
---|
289 | 'U_COLS'=>$base_url.get_query_string_diff(array('cols')), |
---|
290 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
291 | |
---|
292 | 'U_UNIT_MODE' |
---|
293 | => |
---|
294 | $base_url |
---|
295 | .get_query_string_diff(array('mode','display')) |
---|
296 | .'&mode=unit', |
---|
297 | |
---|
298 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
299 | ) |
---|
300 | ); |
---|
301 | |
---|
302 | // +-----------------------------------------------------------------------+ |
---|
303 | // | caddie options | |
---|
304 | // +-----------------------------------------------------------------------+ |
---|
305 | |
---|
306 | if ('caddie' == $_GET['cat']) |
---|
307 | { |
---|
308 | $template->assign_block_vars('in_caddie', array()); |
---|
309 | } |
---|
310 | else |
---|
311 | { |
---|
312 | $template->assign_block_vars('not_in_caddie', array()); |
---|
313 | } |
---|
314 | |
---|
315 | // +-----------------------------------------------------------------------+ |
---|
316 | // | global mode form | |
---|
317 | // +-----------------------------------------------------------------------+ |
---|
318 | |
---|
319 | // Virtualy associate a picture to a category |
---|
320 | $blockname = 'associate_option'; |
---|
321 | |
---|
322 | $template->assign_block_vars( |
---|
323 | $blockname, |
---|
324 | array('SELECTED' => '', |
---|
325 | 'VALUE'=> 0, |
---|
326 | 'OPTION' => '------------' |
---|
327 | )); |
---|
328 | |
---|
329 | $query = ' |
---|
330 | SELECT id,name,uppercats,global_rank |
---|
331 | FROM '.CATEGORIES_TABLE.' |
---|
332 | ;'; |
---|
333 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
334 | |
---|
335 | // Dissociate from a category : categories listed for dissociation can |
---|
336 | // only represent virtual links. Links to physical categories can't be |
---|
337 | // broken |
---|
338 | $blockname = 'dissociate_option'; |
---|
339 | |
---|
340 | $template->assign_block_vars( |
---|
341 | $blockname, |
---|
342 | array('SELECTED' => '', |
---|
343 | 'VALUE'=> 0, |
---|
344 | 'OPTION' => '------------' |
---|
345 | )); |
---|
346 | |
---|
347 | if (count($page['cat_elements_id']) > 0) |
---|
348 | { |
---|
349 | $query = ' |
---|
350 | SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank |
---|
351 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic, |
---|
352 | '.CATEGORIES_TABLE.' AS c, |
---|
353 | '.IMAGES_TABLE.' AS i |
---|
354 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
355 | AND ic.category_id = c.id |
---|
356 | AND ic.image_id = i.id |
---|
357 | AND ic.category_id != i.storage_category_id |
---|
358 | ;'; |
---|
359 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
360 | } |
---|
361 | |
---|
362 | $blockname = 'remove_keyword_option'; |
---|
363 | |
---|
364 | $template->assign_block_vars( |
---|
365 | $blockname, |
---|
366 | array('VALUE'=> 0, |
---|
367 | 'OPTION' => '------------' |
---|
368 | )); |
---|
369 | |
---|
370 | $keywords = get_elements_keywords($page['cat_elements_id']); |
---|
371 | |
---|
372 | foreach ($keywords as $keyword) |
---|
373 | { |
---|
374 | $template->assign_block_vars( |
---|
375 | $blockname, |
---|
376 | array('VALUE'=> $keyword, |
---|
377 | 'OPTION' => $keyword |
---|
378 | )); |
---|
379 | } |
---|
380 | |
---|
381 | // creation date |
---|
382 | $day = |
---|
383 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
384 | get_day_list('date_creation_day', $day); |
---|
385 | |
---|
386 | if (!empty($_POST['date_creation_month'])) |
---|
387 | { |
---|
388 | $month = $_POST['date_creation_month']; |
---|
389 | } |
---|
390 | else |
---|
391 | { |
---|
392 | $month = date('n'); |
---|
393 | } |
---|
394 | get_month_list('date_creation_month', $month); |
---|
395 | |
---|
396 | if (!empty($_POST['date_creation_year'])) |
---|
397 | { |
---|
398 | $year = $_POST['date_creation_year']; |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | $year = date('Y'); |
---|
403 | } |
---|
404 | $template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year)); |
---|
405 | |
---|
406 | // +-----------------------------------------------------------------------+ |
---|
407 | // | global mode thumbnails | |
---|
408 | // +-----------------------------------------------------------------------+ |
---|
409 | |
---|
410 | $page['cols'] = !empty($_GET['cols']) ? intval($_GET['cols']) : 5; |
---|
411 | |
---|
412 | // how many items to display on this page |
---|
413 | if (!empty($_GET['display'])) |
---|
414 | { |
---|
415 | if ('all' == $_GET['display']) |
---|
416 | { |
---|
417 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
418 | } |
---|
419 | else |
---|
420 | { |
---|
421 | $page['nb_images'] = intval($_GET['display']); |
---|
422 | } |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | $page['nb_images'] = 20; |
---|
427 | } |
---|
428 | |
---|
429 | if (count($page['cat_elements_id']) > 0) |
---|
430 | { |
---|
431 | $nav_bar = create_navigation_bar( |
---|
432 | $base_url.get_query_string_diff(array('start')), |
---|
433 | count($page['cat_elements_id']), |
---|
434 | $page['start'], |
---|
435 | $page['nb_images'], |
---|
436 | ''); |
---|
437 | $template->assign_vars(array('NAV_BAR' => $nav_bar)); |
---|
438 | |
---|
439 | $query = ' |
---|
440 | SELECT id,path,tn_ext |
---|
441 | FROM '.IMAGES_TABLE.' |
---|
442 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
443 | '.$conf['order_by'].' |
---|
444 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
---|
445 | ;'; |
---|
446 | //echo '<pre>'.$query.'</pre>'; |
---|
447 | $result = pwg_query($query); |
---|
448 | |
---|
449 | // template thumbnail initialization |
---|
450 | if (mysql_num_rows($result) > 0) |
---|
451 | { |
---|
452 | $template->assign_block_vars('thumbnails', array()); |
---|
453 | // first line |
---|
454 | $template->assign_block_vars('thumbnails.line', array()); |
---|
455 | // current row displayed |
---|
456 | $row_number = 0; |
---|
457 | } |
---|
458 | |
---|
459 | while ($row = mysql_fetch_array($result)) |
---|
460 | { |
---|
461 | $src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
462 | |
---|
463 | $template->assign_block_vars( |
---|
464 | 'thumbnails.line.thumbnail', |
---|
465 | array( |
---|
466 | 'ID' => $row['id'], |
---|
467 | 'SRC' => $src, |
---|
468 | 'ALT' => 'TODO', |
---|
469 | 'TITLE' => 'TODO' |
---|
470 | ) |
---|
471 | ); |
---|
472 | |
---|
473 | // create a new line ? |
---|
474 | if (++$row_number == $page['cols']) |
---|
475 | { |
---|
476 | $template->assign_block_vars('thumbnails.line', array()); |
---|
477 | $row_number = 0; |
---|
478 | } |
---|
479 | } |
---|
480 | } |
---|
481 | |
---|
482 | //----------------------------------------------------------- sending html code |
---|
483 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
484 | ?> |
---|