source: trunk/admin/element_set.php @ 5874

Last change on this file since 5874 was 5196, checked in by plg, 14 years ago

increase copyright year to 2010

  • Property svn:eol-style set to LF
File size: 7.4 KB
RevLine 
[764]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// +-----------------------------------------------------------------------+
[764]23
24/**
25 * Management of elements set. Elements can belong to a category or to the
26 * user caddie.
[2579]27 *
[764]28 */
[2579]29
[764]30if (!defined('PHPWG_ROOT_PATH'))
31{
32  die('Hacking attempt!');
33}
34
[1072]35include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
36
[764]37// +-----------------------------------------------------------------------+
[1072]38// | Check Access and exit when user status is not ok                      |
39// +-----------------------------------------------------------------------+
40check_status(ACCESS_ADMINISTRATOR);
41
[5195]42check_input_parameter('selection', $_POST, true, PATTERN_ID);
43
[1072]44// +-----------------------------------------------------------------------+
[764]45// |                          caddie management                            |
46// +-----------------------------------------------------------------------+
47
48if (isset($_POST['submit_caddie']))
49{
50  if (isset($_POST['caddie_action']))
51  {
52    switch ($_POST['caddie_action'])
53    {
54      case 'empty_all' :
55      {
56          $query = '
57DELETE FROM '.CADDIE_TABLE.'
58  WHERE user_id = '.$user['id'].'
59;';
60          pwg_query($query);
61          break;
62      }
63      case 'empty_selected' :
64      {
65        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
66        {
67          $query = '
68DELETE
69  FROM '.CADDIE_TABLE.'
70  WHERE element_id IN ('.implode(',', $_POST['selection']).')
71    AND user_id = '.$user['id'].'
72;';
73          pwg_query($query);
74        }
75        else
76        {
77          // TODO : add error
78        }
79        break;
80      }
81      case 'add_selected' :
82      {
83        if (isset($_POST['selection']) and count($_POST['selection']) > 0)
84        {
85          fill_caddie($_POST['selection']);
86        }
87        else
88        {
89          // TODO : add error
90        }
91        break;
92      }
93    }
94  }
95  else
96  {
97    // TODO : add error
98  }
99}
100
101// +-----------------------------------------------------------------------+
102// |                    initialize info about category                     |
103// +-----------------------------------------------------------------------+
104
105// To element_set_(global|unit).php, we must provide the elements id of the
106// managed category in $page['cat_elements_id'] array.
[2579]107$page['cat_elements_id'] = array();
[764]108if (is_numeric($_GET['cat']))
109{
[834]110  $page['title'] =
[1861]111    get_cat_display_name_from_id(
112      $_GET['cat'],
[834]113      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
114      false
115      );
[2579]116
[764]117  $query = '
118SELECT image_id
119  FROM '.IMAGE_CATEGORY_TABLE.'
120  WHERE category_id = '.$_GET['cat'].'
121;';
122  $page['cat_elements_id'] = array_from_query($query, 'image_id');
123}
124else if ('caddie' == $_GET['cat'])
125{
[2201]126  $page['title'] = l10n('caddie');
[2579]127
[764]128  $query = '
129SELECT element_id
130  FROM '.CADDIE_TABLE.'
131  WHERE user_id = '.$user['id'].'
132;';
133  $page['cat_elements_id'] = array_from_query($query, 'element_id');
134}
135else if ('not_linked' == $_GET['cat'])
136{
[5021]137  $page['title'] = l10n('Not linked elements');
[3216]138  $template->assign(array('U_ACTIVE_MENU' => 5 ));
[2579]139
[764]140  // we are searching elements not linked to any virtual category
141  $query = '
142SELECT id
143  FROM '.CATEGORIES_TABLE.'
144  WHERE dir IS NULL
145;';
146  $virtual_categories = array_from_query($query, 'id');
147
[1831]148  if (!empty($virtual_categories))
149  {
150    $query = '
[764]151SELECT DISTINCT(image_id)
152  FROM '.IMAGE_CATEGORY_TABLE.'
153;';
[1831]154    $all_elements = array_from_query($query, 'image_id');
155
156    $query = '
[764]157SELECT DISTINCT(image_id)
158  FROM '.IMAGE_CATEGORY_TABLE.'
159  WHERE category_id IN ('.implode(',', $virtual_categories).')
160;';
[1831]161    $linked_to_virtual = array_from_query($query, 'image_id');
[764]162
[1831]163    $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
164  }
[764]165}
[1688]166else if ('duplicates' == $_GET['cat'])
167{
[5021]168  $page['title'] = l10n('Files with same name in more than one physical category');
[3216]169  $template->assign(array('U_ACTIVE_MENU' => 5 ));
[2579]170
[1688]171  // we are searching related elements twice or more to physical categories
172  // 1 - Retrieve Files
173  $query = '
174SELECT DISTINCT(file)
[2579]175  FROM '.IMAGES_TABLE.'
176 GROUP BY file
177HAVING COUNT(DISTINCT storage_category_id) > 1
178;';
[764]179
[1688]180  $duplicate_files = array_from_query($query, 'file');
181  $duplicate_files[]='Nofiles';
182  // 2 - Retrives related picture ids
183  $query = '
184SELECT id, file
[2579]185  FROM '.IMAGES_TABLE.'
[1688]186WHERE file IN (\''.implode("','", $duplicate_files).'\')
187ORDER BY file, id
188;';
189
190  $page['cat_elements_id'] = array_from_query($query, 'id');
191}
[2579]192elseif ('recent'== $_GET['cat'])
193{
[5021]194  $page['title'] = l10n('Recent pictures');
[2579]195  $query = 'SELECT MAX(date_available) AS date
196  FROM '.IMAGES_TABLE;
[4325]197  if ($row = pwg_db_fetch_assoc( pwg_query($query) ) )
[2579]198  {
199    $query = 'SELECT id
200  FROM '.IMAGES_TABLE.'
[4367]201  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
[2579]202    $page['cat_elements_id'] = array_from_query($query, 'id');
203  }
204}
205
[764]206// +-----------------------------------------------------------------------+
207// |                       first element to display                        |
208// +-----------------------------------------------------------------------+
209
210// $page['start'] contains the number of the first element in its
211// category. For exampe, $page['start'] = 12 means we must show elements #12
212// and $page['nb_images'] next elements
213
214if (!isset($_GET['start'])
215    or !is_numeric($_GET['start'])
[956]216    or $_GET['start'] < 0
217    or (isset($_GET['display']) and 'all' == $_GET['display']))
[764]218{
219  $page['start'] = 0;
220}
221else
222{
223  $page['start'] = $_GET['start'];
224}
225
226// +-----------------------------------------------------------------------+
227// |                         open specific mode                            |
228// +-----------------------------------------------------------------------+
229
230$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
231
232switch ($_GET['mode'])
233{
234  case 'global' :
235  {
236    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
237    break;
238  }
239  case 'unit' :
240  {
241    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
242    break;
243  }
244}
[1688]245?>
Note: See TracBrowser for help on using the repository browser.