source: trunk/admin/batch_manager.php @ 8404

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

feature 2089: add the "duplicates" feature to the new Batch Manager and
simplify the algorithm. The duplicates do not rely on physical albums, just
on duplicate filenames.

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