source: branches/2.0/admin/element_set.php @ 5751

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

improvement: avoid the use of @ instead of a real test

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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
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('Elements_not_linked');
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 '.CATEGORIES_TABLE.'
144  WHERE dir IS NULL
145;';
146  $virtual_categories = array_from_query($query, 'id');
147
148  if (!empty($virtual_categories))
149  {
150    $query = '
151SELECT DISTINCT(image_id)
152  FROM '.IMAGE_CATEGORY_TABLE.'
153;';
154    $all_elements = array_from_query($query, 'image_id');
155
156    $query = '
157SELECT DISTINCT(image_id)
158  FROM '.IMAGE_CATEGORY_TABLE.'
159  WHERE category_id IN ('.implode(',', $virtual_categories).')
160;';
161    $linked_to_virtual = array_from_query($query, 'image_id');
162
163    $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
164  }
165}
166else if ('duplicates' == $_GET['cat'])
167{
168  $page['title'] = l10n('Duplicates');
169  $template->assign(array('U_ACTIVE_MENU' => 5 ));
170
171  // we are searching related elements twice or more to physical categories
172  // 1 - Retrieve Files
173  $query = '
174SELECT DISTINCT(file)
175  FROM '.IMAGES_TABLE.'
176 GROUP BY file
177HAVING COUNT(DISTINCT storage_category_id) > 1
178;';
179
180  $duplicate_files = array_from_query($query, 'file');
181  $duplicate_files[]='Nofiles';
182  // 2 - Retrives related picture ids
183  $query = '
184SELECT id, file
185  FROM '.IMAGES_TABLE.'
186WHERE file IN (\''.implode("','", $duplicate_files).'\')
187ORDER BY file, id
188;';
189
190  $page['cat_elements_id'] = array_from_query($query, 'id');
191}
192elseif ('recent'== $_GET['cat'])
193{
194  $page['title'] = l10n('recent_pics_cat');
195  $query = 'SELECT MAX(date_available) AS date
196  FROM '.IMAGES_TABLE;
197  if ($row=mysql_fetch_array( pwg_query($query) ) )
198  {
199    $query = 'SELECT id
200  FROM '.IMAGES_TABLE.'
201  WHERE date_available BETWEEN DATE_SUB("'.$row['date'].'", INTERVAL 1 DAY) AND "'.$row['date'].'"';
202    $page['cat_elements_id'] = array_from_query($query, 'id');
203  }
204}
205
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'])
216    or $_GET['start'] < 0
217    or (isset($_GET['display']) and 'all' == $_GET['display']))
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}
245?>
Note: See TracBrowser for help on using the repository browser.