source: extensions/bulk_manager/element_set.php @ 6756

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

initial release for Piwigo 2.2 bulk manager

File size: 6.2 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// +-----------------------------------------------------------------------+
40
41check_status(ACCESS_ADMINISTRATOR);
42
43check_input_parameter('selection', $_POST, true, PATTERN_ID);
44
45// +-----------------------------------------------------------------------+
46// |                    initialize info about category                     |
47// +-----------------------------------------------------------------------+
48
49if (!isset($_GET['cat']))
50{
51  $_GET['cat'] = 'caddie';
52}
53
54// To element_set_(global|unit).php, we must provide the elements id of the
55// managed category in $page['cat_elements_id'] array.
56$page['cat_elements_id'] = array();
57if (is_numeric($_GET['cat']))
58{
59  $page['title'] =
60    get_cat_display_name_from_id(
61      $_GET['cat'],
62      PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
63      false
64      );
65
66  $query = '
67SELECT image_id
68  FROM '.IMAGE_CATEGORY_TABLE.'
69  WHERE category_id = '.$_GET['cat'].'
70;';
71  $page['cat_elements_id'] = array_from_query($query, 'image_id');
72}
73else if ('caddie' == $_GET['cat'])
74{
75  $page['title'] = l10n('caddie');
76
77  $query = '
78SELECT element_id
79  FROM '.CADDIE_TABLE.'
80  WHERE user_id = '.$user['id'].'
81;';
82  $page['cat_elements_id'] = array_from_query($query, 'element_id');
83}
84else if ('not_linked' == $_GET['cat'])
85{
86  $page['title'] = l10n('Not linked elements');
87  $template->assign(array('U_ACTIVE_MENU' => 5 ));
88
89  // we are searching elements not linked to any virtual category
90  $query = '
91SELECT id
92  FROM '.IMAGES_TABLE.'
93;';
94  $all_elements = array_from_query($query, 'id');
95
96  $linked_to_virtual = array();
97
98  $query = '
99SELECT id
100  FROM '.CATEGORIES_TABLE.'
101  WHERE dir IS NULL
102;';
103  $virtual_categories = array_from_query($query, 'id');
104  if (!empty($virtual_categories))
105  {
106    $query = '
107SELECT DISTINCT(image_id)
108  FROM '.IMAGE_CATEGORY_TABLE.'
109  WHERE category_id IN ('.implode(',', $virtual_categories).')
110;';
111    $linked_to_virtual = array_from_query($query, 'image_id');
112  }
113
114  $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
115}
116else if ('duplicates' == $_GET['cat'])
117{
118  $page['title'] = l10n('Files with same name in more than one physical category');
119  $template->assign(array('U_ACTIVE_MENU' => 5 ));
120
121  // we are searching related elements twice or more to physical categories
122  // 1 - Retrieve Files
123  $query = '
124SELECT DISTINCT(file)
125  FROM '.IMAGES_TABLE.'
126 GROUP BY file
127HAVING COUNT(DISTINCT storage_category_id) > 1
128;';
129
130  $duplicate_files = array_from_query($query, 'file');
131  $duplicate_files[]='Nofiles';
132  // 2 - Retrives related picture ids
133  $query = '
134SELECT id, file
135  FROM '.IMAGES_TABLE.'
136WHERE file IN (\''.implode("','", $duplicate_files).'\')
137ORDER BY file, id
138;';
139
140  $page['cat_elements_id'] = array_from_query($query, 'id');
141}
142elseif ('recent'== $_GET['cat'])
143{
144  $page['title'] = l10n('Recent pictures');
145  $query = 'SELECT MAX(date_available) AS date
146  FROM '.IMAGES_TABLE;
147  $row = pwg_db_fetch_assoc(pwg_query($query));
148  if (!empty($row['date']))
149  {
150    $query = 'SELECT id
151  FROM '.IMAGES_TABLE.'
152  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
153    $page['cat_elements_id'] = array_from_query($query, 'id');
154  }
155}
156
157// +-----------------------------------------------------------------------+
158// |                       first element to display                        |
159// +-----------------------------------------------------------------------+
160
161// $page['start'] contains the number of the first element in its
162// category. For exampe, $page['start'] = 12 means we must show elements #12
163// and $page['nb_images'] next elements
164
165if (!isset($_GET['start'])
166    or !is_numeric($_GET['start'])
167    or $_GET['start'] < 0
168    or (isset($_GET['display']) and 'all' == $_GET['display']))
169{
170  $page['start'] = 0;
171}
172else
173{
174  $page['start'] = $_GET['start'];
175}
176
177// +-----------------------------------------------------------------------+
178// |                         open specific mode                            |
179// +-----------------------------------------------------------------------+
180
181$_GET['mode'] = !empty($_GET['mode']) ? $_GET['mode'] : 'global';
182
183switch ($_GET['mode'])
184{
185  case 'global' :
186  {
187    include(dirname(__FILE__).'/element_set_global.php');
188    break;
189  }
190  case 'unit' :
191  {
192    include(PHPWG_ROOT_PATH.'admin/element_set_unit.php');
193    break;
194  }
195}
196?>
Note: See TracBrowser for help on using the repository browser.