1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | add_event_handler('get_batch_manager_prefilters', 'CR_add_bm_filter'); |
---|
6 | add_event_handler('perform_batch_manager_prefilters', 'CR_perform_bm_filter', 50, 2); |
---|
7 | add_event_handler('element_set_global_action', 'CR_element_set_bm_global_action'); |
---|
8 | |
---|
9 | // Add the filter to the list |
---|
10 | function CR_add_bm_filter($prefilters) |
---|
11 | { |
---|
12 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
13 | |
---|
14 | array_push($prefilters, |
---|
15 | array('ID' => 'with copyright', 'NAME' => l10n('With copyright')), |
---|
16 | array('ID' => 'without copyright', 'NAME' => l10n('Without copyright')) |
---|
17 | ); |
---|
18 | |
---|
19 | return $prefilters; |
---|
20 | } |
---|
21 | |
---|
22 | // Put the right photos in the prefilter array |
---|
23 | function CR_perform_bm_filter($filter_sets, $prefilter) |
---|
24 | { |
---|
25 | if ('with copyright' == $prefilter) { |
---|
26 | // Select all photos in the copyrights table who´s CR not is 0 |
---|
27 | $query = sprintf(' |
---|
28 | SELECT media_id |
---|
29 | FROM %s |
---|
30 | WHERE cr_id <> 0 |
---|
31 | ;', |
---|
32 | COPYRIGHTS_MEDIA); |
---|
33 | array_push($filter_sets, array_from_query($query, 'media_id')); |
---|
34 | } |
---|
35 | |
---|
36 | if ('without copyright' == $prefilter) { |
---|
37 | $query = sprintf(' |
---|
38 | SELECT id |
---|
39 | FROM %s |
---|
40 | WHERE id NOT IN ( |
---|
41 | SELECT media_id |
---|
42 | FROM %s |
---|
43 | WHERE cr_id <> 0 |
---|
44 | ) |
---|
45 | ;', |
---|
46 | IMAGES_TABLE, COPYRIGHTS_MEDIA); |
---|
47 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
48 | } |
---|
49 | |
---|
50 | return $filter_sets; |
---|
51 | } |
---|
52 | |
---|
53 | // Test if the filters aren't set incorrectly |
---|
54 | function CR_element_set_bm_global_action($action) |
---|
55 | { |
---|
56 | if (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with copyrights', 'without copyrights')) and $action == 'copyrights') { |
---|
57 | // let's refresh the page because we the current set might be modified |
---|
58 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | ?> |
---|