source: trunk/admin/element_set.php @ 4529

Last change on this file since 4529 was 4367, checked in by nikrou, 15 years ago

Feature 1255: modification in sql queries

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