source: trunk/admin/batch_manager.php @ 8413

Last change on this file since 8413 was 8413, checked in by plg, 13 years ago

feature 2089: Batch Manager, switch from global to unit mode with tabs

File size: 8.9 KB
RevLine 
[8394]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');
[8413]36include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[8394]37
38// +-----------------------------------------------------------------------+
39// | Check Access and exit when user status is not ok                      |
40// +-----------------------------------------------------------------------+
41
42check_status(ACCESS_ADMINISTRATOR);
43
44check_input_parameter('selection', $_POST, true, PATTERN_ID);
45
46// +-----------------------------------------------------------------------+
47// |                      initialize current set                           |
48// +-----------------------------------------------------------------------+
49
50if (isset($_POST['submitFilter']))
51{
52  // echo '<pre>'; print_r($_POST); echo '</pre>';
53 
54  $_SESSION['bulk_manager_filter'] = array();
55
56  if (isset($_POST['filter_prefilter_use']))
57  {
[8404]58    $prefilters = array('caddie', 'last import', 'with no album', 'with no tag', 'with no virtual album', 'duplicates');
[8394]59    if (in_array($_POST['filter_prefilter'], $prefilters))
60    {
61      $_SESSION['bulk_manager_filter']['prefilter'] = $_POST['filter_prefilter'];
62    }   
63  }
64
65  if (isset($_POST['filter_category_use']))
66  {
67    $_SESSION['bulk_manager_filter']['category'] = $_POST['filter_category'];
68
69    if (isset($_POST['filter_category_recursive']))
70    {
71      $_SESSION['bulk_manager_filter']['category_recursive'] = true;
72    }
73  }
74
75  if (isset($_POST['filter_level_use']))
76  {
77    if (in_array($_POST['filter_level'], $conf['available_permission_levels']))
78    {
79      $_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level'];
80    }
81  }
82}
83
84if (isset($_GET['cat']))
85{
86  if ('caddie' == $_GET['cat'])
87  {
88    $_SESSION['bulk_manager_filter'] = array(
89      'prefilter' => 'caddie'
90      );
91  }
92
93  if (is_numeric($_GET['cat']))
94  {
95    $_SESSION['bulk_manager_filter'] = array(
96      'category' => $_GET['cat']
97      );
98  }
99}
100
101if (!isset($_SESSION['bulk_manager_filter']))
102{
103  $_SESSION['bulk_manager_filter'] = array(
104    'prefilter' => 'caddie'
105    );
106}
107
108// echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>';
109
110// depending on the current filter (in session), we find the appropriate
111// photos
112$filter_sets = array();
113if (isset($_SESSION['bulk_manager_filter']['prefilter']))
114{
115  if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter'])
116  {
117    $query = '
118SELECT element_id
119  FROM '.CADDIE_TABLE.'
120  WHERE user_id = '.$user['id'].'
121;';
122    array_push(
123      $filter_sets,
124      array_from_query($query, 'element_id')
125      );
126  }
127
128  if ('last import'== $_SESSION['bulk_manager_filter']['prefilter'])
129  {
130    $query = '
131SELECT MAX(date_available) AS date
132  FROM '.IMAGES_TABLE.'
133;';
134    $row = pwg_db_fetch_assoc(pwg_query($query));
135    if (!empty($row['date']))
136    {
137      $query = '
138SELECT id
139  FROM '.IMAGES_TABLE.'
140  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'
141;';
142      array_push(
143        $filter_sets,
144        array_from_query($query, 'id')
145        );
146    }
147  }
[8403]148
149  if ('with no virtual album' == $_SESSION['bulk_manager_filter']['prefilter'])
150  {
151    // we are searching elements not linked to any virtual category
152    $query = '
153 SELECT id
154   FROM '.IMAGES_TABLE.'
155 ;';
156    $all_elements = array_from_query($query, 'id');
157 
158    $query = '
159 SELECT id
160   FROM '.CATEGORIES_TABLE.'
161   WHERE dir IS NULL
162 ;';
163    $virtual_categories = array_from_query($query, 'id');
164    if (!empty($virtual_categories))
165    {
166      $query = '
167 SELECT DISTINCT(image_id)
168   FROM '.IMAGE_CATEGORY_TABLE.'
169   WHERE category_id IN ('.implode(',', $virtual_categories).')
170 ;';
171      $linked_to_virtual = array_from_query($query, 'image_id');
172    }
173
174    array_push(
175      $filter_sets,
176      array_diff($all_elements, $linked_to_virtual)
177      );
178  }
[8404]179
180  if ('duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
181  {
182    // we could use the group_concat MySQL function to retrieve the list of
183    // image_ids but it would not be compatible with PostgreSQL, so let's
184    // perform 2 queries instead. We hope there are not too many duplicates.
185   
186    $query = '
187SELECT file
188  FROM '.IMAGES_TABLE.'
189  GROUP BY file
190  HAVING COUNT(*) > 1
191;';
192    $duplicate_files = array_from_query($query, 'file');
193   
194    $query = '
195SELECT id
196  FROM '.IMAGES_TABLE.'
197  WHERE file IN (\''.implode("','", $duplicate_files).'\')
198;';
199
200    array_push(
201      $filter_sets,
202      array_from_query($query, 'id')
203      );
204  }
[8394]205}
206
207if (isset($_SESSION['bulk_manager_filter']['category']))
208{
209  $categories = array();
210 
211  if (isset($_SESSION['bulk_manager_filter']['category_recursive']))
212  {
213    $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category']));
214  }
215  else
216  {
217    $categories = array($_SESSION['bulk_manager_filter']['category']);
218  }
219 
220  $query = '
221 SELECT DISTINCT(image_id)
222   FROM '.IMAGE_CATEGORY_TABLE.'
223   WHERE category_id IN ('.implode(',', $categories).')
224 ;';
225  array_push(
226    $filter_sets,
227    array_from_query($query, 'image_id')
228    );
229}
230
231if (isset($_SESSION['bulk_manager_filter']['level']))
232{
233  $query = '
234SELECT id
235  FROM '.IMAGES_TABLE.'
236  WHERE level >= '.$_SESSION['bulk_manager_filter']['level'].'
237;';
238  array_push(
239    $filter_sets,
240    array_from_query($query, 'id')
241    );
242}
243
244$current_set = array_shift($filter_sets);
245foreach ($filter_sets as $set)
246{
247  $current_set = array_intersect($current_set, $set);
248}
249$page['cat_elements_id'] = $current_set;
250
251// +-----------------------------------------------------------------------+
252// |                       first element to display                        |
253// +-----------------------------------------------------------------------+
254
255// $page['start'] contains the number of the first element in its
256// category. For exampe, $page['start'] = 12 means we must show elements #12
257// and $page['nb_images'] next elements
258
259if (!isset($_GET['start'])
260    or !is_numeric($_GET['start'])
261    or $_GET['start'] < 0
262    or (isset($_GET['display']) and 'all' == $_GET['display']))
263{
264  $page['start'] = 0;
265}
266else
267{
268  $page['start'] = $_GET['start'];
269}
270
271// +-----------------------------------------------------------------------+
[8413]272// |                                 Tabs                                  |
[8394]273// +-----------------------------------------------------------------------+
274
[8413]275$tabs = array(
276  array(
277    'code' => 'global',
278    'label' => l10n('global mode'),
279    ),
280  array(
281    'code' => 'unit',
282    'label' => l10n('unit mode'),
283    ),
284  );
[8394]285
[8413]286$tab_codes = array_map(
287  create_function('$a', 'return $a["code"];'),
288  $tabs
289  );
290
291if (isset($_GET['mode']) and in_array($_GET['mode'], $tab_codes))
[8394]292{
[8413]293  $page['tab'] = $_GET['mode'];
[8394]294}
[8413]295else
296{
297  $page['tab'] = $tabs[0]['code'];
298}
299
300$tabsheet = new tabsheet();
301foreach ($tabs as $tab)
302{
303  $tabsheet->add(
304    $tab['code'],
305    $tab['label'],
306    get_root_url().'admin.php?page='.$_GET['page'].'&amp;mode='.$tab['code']
307    );
308}
309$tabsheet->select($page['tab']);
310$tabsheet->assign();
311
312// +-----------------------------------------------------------------------+
313// |                         open specific mode                            |
314// +-----------------------------------------------------------------------+
315
316include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php');
[8394]317?>
Note: See TracBrowser for help on using the repository browser.