source: branches/2.1/admin/element_set.php @ 6600

Last change on this file since 6600 was 6600, checked in by nikrou, 14 years ago

Bug 1739 fixed : Recent pictures page returns database error
merge from trunk

  • 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
[6048]143  FROM '.IMAGES_TABLE.'
144;';
145  $all_elements = array_from_query($query, 'id');
146
147  $linked_to_virtual = array();
148
149  $query = '
150SELECT id
[764]151  FROM '.CATEGORIES_TABLE.'
152  WHERE dir IS NULL
153;';
154  $virtual_categories = array_from_query($query, 'id');
[1831]155  if (!empty($virtual_categories))
156  {
157    $query = '
[764]158SELECT DISTINCT(image_id)
159  FROM '.IMAGE_CATEGORY_TABLE.'
160  WHERE category_id IN ('.implode(',', $virtual_categories).')
161;';
[1831]162    $linked_to_virtual = array_from_query($query, 'image_id');
[6048]163  }
[764]164
[6048]165  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
[764]166}
[1688]167else if ('duplicates' == $_GET['cat'])
168{
[5021]169  $page['title'] = l10n('Files with same name in more than one physical category');
[3216]170  $template->assign(array('U_ACTIVE_MENU' => 5 ));
[2579]171
[1688]172  // we are searching related elements twice or more to physical categories
173  // 1 - Retrieve Files
174  $query = '
175SELECT DISTINCT(file)
[2579]176  FROM '.IMAGES_TABLE.'
177 GROUP BY file
178HAVING COUNT(DISTINCT storage_category_id) > 1
179;';
[764]180
[1688]181  $duplicate_files = array_from_query($query, 'file');
182  $duplicate_files[]='Nofiles';
183  // 2 - Retrives related picture ids
184  $query = '
185SELECT id, file
[2579]186  FROM '.IMAGES_TABLE.'
[1688]187WHERE file IN (\''.implode("','", $duplicate_files).'\')
188ORDER BY file, id
189;';
190
191  $page['cat_elements_id'] = array_from_query($query, 'id');
192}
[2579]193elseif ('recent'== $_GET['cat'])
194{
[5021]195  $page['title'] = l10n('Recent pictures');
[2579]196  $query = 'SELECT MAX(date_available) AS date
197  FROM '.IMAGES_TABLE;
[6600]198  $row = pwg_db_fetch_assoc(pwg_query($query));
199  if (!empty($row['date']))
[2579]200  {
201    $query = 'SELECT id
202  FROM '.IMAGES_TABLE.'
[4367]203  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
[2579]204    $page['cat_elements_id'] = array_from_query($query, 'id');
205  }
206}
207
[764]208// +-----------------------------------------------------------------------+
209// |                       first element to display                        |
210// +-----------------------------------------------------------------------+
211
212// $page['start'] contains the number of the first element in its
213// category. For exampe, $page['start'] = 12 means we must show elements #12
214// and $page['nb_images'] next elements
215
216if (!isset($_GET['start'])
217    or !is_numeric($_GET['start'])
[956]218    or $_GET['start'] < 0
219    or (isset($_GET['display']) and 'all' == $_GET['display']))
[764]220{
221  $page['start'] = 0;
222}
223else
224{
225  $page['start'] = $_GET['start'];
226}
227
228// +-----------------------------------------------------------------------+
229// |                         open specific mode                            |
230// +-----------------------------------------------------------------------+
231
232$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
233
234switch ($_GET['mode'])
235{
236  case 'global' :
237  {
238    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
239    break;
240  }
241  case 'unit' :
242  {
243    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
244    break;
245  }
246}
[1688]247?>
Note: See TracBrowser for help on using the repository browser.