source: trunk/admin/element_set.php @ 2408

Last change on this file since 2408 was 2299, checked in by plg, 16 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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
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 
137  // we are searching elements not linked to any virtual category
138  $query = '
139SELECT id
140  FROM '.CATEGORIES_TABLE.'
141  WHERE dir IS NULL
142;';
143  $virtual_categories = array_from_query($query, 'id');
144
145  if (!empty($virtual_categories))
146  {
147    $query = '
148SELECT DISTINCT(image_id)
149  FROM '.IMAGE_CATEGORY_TABLE.'
150;';
151    $all_elements = array_from_query($query, 'image_id');
152
153    $query = '
154SELECT DISTINCT(image_id)
155  FROM '.IMAGE_CATEGORY_TABLE.'
156  WHERE category_id IN ('.implode(',', $virtual_categories).')
157;';
158    $linked_to_virtual = array_from_query($query, 'image_id');
159
160    $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
161  }
162  else
163  {
164    $page['cat_elements_id'] = array();
165  }
166}
167else if ('duplicates' == $_GET['cat'])
168{
169  $page['title'] = l10n('Duplicates');
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  $page['cat_elements_id'][] = 0;
192}
193// +-----------------------------------------------------------------------+
194// |                       first element to display                        |
195// +-----------------------------------------------------------------------+
196
197// $page['start'] contains the number of the first element in its
198// category. For exampe, $page['start'] = 12 means we must show elements #12
199// and $page['nb_images'] next elements
200
201if (!isset($_GET['start'])
202    or !is_numeric($_GET['start'])
203    or $_GET['start'] < 0
204    or (isset($_GET['display']) and 'all' == $_GET['display']))
205{
206  $page['start'] = 0;
207}
208else
209{
210  $page['start'] = $_GET['start'];
211}
212
213// +-----------------------------------------------------------------------+
214// |                         open specific mode                            |
215// +-----------------------------------------------------------------------+
216
217$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
218
219switch ($_GET['mode'])
220{
221  case 'global' :
222  {
223    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
224    break;
225  }
226  case 'unit' :
227  {
228    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
229    break;
230  }
231}
232?>
Note: See TracBrowser for help on using the repository browser.