source: trunk/admin/element_set.php @ 2863

Last change on this file since 2863 was 2579, checked in by rvelices, 16 years ago
  • feature admin element set: recently posted images (nice if you forget add to caddie during synchro phase)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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$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
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}
163else if ('duplicates' == $_GET['cat'])
164{
165  $page['title'] = l10n('Duplicates');
166
167  // we are searching related elements twice or more to physical categories
168  // 1 - Retrieve Files
169  $query = '
170SELECT DISTINCT(file)
171  FROM '.IMAGES_TABLE.'
172 GROUP BY file
173HAVING COUNT(DISTINCT storage_category_id) > 1
174;';
175
176  $duplicate_files = array_from_query($query, 'file');
177  $duplicate_files[]='Nofiles';
178  // 2 - Retrives related picture ids
179  $query = '
180SELECT id, file
181  FROM '.IMAGES_TABLE.'
182WHERE file IN (\''.implode("','", $duplicate_files).'\')
183ORDER BY file, id
184;';
185
186  $page['cat_elements_id'] = array_from_query($query, 'id');
187}
188elseif ('recent'== $_GET['cat'])
189{
190  $page['title'] = l10n('recent_pics_cat');
191  $query = 'SELECT MAX(date_available) AS date
192  FROM '.IMAGES_TABLE;
193  if ($row=mysql_fetch_array( pwg_query($query) ) )
194  {
195    $query = 'SELECT id
196  FROM '.IMAGES_TABLE.'
197  WHERE date_available BETWEEN DATE_SUB("'.$row['date'].'", INTERVAL 1 DAY) AND "'.$row['date'].'"';
198    $page['cat_elements_id'] = array_from_query($query, 'id');
199  }
200}
201
202// +-----------------------------------------------------------------------+
203// |                       first element to display                        |
204// +-----------------------------------------------------------------------+
205
206// $page['start'] contains the number of the first element in its
207// category. For exampe, $page['start'] = 12 means we must show elements #12
208// and $page['nb_images'] next elements
209
210if (!isset($_GET['start'])
211    or !is_numeric($_GET['start'])
212    or $_GET['start'] < 0
213    or (isset($_GET['display']) and 'all' == $_GET['display']))
214{
215  $page['start'] = 0;
216}
217else
218{
219  $page['start'] = $_GET['start'];
220}
221
222// +-----------------------------------------------------------------------+
223// |                         open specific mode                            |
224// +-----------------------------------------------------------------------+
225
226$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
227
228switch ($_GET['mode'])
229{
230  case 'global' :
231  {
232    include(PHPWG_ROOT_PATH.'admin/element_set_global.php');
233    break;
234  }
235  case 'unit' :
236  {
237    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
238    break;
239  }
240}
241?>
Note: See TracBrowser for help on using the repository browser.