Skip to content

Commit

Permalink
feature 2969: Unified Batch Manager URL
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@24834 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Oct 10, 2013
1 parent 92d692a commit cfdfeb9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 68 deletions.
4 changes: 2 additions & 2 deletions admin.php
Expand Up @@ -189,7 +189,7 @@
'U_CAT_OPTIONS'=> $link_start.'cat_options',
'U_CAT_UPDATE'=> $link_start.'site_update&site=1',
'U_RATING'=> $link_start.'rating',
'U_RECENT_SET'=> $link_start.'batch_manager&cat=recent',
'U_RECENT_SET'=> $link_start.'batch_manager&filter=prefilter-last_import',
'U_BATCH'=> $link_start.'batch_manager',
'U_TAGS'=> $link_start.'tags',
'U_USERS'=> $link_start.'user_list',
Expand Down Expand Up @@ -222,7 +222,7 @@
$template->assign(
array(
'NB_PHOTOS_IN_CADDIE' => $nb_photos_in_caddie,
'U_CADDIE' => $link_start.'batch_manager&cat=caddie',
'U_CADDIE' => $link_start.'batch_manager&filter=prefilter-caddie',
)
);
}
Expand Down
122 changes: 71 additions & 51 deletions admin/batch_manager.php
Expand Up @@ -43,10 +43,12 @@

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>';
Expand Down Expand Up @@ -109,39 +111,52 @@
}
}
}
else if (isset($_GET['cat']))
// filters from url
else if (isset($_GET['filter']))
{
if ('caddie' == $_GET['cat'])
{
$_SESSION['bulk_manager_filter'] = array(
'prefilter' => 'caddie'
);
}
else if ('recent' == $_GET['cat'])
if (!is_array($_GET['filter']))
{
$_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'
Expand All @@ -150,13 +165,13 @@

// 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.'
Expand All @@ -166,10 +181,10 @@
$filter_sets,
array_from_query($query, 'element_id')
);
}

break;

if ('favorites' == $_SESSION['bulk_manager_filter']['prefilter'])
{
case 'favorites':
$query = '
SELECT image_id
FROM '.FAVORITES_TABLE.'
Expand All @@ -179,10 +194,10 @@
$filter_sets,
array_from_query($query, 'image_id')
);
}

break;

if ('last import'== $_SESSION['bulk_manager_filter']['prefilter'])
{
case 'last_import':
$query = '
SELECT MAX(date_available) AS date
FROM '.IMAGES_TABLE.'
Expand All @@ -200,10 +215,10 @@
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
Expand Down Expand Up @@ -231,10 +246,10 @@
$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
Expand All @@ -246,10 +261,10 @@
$filter_sets,
array_from_query($query, 'id')
);
}

break;

if ('with no tag' == $_SESSION['bulk_manager_filter']['prefilter'])
{
case 'no_tag':
$query = '
SELECT
id
Expand All @@ -261,15 +276,14 @@
$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.'
Expand All @@ -288,16 +302,18 @@
$filter_sets,
array_from_query($query, 'id')
);
}

break;

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']);
Expand Down Expand Up @@ -403,6 +419,7 @@
}
$page['cat_elements_id'] = $current_set;


// +-----------------------------------------------------------------------+
// | first element to display |
// +-----------------------------------------------------------------------+
Expand All @@ -423,6 +440,7 @@
$page['start'] = $_REQUEST['start'];
}


// +-----------------------------------------------------------------------+
// | Tabs |
// +-----------------------------------------------------------------------+
Expand All @@ -442,6 +460,7 @@
$tabsheet->select($page['tab']);
$tabsheet->assign();


// +-----------------------------------------------------------------------+
// | tags |
// +-----------------------------------------------------------------------+
Expand All @@ -452,6 +471,7 @@
;';
$template->assign('tags', get_taglist($query, false));


// +-----------------------------------------------------------------------+
// | dimensions |
// +-----------------------------------------------------------------------+
Expand Down
22 changes: 11 additions & 11 deletions admin/batch_manager_global.php
Expand Up @@ -112,7 +112,7 @@
$tag_ids = get_tag_ids($_POST['add_tags']);
add_tags($tag_ids, $collection);

if ('with no tag' == $page['prefilter'])
if ('no_tag' == $page['prefilter'])
{
redirect($redirect_url);
}
Expand Down Expand Up @@ -149,12 +149,12 @@
);

