aboutsummaryrefslogtreecommitdiffstats
path: root/admin/batch_manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/batch_manager.php')
-rw-r--r--admin/batch_manager.php207
1 files changed, 108 insertions, 99 deletions
diff --git a/admin/batch_manager.php b/admin/batch_manager.php
index a5c82d061..2cb76f7e1 100644
--- a/admin/batch_manager.php
+++ b/admin/batch_manager.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -43,10 +43,12 @@ check_status(ACCESS_ADMINISTRATOR);
check_input_parameter('selection', $_POST, true, PATTERN_ID);
+
// +-----------------------------------------------------------------------+
// | initialize current set |
// +-----------------------------------------------------------------------+
+// filters from form
if (isset($_POST['submitFilter']))
{
// echo '<pre>'; print_r($_POST); echo '</pre>';
@@ -109,39 +111,52 @@ if (isset($_POST['submitFilter']))
}
}
}
-else if (isset($_GET['cat']))
+// filters from url
+else if (isset($_GET['filter']))
{
- if ('caddie' == $_GET['cat'])
+ if (!is_array($_GET['filter']))
{
- $_SESSION['bulk_manager_filter'] = array(
- 'prefilter' => 'caddie'
- );
- }
- else if ('recent' == $_GET['cat'])
- {
- $_SESSION['bulk_manager_filter'] = array(
- 'prefilter' => 'last import'
- );
+ $_GET['filter'] = explode(',', $_GET['filter']);
}
- else if (is_numeric($_GET['cat']))
- {
- $_SESSION['bulk_manager_filter'] = array(
- 'category' => $_GET['cat']
- );
- }
-}
-else if (isset($_GET['tag']))
-{
- if (is_numeric($_GET['tag']))
+
+ $_SESSION['bulk_manager_filter'] = array();
+
+ foreach ($_GET['filter'] as $filter)
{
- $_SESSION['bulk_manager_filter'] = array(
- 'tags' => array($_GET['tag']),
- 'tag_mode' => 'AND',
- );
+ list($type, $value) = explode('-', $filter);
+
+ switch ($type)
+ {
+ case 'prefilter':
+ $_SESSION['bulk_manager_filter']['prefilter'] = $value;
+ break;
+
+ case 'album':
+ if (is_numeric($value))
+ {
+ $_SESSION['bulk_manager_filter']['category'] = $value;
+ }
+ break;
+
+ case 'tag':
+ if (is_numeric($value))
+ {
+ $_SESSION['bulk_manager_filter']['tags'] = array($value);
+ $_SESSION['bulk_manager_filter']['tag_mode'] = 'AND';
+ }
+ break;
+
+ case 'level':
+ if (is_numeric($value) && in_array($value, $conf['available_permission_levels']))
+ {
+ $_SESSION['bulk_manager_filter']['level'] = $value;
+ }
+ break;
+ }
}
}
-if (!isset($_SESSION['bulk_manager_filter']))
+if (empty($_SESSION['bulk_manager_filter']))
{
$_SESSION['bulk_manager_filter'] = array(
'prefilter' => 'caddie'
@@ -150,26 +165,33 @@ if (!isset($_SESSION['bulk_manager_filter']))
// echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>';
-// depending on the current filter (in session), we find the appropriate
-// photos
+// depending on the current filter (in session), we find the appropriate photos
$filter_sets = array();
if (isset($_SESSION['bulk_manager_filter']['prefilter']))
{
- if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter'])
+ switch ($_SESSION['bulk_manager_filter']['prefilter'])
{
+ case 'caddie':
$query = '
SELECT element_id
FROM '.CADDIE_TABLE.'
WHERE user_id = '.$user['id'].'
;';
- array_push(
- $filter_sets,
- array_from_query($query, 'element_id')
- );
- }
+ $filter_sets[] = array_from_query($query, 'element_id');
+
+ break;
- if ('last import'== $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'favorites':
+ $query = '
+SELECT image_id
+ FROM '.FAVORITES_TABLE.'
+ WHERE user_id = '.$user['id'].'
+;';
+ $filter_sets[] = array_from_query($query, 'image_id');
+
+ break;
+
+ case 'last_import':
$query = '
SELECT MAX(date_available) AS date
FROM '.IMAGES_TABLE.'
@@ -182,15 +204,12 @@ SELECT id
FROM '.IMAGES_TABLE.'
WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'
;';
- array_push(
- $filter_sets,
- array_from_query($query, 'id')
- );
+ $filter_sets[] = array_from_query($query, 'id');
}
- }
+
+ break;
- if ('with no virtual album' == $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'no_virtual_album':
// we are searching elements not linked to any virtual category
$query = '
SELECT id
@@ -214,14 +233,11 @@ SELECT id
$linked_to_virtual = array_from_query($query, 'image_id');
}
- array_push(
- $filter_sets,
- array_diff($all_elements, $linked_to_virtual)
- );
- }
+ $filter_sets[] = array_diff($all_elements, $linked_to_virtual);
+
+ break;
- if ('with no album' == $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'no_album':
$query = '
SELECT
id
@@ -229,14 +245,11 @@ SELECT
LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
WHERE category_id is null
;';
- array_push(
- $filter_sets,
- array_from_query($query, 'id')
- );
- }
+ $filter_sets[] = array_from_query($query, 'id');
+
+ break;
- if ('with no tag' == $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'no_tag':
$query = '
SELECT
id
@@ -244,19 +257,15 @@ SELECT
LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id
WHERE tag_id is null
;';
- array_push(
- $filter_sets,
- array_from_query($query, 'id')
- );
- }
+ $filter_sets[] = array_from_query($query, 'id');
+
+ break;
- if ('duplicates' == $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'duplicates':
// we could use the group_concat MySQL function to retrieve the list of
// image_ids but it would not be compatible with PostgreSQL, so let's
// perform 2 queries instead. We hope there are not too many duplicates.
-
$query = '
SELECT file
FROM '.IMAGES_TABLE.'
@@ -268,23 +277,21 @@ SELECT file
$query = '
SELECT id
FROM '.IMAGES_TABLE.'
- WHERE file IN (\''.implode("','", $duplicate_files).'\')
+ WHERE file IN (\''.implode("','", array_map('pwg_db_real_escape_string', $duplicate_files)).'\')
;';
+ $filter_sets[] = array_from_query($query, 'id');
+
+ break;
- array_push(
- $filter_sets,
- array_from_query($query, 'id')
- );
- }
-
- if ('all photos' == $_SESSION['bulk_manager_filter']['prefilter'])
- {
+ case 'all_photos':
$query = '
SELECT id
FROM '.IMAGES_TABLE.'
'.$conf['order_by'];
$filter_sets[] = array_from_query($query, 'id');
+
+ break;
}
$filter_sets = trigger_event('perform_batch_manager_prefilters', $filter_sets, $_SESSION['bulk_manager_filter']['prefilter']);
@@ -308,10 +315,7 @@ if (isset($_SESSION['bulk_manager_filter']['category']))
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id IN ('.implode(',', $categories).')
;';
- array_push(
- $filter_sets,
- array_from_query($query, 'image_id')
- );
+ $filter_sets[] = array_from_query($query, 'image_id');
}
if (isset($_SESSION['bulk_manager_filter']['level']))
@@ -333,15 +337,12 @@ SELECT id
if (!empty($_SESSION['bulk_manager_filter']['tags']))
{
- array_push(
- $filter_sets,
- get_image_ids_for_tags(
- $_SESSION['bulk_manager_filter']['tags'],
- $_SESSION['bulk_manager_filter']['tag_mode'],
- null,
- null,
- false // we don't apply permissions in administration screens
- )
+ $filter_sets[] = get_image_ids_for_tags(
+ $_SESSION['bulk_manager_filter']['tags'],
+ $_SESSION['bulk_manager_filter']['tag_mode'],
+ null,
+ null,
+ false // we don't apply permissions in administration screens
);
}
@@ -390,6 +391,7 @@ foreach ($filter_sets as $set)
}
$page['cat_elements_id'] = $current_set;
+
// +-----------------------------------------------------------------------+
// | first element to display |
// +-----------------------------------------------------------------------+
@@ -410,6 +412,7 @@ else
$page['start'] = $_REQUEST['start'];
}
+
// +-----------------------------------------------------------------------+
// | Tabs |
// +-----------------------------------------------------------------------+
@@ -429,6 +432,7 @@ $tabsheet->set_id('batch_manager');
$tabsheet->select($page['tab']);
$tabsheet->assign();
+
// +-----------------------------------------------------------------------+
// | tags |
// +-----------------------------------------------------------------------+
@@ -439,6 +443,7 @@ SELECT id, name
;';
$template->assign('tags', get_taglist($query, false));
+
// +-----------------------------------------------------------------------+
// | dimensions |
// +-----------------------------------------------------------------------+
@@ -457,21 +462,25 @@ SELECT
;';
$result = pwg_query($query);
-if (!pwg_db_num_rows($result))
-{ // arbitrary values, only used when no photos on the gallery
- $widths = array(600, 1920, 3500);
- $heights = array(480, 1080, 2300);
- $ratios = array(1.25, 1.52, 1.78);
-}
-else
+if (pwg_db_num_rows($result))
{
while ($row = pwg_db_fetch_assoc($result))
{
- $widths[] = $row['width'];
- $heights[] = $row['height'];
- $ratios[] = floor($row['width'] * 100 / $row['height']) / 100;
+ if ($row['width']>0 && $row['height']>0)
+ {
+ $widths[] = $row['width'];
+ $heights[] = $row['height'];
+ $ratios[] = floor($row['width'] / $row['height'] * 100) / 100;
+ }
}
}
+if (empty($widths))
+{ // arbitrary values, only used when no photos on the gallery
+ $widths = array(600, 1920, 3500);
+ $heights = array(480, 1080, 2300);
+ $ratios = array(1.25, 1.52, 1.78);
+}
+
$widths = array_unique($widths);
@@ -530,7 +539,7 @@ foreach (array_keys($ratio_categories) as $ratio_category)
{
$dimensions['ratio_'.$ratio_category] = array(
'min' => $ratio_categories[$ratio_category][0],
- 'max' => $ratio_categories[$ratio_category][count($ratio_categories[$ratio_category]) - 1]
+ 'max' => array_pop($ratio_categories[$ratio_category]),
);
}
}