source: trunk/admin/element_set_global.php @ 5188

Last change on this file since 5188 was 5188, checked in by plg, 15 years ago

feature 724: FCBKcomplete propagated to element_set_global and
element_set_unit to manage tags.

Note: multiple instances of FCBKcomplete on the same page does not work as
good as a single instance.

  • Property svn:eol-style set to LF
File size: 13.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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/**
25 * Management of elements set. Elements can belong to a category or to the
26 * user caddie.
27 *
28 */
29
30if (!defined('PHPWG_ROOT_PATH'))
31{
32  die('Hacking attempt!');
33}
34
35include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
36
37// +-----------------------------------------------------------------------+
38// | Check Access and exit when user status is not ok                      |
39// +-----------------------------------------------------------------------+
40check_status(ACCESS_ADMINISTRATOR);
41
42// +-----------------------------------------------------------------------+
43// |                         deletion form submission                      |
44// +-----------------------------------------------------------------------+
45
46if (isset($_POST['delete']))
47{
48  if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
49  {
50    $collection = array();
51
52    switch ($_POST['target_deletion'])
53    {
54      case 'all' :
55      {
56        $collection = $page['cat_elements_id'];
57        break;
58      }
59      case 'selection' :
60      {
61        if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
62        {
63          array_push($page['errors'], l10n('Select at least one picture'));
64        }
65        else
66        {
67          $collection = $_POST['selection'];
68        }
69        break;
70      }
71    }
72
73    // filter selection on photos that have no storage_category_id (ie that
74    // were added via pLoader)
75    if (count($collection) > 0)
76    {
77      $query = '
78SELECT
79    id
80  FROM '.IMAGES_TABLE.'
81  WHERE id IN ('.implode(',', $collection).')
82    AND storage_category_id IS NULL
83;';
84      $deletables = array_from_query($query, 'id');
85
86      if (count($deletables) > 0)
87      {
88        $physical_deletion = true;
89        delete_elements($deletables, $physical_deletion);
90
91        array_push(
92          $page['infos'],
93          sprintf(
94            l10n_dec(
95              '%d photo was deleted',
96              '%d photos were deleted',
97              count($deletables)
98              ),
99            count($deletables)
100            )
101          );
102      }
103      else
104      {
105        array_push($page['errors'], l10n('No photo can be deleted'));
106      }
107    }
108  }
109  else
110  {
111    array_push($page['errors'], l10n('You need to confirm deletion'));
112  }
113}
114
115// +-----------------------------------------------------------------------+
116// |                       global mode form submission                     |
117// +-----------------------------------------------------------------------+
118
119if (isset($_POST['submit']))
120{
121  $collection = array();
122
123//   echo '<pre>';
124//   print_r($_POST);
125//   echo '</pre>';
126//   exit();
127
128  switch ($_POST['target'])
129  {
130    case 'all' :
131    {
132      $collection = $page['cat_elements_id'];
133      break;
134    }
135    case 'selection' :
136    {
137      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
138      {
139        array_push($page['errors'], l10n('Select at least one picture'));
140      }
141      else
142      {
143        $collection = $_POST['selection'];
144      }
145      break;
146    }
147  }
148
149  if (isset($_POST['add_tags']) and count($collection) > 0)
150  {
151    $tag_ids = get_fckb_tag_ids($_POST['add_tags']);
152    add_tags($tag_ids, $collection);
153  }
154
155  if (isset($_POST['del_tags']) and count($collection) > 0)
156  {
157    $query = '
158DELETE
159  FROM '.IMAGE_TAG_TABLE.'
160  WHERE image_id IN ('.implode(',', $collection).')
161    AND tag_id IN ('.implode(',', $_POST['del_tags']).')
162;';
163    pwg_query($query);
164  }
165
166  if ($_POST['associate'] != 0 and count($collection) > 0)
167  {
168    associate_images_to_categories(
169      $collection,
170      array($_POST['associate'])
171      );
172  }
173
174  if ($_POST['dissociate'] != 0 and count($collection) > 0)
175  {
176    // physical links must not be broken, so we must first retrieve image_id
177    // which create virtual links with the category to "dissociate from".
178    $query = '
179SELECT id
180  FROM '.IMAGE_CATEGORY_TABLE.'
181    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
182  WHERE category_id = '.$_POST['dissociate'].'
183    AND id IN ('.implode(',', $collection).')
184    AND (
185      category_id != storage_category_id
186      OR storage_category_id IS NULL
187    )
188;';
189    $dissociables = array_from_query($query, 'id');
190
191    if (!empty($dissociables))
192    {
193      $query = '
194DELETE
195  FROM '.IMAGE_CATEGORY_TABLE.'
196  WHERE category_id = '.$_POST['dissociate'].'
197    AND image_id IN ('.implode(',', $dissociables).')
198';
199      pwg_query($query);
200
201      // we remove the dissociated images if we are currently displaying the
202      // category to dissociate from.
203      if (is_numeric($_GET['cat']) and $_POST['dissociate'] == $_GET['cat'])
204      {
205        $page['cat_elements_id'] = array_diff(
206          $page['cat_elements_id'],
207          $dissociables
208          );
209      }
210    }
211
212    update_category($_POST['dissociate']);
213  }
214
215  $datas = array();
216  $dbfields = array('primary' => array('id'), 'update' => array());
217
218  $formfields = array('author', 'name', 'date_creation', 'level');
219  foreach ($formfields as $formfield)
220  {
221    if ($_POST[$formfield.'_action'] != 'leave')
222    {
223      array_push($dbfields['update'], $formfield);
224    }
225  }
226
227  // updating elements is useful only if needed...
228  if (count($dbfields['update']) > 0 and count($collection) > 0)
229  {
230    $query = '
231SELECT id
232  FROM '.IMAGES_TABLE.'
233  WHERE id IN ('.implode(',', $collection).')
234;';
235    $result = pwg_query($query);
236
237    while ($row = pwg_db_fetch_assoc($result))
238    {
239      $data = array();
240      $data['id'] = $row['id'];
241
242      if ('set' == $_POST['author_action'])
243      {
244        $data['author'] = $_POST['author'];
245        if ('' == $data['author'])
246        {
247          unset($data['author']);
248        }
249      }
250
251      if ('set' == $_POST['name_action'])
252      {
253        $data['name'] = $_POST['name'];
254        if ('' == $data['name'])
255        {
256          unset($data['name']);
257        }
258      }
259
260      if ('set' == $_POST['date_creation_action'])
261      {
262        $data['date_creation'] =
263          $_POST['date_creation_year']
264          .'-'.$_POST['date_creation_month']
265          .'-'.$_POST['date_creation_day']
266          ;
267      }
268
269      if ('set' == $_POST['level_action'])
270      {
271        $data['level'] = $_POST['level'];
272      }
273
274      array_push($datas, $data);
275    }
276    // echo '<pre>'; print_r($datas); echo '</pre>';
277    mass_updates(IMAGES_TABLE, $dbfields, $datas);
278  }
279}
280
281// +-----------------------------------------------------------------------+
282// |                             template init                             |
283// +-----------------------------------------------------------------------+
284$template->set_filenames(
285  array('element_set_global' => 'element_set_global.tpl'));
286
287$base_url = get_root_url().'admin.php';
288
289// $form_action = $base_url.'?page=element_set_global';
290
291$template->assign(
292  array(
293    'CATEGORIES_NAV'=>$page['title'],
294
295    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
296
297    'U_UNIT_MODE'
298    =>
299    $base_url
300    .get_query_string_diff(array('mode','display'))
301    .'&amp;mode=unit',
302
303    'F_ACTION'=>$base_url.get_query_string_diff(array()),
304   )
305 );
306
307// +-----------------------------------------------------------------------+
308// |                            caddie options                             |
309// +-----------------------------------------------------------------------+
310
311$template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
312
313// +-----------------------------------------------------------------------+
314// |                            deletion form                              |
315// +-----------------------------------------------------------------------+
316
317// we can only remove photos that have no storage_category_id, in other
318// word, it currently (Butterfly) means that the photo was added with
319// pLoader
320if (count($page['cat_elements_id']) > 0)
321{
322  $query = '
323SELECT
324    COUNT(*)
325  FROM '.IMAGES_TABLE.'
326  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
327    AND storage_category_id IS NULL
328;';
329  list($counter) = pwg_db_fetch_row(pwg_query($query));
330
331  if ($counter > 0)
332  {
333    $template->assign('show_delete_form', true);
334  }
335}
336
337// +-----------------------------------------------------------------------+
338// |                           global mode form                            |
339// +-----------------------------------------------------------------------+
340
341// Virtualy associate a picture to a category
342$query = '
343SELECT id,name,uppercats,global_rank
344  FROM '.CATEGORIES_TABLE.'
345;';
346display_select_cat_wrapper($query, array(), 'associate_options', true);
347
348// Dissociate from a category : categories listed for dissociation can
349// only represent virtual links. Links to physical categories can't be
350// broken
351if (count($page['cat_elements_id']) > 0)
352{
353  $query = '
354SELECT
355    DISTINCT(category_id) AS id,
356    c.name,
357    c.uppercats,
358    c.global_rank
359  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
360    JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id
361    JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id
362  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
363    AND (
364      ic.category_id != i.storage_category_id
365      OR i.storage_category_id IS NULL
366    )
367;';
368  display_select_cat_wrapper($query, array(), 'dissociate_options', true);
369}
370
371if (count($page['cat_elements_id']) > 0)
372{
373  // remove tags
374  $tags = get_common_tags($page['cat_elements_id'], -1);
375
376  $template->assign(
377    array(
378      'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
379      )
380    );
381}
382
383// creation date
384$day =
385empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
386
387$month =
388empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month'];
389
390$year =
391empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year'];
392
393$month_list = $lang['month'];
394$month_list[0]='------------';
395ksort($month_list);
396$template->assign( array(
397      'month_list'         => $month_list,
398      'DATE_CREATION_DAY'  => (int)$day,
399      'DATE_CREATION_MONTH'=> (int)$month,
400      'DATE_CREATION_YEAR' => (int)$year,
401    )
402  );
403
404// image level options
405$tpl_options = array();
406foreach ($conf['available_permission_levels'] as $level)
407{
408  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
409}
410$template->assign(
411    array(
412      'level_options'=> $tpl_options,
413    )
414  );
415
416// +-----------------------------------------------------------------------+
417// |                        global mode thumbnails                         |
418// +-----------------------------------------------------------------------+
419
420// how many items to display on this page
421if (!empty($_GET['display']))
422{
423  if ('all' == $_GET['display'])
424  {
425    $page['nb_images'] = count($page['cat_elements_id']);
426  }
427  else
428  {
429    $page['nb_images'] = intval($_GET['display']);
430  }
431}
432else
433{
434  $page['nb_images'] = 20;
435}
436
437if (count($page['cat_elements_id']) > 0)
438{
439  $nav_bar = create_navigation_bar(
440    $base_url.get_query_string_diff(array('start')),
441    count($page['cat_elements_id']),
442    $page['start'],
443    $page['nb_images']
444    );
445  $template->assign('navbar', $nav_bar);
446
447  $query = '
448SELECT id,path,tn_ext,file,filesize,level
449  FROM '.IMAGES_TABLE.'
450  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
451  '.$conf['order_by'].'
452  LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].'
453;';
454  $result = pwg_query($query);
455
456  // template thumbnail initialization
457  while ($row = pwg_db_fetch_assoc($result))
458  {
459    $src = get_thumbnail_url($row);
460
461    $template->append(
462      'thumbnails',
463      array(
464        'ID' => $row['id'],
465        'TN_SRC' => $src,
466        'FILE' => $row['file'],
467        'TITLE' => get_thumbnail_title($row),
468        'LEVEL' => $row['level']
469        )
470      );
471  }
472}
473
474//----------------------------------------------------------- sending html code
475$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
476?>
Note: See TracBrowser for help on using the repository browser.