Changeset 6772


Ignore:
Timestamp:
Aug 17, 2010, 5:47:14 PM (10 years ago)
Author:
plg
Message:

feature 1802 added: filtering system. Only 3 filters available, more to come
later. Ability to add/remove filters on the fly.

When an administrator displays the "caddie" content, it means bulk manager
with a single filter "prefilter=caddie". Same principle for the photos of a
given album.

Location:
extensions/bulk_manager
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/bulk_manager/element_set.php

    r6756 r6772  
    4444
    4545// +-----------------------------------------------------------------------+
    46 // |                    initialize info about category                     |
    47 // +-----------------------------------------------------------------------+
    48 
    49 if (!isset($_GET['cat']))
    50 {
    51   $_GET['cat'] = 'caddie';
    52 }
    53 
    54 // To element_set_(global|unit).php, we must provide the elements id of the
    55 // managed category in $page['cat_elements_id'] array.
    56 $page['cat_elements_id'] = array();
    57 if (is_numeric($_GET['cat']))
    58 {
    59   $page['title'] =
    60     get_cat_display_name_from_id(
    61       $_GET['cat'],
    62       PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=',
    63       false
     46// |                      initialize current set                           |
     47// +-----------------------------------------------------------------------+
     48
     49if (isset($_POST['submitFilter']))
     50{
     51  // echo '<pre>'; print_r($_POST); echo '</pre>';
     52 
     53  $_SESSION['bulk_manager_filter'] = array();
     54
     55  if (isset($_POST['filter_prefilter_use']))
     56  {
     57    $prefilters = array('caddie', 'last import', 'with no album', 'with no tag');
     58    if (in_array($_POST['filter_prefilter'], $prefilters))
     59    {
     60      $_SESSION['bulk_manager_filter']['prefilter'] = $_POST['filter_prefilter'];
     61    }   
     62  }
     63
     64  if (isset($_POST['filter_category_use']))
     65  {
     66    $_SESSION['bulk_manager_filter']['category'] = $_POST['filter_category'];
     67
     68    if (isset($_POST['filter_category_recursive']))
     69    {
     70      $_SESSION['bulk_manager_filter']['category_recursive'] = true;
     71    }
     72  }
     73
     74  if (isset($_POST['filter_level_use']))
     75  {
     76    if (in_array($_POST['filter_level'], $conf['available_permission_levels']))
     77    {
     78      $_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level'];
     79    }
     80  }
     81}
     82
     83if (isset($_GET['cat']))
     84{
     85  if ('caddie' == $_GET['cat'])
     86  {
     87    $_SESSION['bulk_manager_filter'] = array(
     88      'prefilter' => 'caddie'
    6489      );
    65 
    66   $query = '
    67 SELECT image_id
    68   FROM '.IMAGE_CATEGORY_TABLE.'
    69   WHERE category_id = '.$_GET['cat'].'
    70 ;';
    71   $page['cat_elements_id'] = array_from_query($query, 'image_id');
    72 }
    73 else if ('caddie' == $_GET['cat'])
    74 {
    75   $page['title'] = l10n('caddie');
    76 
    77   $query = '
     90  }
     91
     92  if (is_numeric($_GET['cat']))
     93  {
     94    $_SESSION['bulk_manager_filter'] = array(
     95      'category' => $_GET['cat']
     96      );
     97  }
     98}
     99
     100if (!isset($_SESSION['bulk_manager_filter']))
     101{
     102  $_SESSION['bulk_manager_filter'] = array(
     103    'prefilter' => 'caddie'
     104    );
     105}
     106
     107// echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>';
     108
     109// depending on the current filter (in session), we find the appropriate
     110// photos
     111$filter_sets = array();
     112if (isset($_SESSION['bulk_manager_filter']['prefilter']))
     113{
     114  if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter'])
     115  {
     116    $query = '
    78117SELECT element_id
    79118  FROM '.CADDIE_TABLE.'
    80119  WHERE user_id = '.$user['id'].'
    81120;';
    82   $page['cat_elements_id'] = array_from_query($query, 'element_id');
    83 }
    84 else if ('not_linked' == $_GET['cat'])
    85 {
    86   $page['title'] = l10n('Not linked elements');
    87   $template->assign(array('U_ACTIVE_MENU' => 5 ));
    88 
    89   // we are searching elements not linked to any virtual category
     121    array_push(
     122      $filter_sets,
     123      array_from_query($query, 'element_id')
     124      );
     125  }
     126
     127  if ('last import'== $_SESSION['bulk_manager_filter']['prefilter'])
     128  {
     129    $query = '
     130SELECT MAX(date_available) AS date
     131  FROM '.IMAGES_TABLE.'
     132;';
     133    $row = pwg_db_fetch_assoc(pwg_query($query));
     134    if (!empty($row['date']))
     135    {
     136      $query = '
     137SELECT id
     138  FROM '.IMAGES_TABLE.'
     139  WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'
     140;';
     141      array_push(
     142        $filter_sets,
     143        array_from_query($query, 'id')
     144        );
     145    }
     146  }
     147}
     148
     149if (isset($_SESSION['bulk_manager_filter']['category']))
     150{
     151  $categories = array();
     152 
     153  if (isset($_SESSION['bulk_manager_filter']['category_recursive']))
     154  {
     155    $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category']));
     156  }
     157  else
     158  {
     159    $categories = array($_SESSION['bulk_manager_filter']['category']);
     160  }
     161 
     162  $query = '
     163 SELECT DISTINCT(image_id)
     164   FROM '.IMAGE_CATEGORY_TABLE.'
     165   WHERE category_id IN ('.implode(',', $categories).')
     166 ;';
     167  array_push(
     168    $filter_sets,
     169    array_from_query($query, 'image_id')
     170    );
     171}
     172
     173if (isset($_SESSION['bulk_manager_filter']['level']))
     174{
    90175  $query = '
    91176SELECT id
    92177  FROM '.IMAGES_TABLE.'
     178  WHERE level >= '.$_SESSION['bulk_manager_filter']['level'].'
    93179;';
    94   $all_elements = array_from_query($query, 'id');
    95 
    96   $linked_to_virtual = array();
    97 
    98   $query = '
    99 SELECT id
    100   FROM '.CATEGORIES_TABLE.'
    101   WHERE dir IS NULL
    102 ;';
    103   $virtual_categories = array_from_query($query, 'id');
    104   if (!empty($virtual_categories))
    105   {
    106     $query = '
    107 SELECT DISTINCT(image_id)
    108   FROM '.IMAGE_CATEGORY_TABLE.'
    109   WHERE category_id IN ('.implode(',', $virtual_categories).')
    110 ;';
    111     $linked_to_virtual = array_from_query($query, 'image_id');
    112   }
    113 
    114   $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
    115 }
    116 else if ('duplicates' == $_GET['cat'])
    117 {
    118   $page['title'] = l10n('Files with same name in more than one physical category');
    119   $template->assign(array('U_ACTIVE_MENU' => 5 ));
    120 
    121   // we are searching related elements twice or more to physical categories
    122   // 1 - Retrieve Files
    123   $query = '
    124 SELECT DISTINCT(file)
    125   FROM '.IMAGES_TABLE.'
    126  GROUP BY file
    127 HAVING COUNT(DISTINCT storage_category_id) > 1
    128 ;';
    129 
    130   $duplicate_files = array_from_query($query, 'file');
    131   $duplicate_files[]='Nofiles';
    132   // 2 - Retrives related picture ids
    133   $query = '
    134 SELECT id, file
    135   FROM '.IMAGES_TABLE.'
    136 WHERE file IN (\''.implode("','", $duplicate_files).'\')
    137 ORDER BY file, id
    138 ;';
    139 
    140   $page['cat_elements_id'] = array_from_query($query, 'id');
    141 }
    142 elseif ('recent'== $_GET['cat'])
    143 {
    144   $page['title'] = l10n('Recent pictures');
    145   $query = 'SELECT MAX(date_available) AS date
    146   FROM '.IMAGES_TABLE;
    147   $row = pwg_db_fetch_assoc(pwg_query($query));
    148   if (!empty($row['date']))
    149   {
    150     $query = 'SELECT id
    151   FROM '.IMAGES_TABLE.'
    152   WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
    153     $page['cat_elements_id'] = array_from_query($query, 'id');
    154   }
    155 }
     180  array_push(
     181    $filter_sets,
     182    array_from_query($query, 'id')
     183    );
     184}
     185
     186$current_set = array_shift($filter_sets);
     187foreach ($filter_sets as $set)
     188{
     189  $current_set = array_intersect($current_set, $set);
     190}
     191$page['cat_elements_id'] = $current_set;
     192
     193//  // To element_set_(global|unit).php, we must provide the elements id of the
     194//  // managed category in $page['cat_elements_id'] array.
     195//  $page['cat_elements_id'] = array();
     196//  if (is_numeric($_GET['cat']))
     197//  {
     198//    $page['title'] =
     199//      get_cat_display_name_from_id(
     200//        $_GET['cat'],
     201//        PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=',
     202//        false
     203//        );
     204// 
     205//    $query = '
     206//  SELECT image_id
     207//    FROM '.IMAGE_CATEGORY_TABLE.'
     208//    WHERE category_id = '.$_GET['cat'].'
     209//  ;';
     210//    $page['cat_elements_id'] = array_from_query($query, 'image_id');
     211//  }
     212//  else if ('caddie' == $_GET['cat'])
     213//  {
     214//    $page['title'] = l10n('caddie');
     215// 
     216//    $query = '
     217//  SELECT element_id
     218//    FROM '.CADDIE_TABLE.'
     219//    WHERE user_id = '.$user['id'].'
     220//  ;';
     221//    $page['cat_elements_id'] = array_from_query($query, 'element_id');
     222//  }
     223//  else if ('not_linked' == $_GET['cat'])
     224//  {
     225//    $page['title'] = l10n('Not linked elements');
     226//    $template->assign(array('U_ACTIVE_MENU' => 5 ));
     227// 
     228//    // we are searching elements not linked to any virtual category
     229//    $query = '
     230//  SELECT id
     231//    FROM '.IMAGES_TABLE.'
     232//  ;';
     233//    $all_elements = array_from_query($query, 'id');
     234// 
     235//    $linked_to_virtual = array();
     236// 
     237//    $query = '
     238//  SELECT id
     239//    FROM '.CATEGORIES_TABLE.'
     240//    WHERE dir IS NULL
     241//  ;';
     242//    $virtual_categories = array_from_query($query, 'id');
     243//    if (!empty($virtual_categories))
     244//    {
     245//      $query = '
     246//  SELECT DISTINCT(image_id)
     247//    FROM '.IMAGE_CATEGORY_TABLE.'
     248//    WHERE category_id IN ('.implode(',', $virtual_categories).')
     249//  ;';
     250//      $linked_to_virtual = array_from_query($query, 'image_id');
     251//    }
     252// 
     253//    $page['cat_elements_id'] = array_diff($all_elements, $linked_to_virtual);
     254//  }
     255//  else if ('duplicates' == $_GET['cat'])
     256//  {
     257//    $page['title'] = l10n('Files with same name in more than one physical category');
     258//    $template->assign(array('U_ACTIVE_MENU' => 5 ));
     259// 
     260//    // we are searching related elements twice or more to physical categories
     261//    // 1 - Retrieve Files
     262//    $query = '
     263//  SELECT DISTINCT(file)
     264//    FROM '.IMAGES_TABLE.'
     265//   GROUP BY file
     266//  HAVING COUNT(DISTINCT storage_category_id) > 1
     267//  ;';
     268// 
     269//    $duplicate_files = array_from_query($query, 'file');
     270//    $duplicate_files[]='Nofiles';
     271//    // 2 - Retrives related picture ids
     272//    $query = '
     273//  SELECT id, file
     274//    FROM '.IMAGES_TABLE.'
     275//  WHERE file IN (\''.implode("','", $duplicate_files).'\')
     276//  ORDER BY file, id
     277//  ;';
     278// 
     279//    $page['cat_elements_id'] = array_from_query($query, 'id');
     280//  }
     281//  elseif ('recent'== $_GET['cat'])
     282//  {
     283//    $page['title'] = l10n('Recent pictures');
     284//    $query = 'SELECT MAX(date_available) AS date
     285//    FROM '.IMAGES_TABLE;
     286//    $row = pwg_db_fetch_assoc(pwg_query($query));
     287//    if (!empty($row['date']))
     288//    {
     289//      $query = 'SELECT id
     290//    FROM '.IMAGES_TABLE.'
     291//    WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\'';
     292//      $page['cat_elements_id'] = array_from_query($query, 'id');
     293//    }
     294//  }
    156295
    157296// +-----------------------------------------------------------------------+
  • extensions/bulk_manager/element_set_global.php

    r6756 r6772  
    325325$template->assign(
    326326  array(
     327    'filter' => $_SESSION['bulk_manager_filter'],
     328   
    327329    'selection' => $collection,
    328330   
    329     'CATEGORIES_NAV'=>$page['title'],
    330 
    331331    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
    332332
     
    337337    .'&amp;mode=unit',
    338338
    339     'F_ACTION'=>$base_url.get_query_string_diff(array()),
     339    'F_ACTION'=>$base_url.get_query_string_diff(array('cat')),
    340340   )
    341341 );
     
    345345// +-----------------------------------------------------------------------+
    346346
    347 $template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
     347$in_caddie = false;
     348if (isset($_SESSION['bulk_manager_filter']['prefilter'])
     349    and 'caddie' == $_SESSION['bulk_manager_filter']['prefilter'])
     350{
     351  $in_caddie = true;
     352}
     353$template->assign('IN_CADDIE', $in_caddie);
    348354
    349355// +-----------------------------------------------------------------------+
     
    375381// +-----------------------------------------------------------------------+
    376382
     383// privacy level
     384$template->assign(
     385    array(
     386      'filter_level_options'=> get_privacy_level_options(),
     387      'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level'])
     388        ? $_SESSION['bulk_manager_filter']['level']
     389        : 0,
     390    )
     391  );
     392
    377393// Virtualy associate a picture to a category
    378394$query = '
     
    381397;';
    382398display_select_cat_wrapper($query, array(), 'associate_options', true);
     399
     400// in the filter box, which category to select by default
     401$selected_category = array();
     402
     403if (isset($_SESSION['bulk_manager_filter']['category']))
     404{
     405  $selected_category = array($_SESSION['bulk_manager_filter']['category']);
     406}
     407else
     408{
     409  // we need to know the category in which the last photo was added
     410  $selected_category = array();
     411
     412  $query = '
     413SELECT
     414    category_id,
     415    id_uppercat
     416  FROM '.IMAGES_TABLE.' AS i
     417    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
     418    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
     419  ORDER BY i.id DESC
     420  LIMIT 1
     421;';
     422  $result = pwg_query($query);
     423  if (pwg_db_num_rows($result) > 0)
     424  {
     425    $row = pwg_db_fetch_assoc($result);
     426 
     427    $selected_category = array($row['category_id']);
     428  }
     429}
     430
     431$query = '
     432SELECT id,name,uppercats,global_rank
     433  FROM '.CATEGORIES_TABLE.'
     434;';
     435display_select_cat_wrapper($query, $selected_category, 'filter_category_options', true);
    383436
    384437// Dissociate from a category : categories listed for dissociation can
  • extensions/bulk_manager/element_set_global.tpl

    r6756 r6772  
    235235  });
    236236
     237  $(".removeFilter").click(function () {
     238    var filter = $(this).parent('li').attr("id");
     239    filter_disable(filter);
     240
     241    return false;
     242  });
     243
     244  function filter_enable(filter) {
     245    /* show the filter*/
     246    $("#"+filter).show();
     247
     248    /* check the checkbox to declare we use this filter */
     249    $("input[type=checkbox][name="+filter+"_use]").attr("checked", true);
     250
     251    /* forbid to select this filter in the addFilter list */
     252    $("#addFilter").children("option[value="+filter+"]").attr("disabled", "disabled");
     253  }
     254
     255  $("#addFilter").change(function () {
     256    var filter = $(this).attr("value");
     257    filter_enable(filter);
     258    $(this).attr("value", -1);
     259  });
     260
     261  function filter_disable(filter) {
     262    /* hide the filter line */
     263    $("#"+filter).hide();
     264
     265    /* uncheck the checkbox to declare we do not use this filter */
     266    $("input[name="+filter+"_use]").removeAttr("checked");
     267
     268    /* give the possibility to show it again */
     269    $("#addFilter").children("option[value="+filter+"]").removeAttr("disabled");
     270  }
     271
     272  $("#removeFilters").click(function() {
     273    $("#filterList li").each(function() {
     274      var filter = $(this).attr("id");
     275      filter_disable(filter);
     276    });
     277    return false;
     278  });
     279
    237280  checkPermitAction()
    238281});
     
    253296#selectSet a {border-bottom:1px dotted}
    254297#applyOnDetails {font-style:italic;}
     298
     299.actionButtons {text-align:left;}
     300#filterList {padding-left:5px;}
     301#filterList li {margin-bottom:5px; list-style-type:none;}
     302a.removeFilter {background: url(plugins/bulk_manager/remove_filter.png) no-repeat top left;width:7px;height:7px;display:inline-block}
     303a.removeFilter:hover {background: url(plugins/bulk_manager/remove_filter_hover.png); border:none;}
     304.removeFilter span {display:none}
     305#applyFilterBlock {margin-top:20px;}
     306.useFilterCheckbox {display:none}
    255307</style>
    256308{/literal}
    257309
     310  <p style="float:left; font-size:90%;margin:5px 0 0 0;padding:0;">
     311    <a href="{$U_UNIT_MODE}">Switch to unit mode</a>
     312  </p>
     313
    258314<h2>{'Batch management'|@translate}</h2>
    259315
    260 <h3>{$CATEGORIES_NAV}</h3>
    261 
    262 {if !empty($thumbnails)}
    263   <p style="text-align:center;">
    264     {'global mode'|@translate}
    265     | <a href="{$U_UNIT_MODE}">{'unit mode'|@translate}</a>
    266   </p>
    267 
    268   <fieldset style="display:none;">
    269 
    270     <legend>{'Display options'|@translate}</legend>
    271 
    272     <p>{'elements per page'|@translate}:
    273         <a href="{$U_DISPLAY}&amp;display=20">20</a>
    274       | <a href="{$U_DISPLAY}&amp;display=50">50</a>
    275       | <a href="{$U_DISPLAY}&amp;display=100">100</a>
    276       | <a href="{$U_DISPLAY}&amp;display=all">{'all'|@translate}</a>
     316  <form action="{$F_ACTION}" method="post">
     317
     318  <fieldset>
     319    <legend>{'Filter'|@translate}</legend>
     320
     321    <ul id="filterList">
     322      <li id="filter_prefilter" {if !isset($filter.prefilter)}style="display:none"{/if}>
     323        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
     324        <input type="checkbox" name="filter_prefilter_use" class="useFilterCheckbox" {if isset($filter.prefilter)}checked="checked"{/if}>
     325        predefined filter
     326        <select name="filter_prefilter">
     327          <option value="caddie" {if $filter.prefilter eq 'caddie'}selected="selected"{/if}>caddie</option>
     328          <option value="last import" {if $filter.prefilter eq 'last import'}selected="selected"{/if}>last import</option>
     329<!--          <option value="with no album">with no album</option> -->
     330<!--          <option value="with no virtual album">with no virtual album</option> -->
     331<!--          <option value="with no tag">with no tag</option> -->
     332        </select>
     333      </li>
     334      <li id="filter_category" {if !isset($filter.category)}style="display:none"{/if}>
     335        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
     336        <input type="checkbox" name="filter_category_use" class="useFilterCheckbox" {if isset($filter.category)}checked="checked"{/if}>
     337        album
     338        <select style="width:400px" name="filter_category" size="1">
     339          {html_options options=$filter_category_options selected=$filter_category_options_selected}
     340        </select>
     341        <label><input type="checkbox" name="filter_category_recursive" {if isset($filter.category_recursive)}checked="checked"{/if}> {'include child albums'|@translate}</label>
     342      </li>
     343      <li id="filter_level" {if !isset($filter.level)}style="display:none"{/if}>
     344        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
     345        <input type="checkbox" name="filter_level_use" class="useFilterCheckbox" {if isset($filter.level)}checked="checked"{/if}>
     346        {'Who can see these photos?'|@translate}
     347        <select name="filter_level" size="1">
     348          {html_options options=$filter_level_options selected=$filter_level_options_selected}
     349        </select>
     350      </li>
     351    </ul>
     352
     353    <p class="actionButtons" style="">
     354      <select id="addFilter">
     355        <option value="-1">Add a filter</option>
     356        <option disabled="disabled">------------------</option>
     357        <option value="filter_prefilter">predefined filter</option>
     358        <option value="filter_category">album</option>
     359        <option value="filter_level">{'Who can see these photos?'|@translate}</option>
     360      </select>
     361<!--      <input id="removeFilters" class="submit" type="submit" value="Remove all filters" name="removeFilters"> -->
     362      <a id="removeFilters" href="">Remove all filters</a>
    277363    </p>
    278364
     365    <p class="actionButtons" id="applyFilterBlock">
     366      <input id="applyFilter" class="submit" type="submit" value="Refresh photo set" name="submitFilter">
     367    </p>
     368
    279369  </fieldset>
    280370
    281 <!--  <fieldset> -->
    282 <!--    <legend>{'Filter'|@translate}</legend> -->
    283 <!--  </fieldset> -->
    284 
    285   <form action="{$F_ACTION}" method="post">
    286 
    287371  <fieldset>
    288372
    289373    <legend>{'Selection'|@translate}</legend>
    290374
     375  {if !empty($thumbnails)}
    291376  <p id="checkActions">
    292377    {'Select:'|@translate}
     
    304389  </p>
    305390
    306   {if !empty($thumbnails)}
    307391    <ul class="thumbnails">
    308392      {foreach from=$thumbnails item=thumbnail}
     
    332416      {/foreach}
    333417    </ul>
    334   {/if}
    335418
    336419  {if !empty($navbar) }
     
    351434  {/if}
    352435
     436  {else}
     437  <div>No photo in the current set.</div>
     438  {/if}
    353439  </fieldset>
    354440
     
    462548    </div>
    463549
    464     <p id="applyActionBlock" style="display:none">
     550    <p id="applyActionBlock" style="display:none" class="actionButtons">
    465551      <input id="applyAction" class="submit" type="submit" value="{'Apply action'|@translate}" name="submit" {$TAG_INPUT_ENABLED}> <span id="applyOnDetails"></span></p>
    466552
     
    469555
    470556  </form>
    471 
    472 {else}
    473   <div class="infos"><p>{'Caddie is currently empty'|@translate}</p></div>
    474 {/if}
  • extensions/bulk_manager/main.inc.php

    r6756 r6772  
    22/*
    33Plugin Name: Bulk Manager
    4 Version: auto
     4Version: 2.1a
    55Description: Bulk Manager new generation, for Piwigo 2.2
    66Plugin URI: http://piwigo.org/ext/extension_view.php?eid=440
Note: See TracChangeset for help on using the changeset viewer.