source: extensions/batch_manager_prefilters/main.inc.php @ 11258

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

Small bug fixed

File size: 2.4 KB
Line 
1<?php
2/*
3Plugin Name: Batch Manager Prefilters
4Version: auto
5Description: Add some prefilters in Batch Manager.
6Plugin URI: auto
7Author: P@t
8Author URI: http://www.gauchon.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13add_event_handler('get_batch_manager_prefilters', 'add_bmp');
14add_event_handler('perform_batch_manager_prefilters', 'perform_bmp', 50, 2);
15add_event_handler('element_set_global_action', 'element_set_global_action_bmp');
16
17function add_bmp($prefilters)
18{
19  load_language('plugin.lang', dirname(__FILE__).'/');
20
21  array_push($prefilters,
22    array('ID' => 'with tags', 'NAME' => l10n('with tags')),
23    array('ID' => 'with HD', 'NAME' => l10n('with HD')),
24    array('ID' => 'without HD', 'NAME' => l10n('without HD')),
25    array('ID' => 'with author', 'NAME' => l10n('with author')),
26    array('ID' => 'without author', 'NAME' => l10n('without author'))
27  );
28
29  return $prefilters;
30}
31
32function perform_bmp($filter_sets, $prefilter)
33{
34  if ('with tags' == $prefilter)
35  {
36    $query = 'SELECT DISTINCT image_id FROM '.IMAGE_TAG_TABLE.';';
37    array_push($filter_sets, array_from_query($query, 'image_id'));
38  }
39
40  if ('with HD' == $prefilter)
41  {
42    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE has_high IS NOT NULL;';
43    array_push($filter_sets, array_from_query($query, 'id'));
44  }
45
46  if ('without HD' == $prefilter)
47  {
48    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE has_high IS NULL;';
49    array_push($filter_sets, array_from_query($query, 'id'));
50  }
51
52  if ('with author' == $prefilter)
53  {
54    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NOT NULL;';
55    array_push($filter_sets, array_from_query($query, 'id'));
56  }
57
58  if ('without author' == $prefilter)
59  {
60    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NULL;';
61    array_push($filter_sets, array_from_query($query, 'id'));
62  }
63
64  return $filter_sets;
65}
66
67function element_set_global_action_bmp($action)
68{
69  if ((@$_SESSION['bulk_manager_filter']['prefilter'] == 'with tags' and in_array($action, array('add_tags', 'del_tags')))
70    or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with author', 'without author')) and $action == 'author'))
71  {
72    // let's refresh the page because we the current set might be modified
73    redirect(get_root_url().'admin.php?page='.$_GET['page']);
74  }
75}
76
77?>
Note: See TracBrowser for help on using the repository browser.