Ignore:
Timestamp:
Sep 11, 2007, 4:24:51 AM (17 years ago)
Author:
rvelices
Message:

feature 731: permissions at image level

  • this is the first version - I wait for feedback before changing help files
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_user.inc.php

    r2055 r2084  
    258258        calculate_permissions($userdata['id'], $userdata['status']);
    259259
     260      /* now we build the list of forbidden images (this list does not contain
     261      images that are not in at least an authorized category)*/
     262      $query = '
     263SELECT DISTINCT(id)
     264  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     265  WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
     266    AND level>'.$userdata['level'];
     267      $forbidden_ids = array_from_query($query, 'id');
     268
     269      if ( empty($forbidden_ids) )
     270      {
     271        array_push( $forbidden_ids, 0 );
     272      }
     273      $userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
     274      $userdata['image_access_list'] = implode(',',$forbidden_ids);
     275
    260276      update_user_cache_categories($userdata);
    261277
     
    270286  FROM '.IMAGE_CATEGORY_TABLE.'
    271287  WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
     288    AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
    272289;';
    273290      list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
     
    282299      $query = '
    283300INSERT INTO '.USER_CACHE_TABLE.'
    284   (user_id, need_update, forbidden_categories, nb_total_images)
     301  (user_id, need_update, forbidden_categories, nb_total_images,
     302    image_access_type, image_access_list)
    285303  VALUES
    286304  ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
    287   .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].')
     305  .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
     306  .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
    288307;';
    289308      pwg_query($query);
     
    528547
    529548  $query = 'SELECT c.id cat_id, global_rank';
    530   if ( !isset($filter_days) )
    531   {
    532     $query .= ',
    533     date_last cat_date_last,
    534     nb_images cat_nb_images
    535   FROM '.CATEGORIES_TABLE.' as c';
    536   }
    537   else
    538   {
    539     // Count by date_available to avoid count null
    540     $query .= ',
    541     MAX(date_available) cat_date_last,
    542     COUNT(date_available) cat_nb_images
    543   FROM '.CATEGORIES_TABLE.' as c
    544     LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
    545     LEFT JOIN '.IMAGES_TABLE.' AS i
    546       ON ic.image_id = i.id AND
    547           i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
    548     $group_by = 'c.id';
    549   }
     549  // Count by date_available to avoid count null
     550  $query .= ',
     551  MAX(date_available) cat_date_last,  COUNT(date_available) cat_nb_images
     552FROM '.CATEGORIES_TABLE.' as c
     553  LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
     554  LEFT JOIN '.IMAGES_TABLE.' AS i
     555    ON ic.image_id = i.id
     556      AND i.level<='.$userdata['level'];
     557
     558  if ( isset($filter_days) )
     559  {
     560    $query .= ' AND i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
     561  }
     562  $group_by = 'c.id';
    550563
    551564  if ( !empty($userdata['forbidden_categories']) )
     
    720733{
    721734  global $page, $conf;
    722  
     735
    723736  if (!isset($page['cache_default_user']))
    724737  {
     
    728741    $result = pwg_query($query);
    729742    $page['cache_default_user'] = mysql_fetch_assoc($result);
    730    
     743
    731744    if ($page['cache_default_user'] !== false)
    732745    {
     
    840853    foreach ($user_ids as $user_id)
    841854    {
     855      $level= isset($default_user['level']) ? $default_user['level'] : 0;
    842856      if ($user_id == $conf['webmaster_id'])
    843857      {
    844858        $status = 'webmaster';
    845       }
    846       else if (($user_id == $conf['guest_id']) or
     859        $level = max( $conf['available_permission_levels'] );
     860      }
     861      else if (($user_id == $conf['guest_id']) or
    847862               ($user_id == $conf['default_user_id']))
    848863      {
     
    859874          'user_id' => $user_id,
    860875          'status' => $status,
    861           'registration_date' => $dbnow
     876          'registration_date' => $dbnow,
     877          'level' => $level
    862878          ));
    863879
    864880      array_push($inserts, $insert);
    865       }
     881    }
    866882
    867883    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     
    902918 * availability of the file
    903919 *
    904  * in descending order of preference: 
     920 * in descending order of preference:
    905921 *   param language, user language, default language
    906922 * PhpWebGallery default language.
     
    12911307      }
    12921308      case 'visible_images':
    1293       {
    12941309        if (!empty($filter['visible_images']))
    12951310        {
     
    12971312            $field_name.' IN ('.$filter['visible_images'].')';
    12981313        }
     1314        // note there is no break - visible include forbidden
     1315      case 'forbidden_images':
     1316        if (
     1317            !empty($user['image_access_list'])
     1318            or $user['image_access_type']!='NOT IN'
     1319            )
     1320        {
     1321          $table_prefix=null;
     1322          if ($field_name=='id')
     1323          {
     1324            $table_prefix = '';
     1325          }
     1326          elseif ($field_name=='i.id')
     1327          {
     1328            $table_prefix = 'i.';
     1329          }
     1330          if ( isset($table_prefix) )
     1331          {
     1332            $sql_list[]=$table_prefix.'level<='.$user['level'];
     1333          }
     1334          else
     1335          {
     1336            $sql_list[]=$field_name.' '.$user['image_access_type']
     1337                .' ('.$user['image_access_list'].')';
     1338          }
     1339        }
    12991340        break;
    1300       }
    13011341      default:
    13021342      {
Note: See TracChangeset for help on using the changeset viewer.