source: branches/2.1/admin/element_set_global.php @ 6464

Last change on this file since 6464 was 6364, checked in by plg, 14 years ago

remove all svn:mergeinfo properties

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