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