// let's refresh the page because we the current set might be modified
if ('with no album' == $page['prefilter'])
if ('no_album' == $page['prefilter'])
{
redirect($redirect_url);
}

if ('with no virtual album' == $page['prefilter'])
if ('no_virtual_album' == $page['prefilter'])
{
$category_info = get_cat_info($_POST['associate']);
if (empty($category_info['dir']))
Expand All @@ -173,12 +173,12 @@
);

// let's refresh the page because we the current set might be modified
if ('with no album' == $page['prefilter'])
if ('no_album' == $page['prefilter'])
{
redirect($redirect_url);
}

if ('with no virtual album' == $page['prefilter'])
if ('no_virtual_album' == $page['prefilter'])
{
$category_info = get_cat_info($_POST['move']);
if (empty($category_info['dir']))
Expand Down Expand Up @@ -435,17 +435,17 @@
$prefilters = array(
array('ID' => 'caddie', 'NAME' => l10n('Caddie')),
array('ID' => 'favorites', 'NAME' => l10n('Your favorites')),
array('ID' => 'last import', 'NAME' => l10n('Last import')),
array('ID' => 'with no album', 'NAME' => l10n('With no album')),
array('ID' => 'with no tag', 'NAME' => l10n('With no tag')),
array('ID' => 'last_import', 'NAME' => l10n('Last import')),
array('ID' => 'no_album', 'NAME' => l10n('With no album')),
array('ID' => 'no_tag', 'NAME' => l10n('With no tag')),
array('ID' => 'duplicates', 'NAME' => l10n('Duplicates')),
array('ID' => 'all photos', 'NAME' => l10n('All'))
array('ID' => 'all_photos', 'NAME' => l10n('All'))
);

if ($conf['enable_synchronization'])
{
array_push($prefilters,
array('ID' => 'with no virtual album', 'NAME' => l10n('With no virtual album'))
array('ID' => 'no_virtual_album', 'NAME' => l10n('With no virtual album'))
);
}

Expand All @@ -460,7 +460,7 @@
'all_elements' => $page['cat_elements_id'],
'START' => $page['start'],
'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
'F_ACTION'=>$base_url.get_query_string_diff(array('cat','start','tag')),
'F_ACTION'=>$base_url.get_query_string_diff(array('cat','start','tag','filter')),
)
);

Expand Down
2 changes: 1 addition & 1 deletion admin/cat_list.php
Expand Up @@ -322,7 +322,7 @@ function save_categories_order($categories)
if ( array_key_exists($category['id'], $categories_with_images) )
{
$tpl_cat['U_MANAGE_ELEMENTS']=
$base_url.'batch_manager&amp;cat='.$category['id'];
$base_url.'batch_manager&amp;filter=album-'.$category['id'];
}

$template->append('categories', $tpl_cat);
Expand Down
2 changes: 1 addition & 1 deletion admin/cat_modify.php
Expand Up @@ -252,7 +252,7 @@ function get_site_url($category_id)
{
$template->assign(
'U_MANAGE_ELEMENTS',
$base_url.'batch_manager&amp;cat='.$category['id']
$base_url.'batch_manager&amp;filter=album-'.$category['id']
);

$query = '
Expand Down
2 changes: 1 addition & 1 deletion admin/photos_add_direct.php
Expand Up @@ -57,7 +57,7 @@
$inserts
);

redirect(get_root_url().'admin.php?page=batch_manager&cat=caddie');
redirect(get_root_url().'admin.php?page=batch_manager&filter=prefilter-caddie');
}

// +-----------------------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion admin/tags.php
Expand Up @@ -461,7 +461,7 @@
$tag['name'] = trigger_event('render_tag_name', $raw_name);
$tag['counter'] = intval(@$tag_counters[ $tag['id'] ]);
$tag['U_VIEW'] = make_index_url(array('tags'=>array($tag)));
$tag['U_EDIT'] = 'admin.php?page=batch_manager&amp;tag='.$tag['id'];
$tag['U_EDIT'] = 'admin.php?page=batch_manager&amp;filter=tag-'.$tag['id'];

$alt_names = trigger_event('get_tag_alt_names', array(), $raw_name);
$alt_names = array_diff( array_unique($alt_names), array($tag['name']) );
Expand Down

0 comments on commit cfdfeb9

Please sign in to comment.