[26742] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Batch Manager, Added By |
---|
| 4 | Version: auto |
---|
| 5 | Description: Add filter "Added by" in Batch Manager |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid= |
---|
| 7 | Author: plg |
---|
| 8 | Author URI: http://le-gall.net/pierrick |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | add_event_handler('loc_end_element_set_global', 'bmab_add_filter'); |
---|
| 14 | function bmab_add_filter() |
---|
| 15 | { |
---|
| 16 | global $conf, $template; |
---|
| 17 | |
---|
| 18 | $query = ' |
---|
| 19 | SELECT |
---|
| 20 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 21 | i.added_by, |
---|
| 22 | COUNT(*) AS counter |
---|
| 23 | FROM '.USERS_TABLE.' AS u |
---|
| 24 | INNER JOIN '.IMAGES_TABLE.' AS i ON u.'.$conf['user_fields']['id'].' = i.added_by |
---|
| 25 | GROUP BY i.added_by |
---|
| 26 | ORDER BY u.'.$conf['user_fields']['username'].' ASC |
---|
| 27 | ;'; |
---|
| 28 | $result = pwg_query($query); |
---|
| 29 | |
---|
| 30 | $added_by_options = array(); |
---|
| 31 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 32 | { |
---|
| 33 | $added_by_options[$row['added_by']] = $row['username'].' ('.l10n_dec('%d photo', '%d photos', $row['counter']).')'; |
---|
| 34 | } |
---|
| 35 | $template->assign('added_by_options', $added_by_options); |
---|
| 36 | |
---|
| 37 | $template->assign( |
---|
| 38 | 'added_by_selected', |
---|
| 39 | isset($_SESSION['bulk_manager_filter']['added_by']) ? $_SESSION['bulk_manager_filter']['added_by'] : '' |
---|
| 40 | ); |
---|
| 41 | |
---|
| 42 | $template->set_prefilter('batch_manager_global', 'bmab_add_filter_prefilter'); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | function bmab_add_filter_prefilter($content, &$smarty) |
---|
| 46 | { |
---|
| 47 | // first we add the (hidden by default) block to select the user |
---|
| 48 | $pattern = '#</ul>\s*<p class="actionButtons">#ms'; |
---|
| 49 | $replacement = ' |
---|
| 50 | <li id="filter_added_by" {if !isset($filter.added_by)}style="display:none"{/if}> |
---|
| 51 | <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a> |
---|
| 52 | <input type="checkbox" name="filter_added_by_use" class="useFilterCheckbox" {if isset($filter.added_by)}checked="checked"{/if}> |
---|
| 53 | {\'Added by %s\'|@translate|sprintf:""} |
---|
| 54 | <select name="filter_added_by"> |
---|
| 55 | {html_options options=$added_by_options selected=$added_by_selected} |
---|
| 56 | </select> |
---|
| 57 | </li> |
---|
| 58 | </ul> |
---|
| 59 | |
---|
| 60 | <p class="actionButtons"> |
---|
| 61 | '; |
---|
| 62 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 63 | |
---|
| 64 | // then we add the "Added by" in the filter selector |
---|
| 65 | $pattern = '#</select>\s*<a id="removeFilters"#ms'; |
---|
| 66 | $replacement = ' |
---|
| 67 | <option value="filter_added_by" {if isset($filter.added_by)}disabled="disabled"{/if}>{\'Added by %s\'|@translate|sprintf:""}</option> |
---|
| 68 | </select> |
---|
| 69 | <a id="removeFilters" |
---|
| 70 | '; |
---|
| 71 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 72 | |
---|
| 73 | return $content; |
---|
| 74 | } |
---|
| 75 | |
---|
[29738] | 76 | add_event_handler('batch_manager_register_filters', 'bmab_register_filter'); |
---|
| 77 | function bmab_register_filter($filters) |
---|
[26742] | 78 | { |
---|
| 79 | if (isset($_POST['filter_added_by_use'])) |
---|
| 80 | { |
---|
| 81 | check_input_parameter('filter_added_by', $_POST, false, PATTERN_ID); |
---|
[29738] | 82 | |
---|
| 83 | $filters['added_by'] = $_POST['filter_added_by']; |
---|
[26742] | 84 | } |
---|
[29738] | 85 | |
---|
| 86 | return $filters; |
---|
[29378] | 87 | } |
---|
[26742] | 88 | |
---|
[29378] | 89 | add_event_handler('batch_manager_perform_filters', 'bmab_perform_filter'); |
---|
| 90 | function bmab_perform_filter($filter_sets) |
---|
| 91 | { |
---|
[26742] | 92 | if (isset($_SESSION['bulk_manager_filter']['added_by'])) |
---|
| 93 | { |
---|
| 94 | $query = ' |
---|
| 95 | SELECT |
---|
| 96 | id |
---|
| 97 | FROM '.IMAGES_TABLE.' |
---|
| 98 | WHERE added_by = '.$_SESSION['bulk_manager_filter']['added_by'].' |
---|
| 99 | ;'; |
---|
[29378] | 100 | $filter_sets[] = array_from_query($query, 'id'); |
---|
[26742] | 101 | } |
---|
[29378] | 102 | |
---|
| 103 | return $filter_sets; |
---|
[26742] | 104 | } |
---|
| 105 | ?> |
---|