source: trunk/admin/batch_manager.php @ 12581

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

bug 2449 fixed: in the "tags box" on batch manager and picture_modify, we
should only display the tag in the current user language, not the tag in all
available languages.

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