Ignore:
Timestamp:
Aug 12, 2011, 9:13:57 AM (13 years ago)
Author:
icy
Message:

Merge branch 'master' into svn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Icy_Picture_Modify/icy_picture_modify.php

    r11614 r11934  
    5858
    5959// Simplify redirect to administrator page if current user == admin
    60 // FIXME: when a non-existent image_id is provided, the original code
    61 // FIXME: picture_modify doesn't work well. It should deny to modify
    62 // FIXME: such picture.
    6360if (is_admin())
    6461{
     
    6865    $url.= '&image_id='.$_GET['image_id'];
    6966    $url.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : '';
     67    // FIXME: What happens if a POST data were sent within admin uid?
    7068    redirect_http($url);
    7169  }
     
    9492}
    9593
     94// <find writable categories>
     95
     96// * Purpose: Find all categories that are reachable for the current user.
     97// * FIXME:   This query will include all readable categories, those ones
     98//            use can't write to them.
     99
     100$my_categories = array();
     101$my_permissions = null;
     102
     103// <community support>
     104if (is_file(PHPWG_PLUGINS_PATH.'community/include/functions_community.inc.php'))
     105{
     106  include_once(PHPWG_PLUGINS_PATH.'community/include/functions_community.inc.php');
     107  $user_permissions = community_get_user_permissions($user['id']);
     108  $my_categories = $user_permissions['upload_categories'];
     109}
     110// </community support>
     111
     112// FIXME: what happens if both of the following conditions are true
     113// FIXME:    * true == $user_permissions['create_whole_gallery']
     114// FIXME:    * 0    <  count($my_categories)
     115if (empty($user_permissions) or $user_permissions['create_whole_gallery'])
     116{
     117  $query = '
     118  SELECT category_id
     119    FROM '.IMAGE_CATEGORY_TABLE.'
     120  ;';
     121
     122  // list of categories to which the user can access
     123  $my_categories = array_diff(
     124    array_from_query($query, 'category_id'),
     125    explode(',',calculate_permissions($user['id'], $user['status'])));
     126}
     127// </find writable categories>
    96128
    97129// +-----------------------------------------------------------------------+
     
    128160;';
    129161
    130   $authorizeds = array_diff(
    131     array_from_query($query, 'category_id'),
    132     explode(',', calculate_permissions($user['id'], $user['status']))
    133     );
     162  $authorizeds = array_intersect($my_categories,
     163    array_from_query($query, 'category_id'));
    134164
    135165  foreach ($authorizeds as $category_id)
     
    164194}
    165195
    166 //--------------------------------------------------------- update informations
     196// +-----------------------------------------------------------------------+
     197// |                          update informations                          |
     198// +-----------------------------------------------------------------------+
    167199
    168200// first, we verify whether there is a mistake on the given creation date
     
    231263  array_push($page['infos'], l10n('Photo informations updated'));
    232264}
     265
     266// +-----------------------------------------------------------------------+
     267// |                              associate                                |
     268// +-----------------------------------------------------------------------+
    233269// associate the element to other categories than its storage category
     270//
    234271if (isset($_POST['associate'])
    235272    and isset($_POST['cat_dissociated'])
     
    239276  associate_images_to_categories(
    240277    array($_GET['image_id']),
    241     $_POST['cat_dissociated']
     278    array_intersect($_POST['cat_dissociated'], $my_categories)
    242279    );
    243280}
     281
     282
    244283// dissociate the element from categories (but not from its storage category)
    245284if (isset($_POST['dissociate'])
     
    248287  )
    249288{
     289  $arr_dissociate = array_intersect($_POST['cat_associated'], $my_categories);
    250290  $query = '
    251291DELETE FROM '.IMAGE_CATEGORY_TABLE.'
    252292  WHERE image_id = '.$_GET['image_id'].'
    253     AND category_id IN ('.implode(',', $_POST['cat_associated']).')
     293    AND category_id IN ('.implode(',', $arr_dissociate).')
    254294';
    255295  pwg_query($query);
    256296
    257   update_category($_POST['cat_associated']);
    258 }
    259 // elect the element to represent the given categories
     297  update_category($arr_dissociate);
     298}
     299// select the element to represent the given categories
    260300if (isset($_POST['elect'])
    261301    and isset($_POST['cat_dismissed'])
     
    264304{
    265305  $datas = array();
    266   foreach ($_POST['cat_dismissed'] as $category_id)
    267   {
    268     array_push($datas,
    269                array('id' => $category_id,
    270                      'representative_picture_id' => $_GET['image_id']));
    271   }
    272   $fields = array('primary' => array('id'),
    273                   'update' => array('representative_picture_id'));
    274   mass_updates(CATEGORIES_TABLE, $fields, $datas);
     306  $arr_dimissed = array_intersect($_POST['cat_dismissed'], $my_categories);
     307  if (count($arr_dimissed) > 0)
     308  {
     309    foreach ($arr_dimissed as $category_id)
     310    {
     311      array_push($datas,
     312                 array('id' => $category_id,
     313                       'representative_picture_id' => $_GET['image_id']));
     314    }
     315    $fields = array('primary' => array('id'),
     316                    'update' => array('representative_picture_id'));
     317    mass_updates(CATEGORIES_TABLE, $fields, $datas);
     318  }
    275319}
    276320// dismiss the element as representant of the given categories
     
    280324  )
    281325{
    282   set_random_representant($_POST['cat_elected']);
     326  $arr_dismiss = array_intersect($_POST['cat_elected'], $my_categories);
     327  if (count($arr_dismiss) > 0)
     328  {
     329    set_random_representant($arr_dismiss);
     330  }
    283331}
    284332
     
    310358$row = pwg_db_fetch_assoc(pwg_query($query));
    311359
     360// the physical storage directory contains the image
    312361$storage_category_id = null;
    313362if (!empty($row['storage_category_id']))
     
    463512;';
    464513
    465 $authorizeds = array_diff(
    466   array_from_query($query, 'category_id'),
    467   explode(
    468     ',',
    469     calculate_permissions($user['id'], $user['status'])
    470     )
    471   );
    472 
     514// list of categories (OF THIS IMAGE) to which the user can access
     515$authorizeds = array_intersect($my_categories,
     516  array_from_query($query, 'category_id'));
     517
     518// if current category belongs to list of authorized categories
     519// we simply provide link to that category
    473520if (isset($_GET['cat_id'])
    474521    and in_array($_GET['cat_id'], $authorizeds))
     
    482529    );
    483530}
     531// otherwise we provide links to the *first* category in the list
    484532else
    485533{
     
    493541        )
    494542      );
     543    // FIXME: why the first category is selected?
    495544    break;
    496545  }
     
    507556  FROM '.CATEGORIES_TABLE.'
    508557    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id
    509   WHERE image_id = '.$_GET['image_id'];
     558  WHERE image_id = '.$_GET['image_id'] . '
     559    AND id IN ('. join(",", $my_categories).')';
     560// if the image belongs to a physical storage,
     561// we simply ignore that storage album
    510562if (isset($storage_category_id))
    511563{
     
    531583  FROM '.CATEGORIES_TABLE.'
    532584  WHERE id NOT IN ('.implode(',', $associateds).')
     585  AND id IN ('. join(",", $my_categories).')
    533586;';
    534587display_select_cat_wrapper($query, array(), 'dissociated_options');
     
    539592  FROM '.CATEGORIES_TABLE.'
    540593  WHERE representative_picture_id = '.$_GET['image_id'].'
     594    AND id IN ('. join(",", $my_categories).')
    541595;';
    542596display_select_cat_wrapper($query, array(), 'elected_options');
     
    545599SELECT id,name,uppercats,global_rank
    546600  FROM '.CATEGORIES_TABLE.'
    547   WHERE representative_picture_id != '.$_GET['image_id'].'
    548     OR representative_picture_id IS NULL
     601  WHERE id IN ('. join(",", $my_categories).')
     602    AND (representative_picture_id != '.$_GET['image_id'].'
     603    OR representative_picture_id IS NULL)
    549604;';
    550605display_select_cat_wrapper($query, array(), 'dismissed_options');
Note: See TracChangeset for help on using the changeset viewer.