source: trunk/admin/batch_manager.php @ 9068

Last change on this file since 9068 was 9068, checked in by rvelices, 13 years ago

allow to include batch_manager with a mode <> than global/unit (don't create tabsheet and dont include global/unit.php); used by rv_gmaps to batch edit lat/lon

File size: 9.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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');
36include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
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  {
58    $prefilters = array('caddie', 'last import', 'with no album', 'with no tag', 'with no virtual album', 'duplicates');
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 ('recent' == $_GET['cat'])
94  {
95    $_SESSION['bulk_manager_filter'] = array(
96      'prefilter' => 'last import'
97      );
98  }
99
100  if (is_numeric($_GET['cat']))
101  {
102    $_SESSION['bulk_manager_filter'] = array(
103      'category' => $_GET['cat']
104      );
105  }
106}
107
108if (!isset($_SESSION['bulk_manager_filter']))
109{
110  $_SESSION['bulk_manager_filter'] = array(
111    'prefilter' => 'caddie'
112    );
113}
114
115// echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>';
116
117// depending on the current filter (in session), we find the appropriate
118// photos
119$filter_sets = array();
120if (isset($_SESSION['bulk_manager_filter']['prefilter']))
121{
122  if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter'])
123  {
124    $query = '
125SELECT element_id
126  FROM '.CADDIE_TABLE.'
127  WHERE user_id = '.$user['id'].'
128;';
129    array_push(
130      $filter_sets,
131      array_from_query($query, 'element_id')
132      );
133  }
134
135  if ('last import'== $_SESSION['bulk_manager_filter']['prefilter'])
136  {
137    $query = '
138SELECT MAX(date_available) AS date
139  FROM '.IMAGES_TABLE.'
140;';
141    $row = pwg_db_fetch_assoc(pwg_query($query));
142    if (!empty($row['date']))
143    {
144      $query = '
145SELECT id
146  FROM '.IMAGES_TABLE.'
147  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'
148;';
149      array_push(
150        $filter_sets,
151        array_from_query($query, 'id')
152        );
153    }
154  }
155
156  if ('with no virtual album' == $_SESSION['bulk_manager_filter']['prefilter'])
157  {
158    // we are searching elements not linked to any virtual category
159    $query = '
160 SELECT id
161   FROM '.IMAGES_TABLE.'
162 ;';
163    $all_elements = array_from_query($query, 'id');
164
165    $query = '
166 SELECT id
167   FROM '.CATEGORIES_TABLE.'
168   WHERE dir IS NULL
169 ;';
170    $virtual_categories = array_from_query($query, 'id');
171    if (!empty($virtual_categories))
172    {
173      $query = '
174 SELECT DISTINCT(image_id)
175   FROM '.IMAGE_CATEGORY_TABLE.'
176   WHERE category_id IN ('.implode(',', $virtual_categories).')
177 ;';
178      $linked_to_virtual = array_from_query($query, 'image_id');
179    }
180
181    array_push(
182      $filter_sets,
183      array_diff($all_elements, $linked_to_virtual)
184      );
185  }
186
187  if ('with no album' == $_SESSION['bulk_manager_filter']['prefilter'])
188  {
189    $query = '
190SELECT
191    id
192  FROM '.IMAGES_TABLE.'
193    LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
194  WHERE category_id is null
195;';
196    array_push(
197      $filter_sets,
198      array_from_query($query, 'id')
199      );
200  }
201
202  if ('with no tag' == $_SESSION['bulk_manager_filter']['prefilter'])
203  {
204    $query = '
205SELECT
206    id
207  FROM '.IMAGES_TABLE.'
208    LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id
209  WHERE tag_id is null
210;';
211    array_push(
212      $filter_sets,
213      array_from_query($query, 'id')
214      );
215  }
216
217
218  if ('duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
219  {
220    // we could use the group_concat MySQL function to retrieve the list of
221    // image_ids but it would not be compatible with PostgreSQL, so let's
222    // perform 2 queries instead. We hope there are not too many duplicates.
223
224    $query = '
225SELECT file
226  FROM '.IMAGES_TABLE.'
227  GROUP BY file
228  HAVING COUNT(*) > 1
229;';
230    $duplicate_files = array_from_query($query, 'file');
231
232    $query = '
233SELECT id
234  FROM '.IMAGES_TABLE.'
235  WHERE file IN (\''.implode("','", $duplicate_files).'\')
236;';
237
238    array_push(
239      $filter_sets,
240      array_from_query($query, 'id')
241      );
242  }
243}
244
245if (isset($_SESSION['bulk_manager_filter']['category']))
246{
247  $categories = array();
248
249  if (isset($_SESSION['bulk_manager_filter']['category_recursive']))
250  {
251    $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category']));
252  }
253  else
254  {
255    $categories = array($_SESSION['bulk_manager_filter']['category']);
256  }
257
258  $query = '
259 SELECT DISTINCT(image_id)
260   FROM '.IMAGE_CATEGORY_TABLE.'
261   WHERE category_id IN ('.implode(',', $categories).')
262 ;';
263  array_push(
264    $filter_sets,
265    array_from_query($query, 'image_id')
266    );
267}
268
269if (isset($_SESSION['bulk_manager_filter']['level']))
270{
271  $query = '
272SELECT id
273  FROM '.IMAGES_TABLE.'
274  WHERE level >= '.$_SESSION['bulk_manager_filter']['level'].'
275;';
276  array_push(
277    $filter_sets,
278    array_from_query($query, 'id')
279    );
280}
281
282$current_set = array_shift($filter_sets);
283foreach ($filter_sets as $set)
284{
285  $current_set = array_intersect($current_set, $set);
286}
287$page['cat_elements_id'] = $current_set;
288
289// +-----------------------------------------------------------------------+
290// |                       first element to display                        |
291// +-----------------------------------------------------------------------+
292
293// $page['start'] contains the number of the first element in its
294// category. For exampe, $page['start'] = 12 means we must show elements #12
295// and $page['nb_images'] next elements
296
297if (!isset($_GET['start'])
298    or !is_numeric($_GET['start'])
299    or $_GET['start'] < 0
300    or (isset($_GET['display']) and 'all' == $_GET['display']))
301{
302  $page['start'] = 0;
303}
304else
305{
306  $page['start'] = $_GET['start'];
307}
308
309// +-----------------------------------------------------------------------+
310// |                                 Tabs                                  |
311// +-----------------------------------------------------------------------+
312
313$tabs = array(
314  array(
315    'code' => 'global',
316    'label' => l10n('global mode'),
317    ),
318  array(
319    'code' => 'unit',
320    'label' => l10n('unit mode'),
321    ),
322  );
323
324$tab_codes = array_map(
325  create_function('$a', 'return $a["code"];'),
326  $tabs
327  );
328
329if (isset($_GET['mode']))
330{
331  $page['tab'] = $_GET['mode'];
332}
333else
334{
335  $page['tab'] = $tabs[0]['code'];
336}
337
338if (in_array($page['tab'], $tab_codes))
339{
340  $tabsheet = new tabsheet();
341  foreach ($tabs as $tab)
342  {
343    $tabsheet->add(
344      $tab['code'],
345      $tab['label'],
346      get_root_url().'admin.php?page='.$_GET['page'].'&amp;mode='.$tab['code']
347      );
348  }
349  $tabsheet->select($page['tab']);
350  $tabsheet->assign();
351
352// +-----------------------------------------------------------------------+
353// |                         open specific mode                            |
354// +-----------------------------------------------------------------------+
355
356  include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php');
357}
358?>
Note: See TracBrowser for help on using the repository browser.