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 | // Select all photo's, except the ones that have a copyright |
---|
38 | $query = sprintf(' |
---|
39 | SELECT id |
---|
40 | FROM %s |
---|
41 | WHERE id NOT IN ( |
---|
42 | SELECT media_id |
---|
43 | FROM %s |
---|
44 | WHERE cr_id <> 0 |
---|
45 | ) |
---|
46 | ;', |
---|
47 | IMAGES_TABLE, COPYRIGHTS_MEDIA); |
---|
48 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
49 | } |
---|
50 | |
---|
51 | return $filter_sets; |
---|
52 | } |
---|
53 | |
---|
54 | // Test if the filters aren't set incorrectly |
---|
55 | function CR_element_set_bm_global_action($action) |
---|
56 | { |
---|
57 | if (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with copyrights', 'without copyrights')) and $action == 'copyrights') { |
---|
58 | // let's refresh the page because we the current set might be modified |
---|
59 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | ?> |
---|