source: extensions/Copyrights/filter.php @ 32013

Last change on this file since 32013 was 11877, checked in by Mattias, 13 years ago

Added some comment in filter.php

File size: 1.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5add_event_handler('get_batch_manager_prefilters', 'CR_add_bm_filter');
6add_event_handler('perform_batch_manager_prefilters', 'CR_perform_bm_filter', 50, 2);
7add_event_handler('element_set_global_action', 'CR_element_set_bm_global_action');
8
9// Add the filter to the list
10function 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
23function 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
55function 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?>
Note: See TracBrowser for help on using the repository browser.