source: extensions/regenerateThumbnails/admin.php @ 11217

Last change on this file since 11217 was 9931, checked in by patdenice, 13 years ago

Update configuration after regeneration.

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