source: trunk/admin/element_set.php @ 6276

Last change on this file since 6276 was 6048, checked in by plg, 14 years ago

bug 1638 fixed: the "admin>tools>maintenance>unlinked elements" features now
works if you have only virtual categories, this is what happens if you don't
use synchronization to add photos (if you use pLoader or UploadForm for
example).

  • Property svn:eol-style set to LF
File size: 7.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 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
42check_input_parameter('selection', $_POST, true, PATTERN_ID);
43
44// +-----------------------------------------------------------------------+
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.
107$page['cat_elements_id'] = array();
108if (is_numeric($_GET['cat']))
109{
110  $page['title'] =
111    get_cat_display_name_from_id(
112      $_GET['cat'],
113      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
114      false
115      );
116
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{
126  $page['title'] = l10n('caddie');
127
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{
137  $page['title'] = l10n('Not linked elements');
138  $template->assign(array('U_ACTIVE_MENU' => 5 ));
139
140  // we are searching elements not linked to any virtual category
141  $query = '
142SELECT id
143  FROM '.IMAGES_TABLE.'
144;';
145  $all_elements = array_from_query($query, 'id');
146
147  $linked_to_virtual = array();
148
149  $query = '
150SELECT id
151  FROM '.CATEGORIES_TABLE.'
152  WHERE dir IS NULL
153;';
154  $virtual_categories = array_from_query($query, 'id');
155  if (!empty($virtual_categories))
156  {
157    $query = '
158SELECT DISTINCT(image_id)
159  FROM '.IMAGE_CATEGORY_TABLE.'
160  WHERE category_id IN ('.implode(',', $virtual_categories).')
161;';
162    $linked_to_virtual = array_from_query($query, 'image_id');
163  }
164
165  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
166}
167else if ('duplicates' == $_GET['cat'])
168{
169  $page['title'] = l10n('Files with same name in more than one physical category');
170  $template->assign(array('U_ACTIVE_MENU' => 5 ));
171
172  // we are searching related elements twice or more to physical categories
173  // 1 - Retrieve Files
174  $query = '
175SELECT DISTINCT(file)
176  FROM '.IMAGES_TABLE.'
177 GROUP BY file
178HAVING COUNT(DISTINCT storage_category_id) > 1
179;';
180
181  $duplicate_files = array_from_query($query, 'file');
182  $duplicate_files[]='Nofiles';
183  // 2 - Retrives related picture ids
184  $query = '
185SELECT id, file
186  FROM '.IMAGES_TABLE.'
187WHERE file IN (\''.implode("','", $duplicate_files).'\')
188ORDER BY file, id
189;';
190
191  $page['cat_elements_id'] = array_from_query($query, 'id');
192}
193elseif ('recent'== $_GET['cat'])
194{
195  $page['title'] = l10n('Recent pictures');
196  $query = 'SELECT MAX(date_available) AS date
197  FROM '.IMAGES_TABLE;
198  if ($row = pwg_db_fetch_assoc( pwg_query($query) ) )
199  {
200    $query = 'SELECT id
201  FROM '.IMAGES_TABLE.'
202  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
203    $page['cat_elements_id'] = array_from_query($query, 'id');
204  }
205}
206
207// +-----------------------------------------------------------------------+
208// |                       first element to display                        |
209// +-----------------------------------------------------------------------+
210
211// $page['start'] contains the number of the first element in its
212// category. For exampe, $page['start'] = 12 means we must show elements #12
213// and $page['nb_images'] next elements
214
215if (!isset($_GET['start'])
216    or !is_numeric($_GET['start'])
217    or $_GET['start'] < 0
218    or (isset($_GET['display']) and 'all' == $_GET['display']))
219{
220  $page['start'] = 0;
221}
222else
223{
224  $page['start'] = $_GET['start'];
225}
226
227// +-----------------------------------------------------------------------+
228// |                         open specific mode                            |
229// +-----------------------------------------------------------------------+
230
231$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
232
233switch ($_GET['mode'])
234{
235  case 'global' :
236  {
237    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
238    break;
239  }
240  case 'unit' :
241  {
242    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
243    break;
244  }
245}
246?>
Note: See TracBrowser for help on using the repository browser.