Ignore:
Timestamp:
Jul 13, 2011, 3:30:06 PM (13 years ago)
Author:
plg
Message:

feature 2245: when a new private album is added, the creator and admins
automatically get permission on it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/admin/include/functions.php

    r11056 r11727  
    12731273function create_virtual_category($category_name, $parent_id=null)
    12741274{
    1275   global $conf;
     1275  global $conf, $user;
    12761276
    12771277  // is the given category name only containing blank spaces ?
     
    13611361;';
    13621362  pwg_query($query);
     1363
     1364  if ('private' == $insert['status'])
     1365  {
     1366    add_permission_on_category($inserted_id, array_unique(array_merge(get_admins(), array($user['id']))));
     1367  }
    13631368
    13641369  return array(
     
    21682173}
    21692174
     2175function add_permission_on_category($category_ids, $user_ids)
     2176{
     2177  // array-ify categories and users
     2178  if (!is_array($category_ids))
     2179  {
     2180    $category_ids = array($category_ids);
     2181  }
     2182
     2183  if (!is_array($user_ids))
     2184  {
     2185    $user_ids = array($user_ids);
     2186  }
     2187
     2188  // check for emptiness
     2189  if (count($category_ids) == 0 or count($user_ids) == 0)
     2190  {
     2191    return;
     2192  }
     2193 
     2194  // make sure categories are private and select uppercats
     2195  $query = '
     2196SELECT
     2197    id
     2198  FROM '.CATEGORIES_TABLE.'
     2199  WHERE id IN ('.implode(',', get_uppercat_ids($category_ids)).')
     2200    AND status = \'private\'
     2201;';
     2202  $private_uppercats = array_from_query($query, 'id');
     2203
     2204  if (count($private_uppercats) == 0)
     2205  {
     2206    return;
     2207  }
     2208 
     2209  // We must not reinsert already existing lines in user_access table
     2210  $granteds = array();
     2211  foreach ($private_uppercats as $cat_id)
     2212  {
     2213    $granteds[$cat_id] = array();
     2214  }
     2215 
     2216  $query = '
     2217SELECT
     2218    user_id,
     2219    cat_id
     2220  FROM '.USER_ACCESS_TABLE.'
     2221  WHERE cat_id IN ('.implode(',', $private_uppercats).')
     2222    AND user_id IN ('.implode(',', $user_ids).')
     2223;';
     2224  $result = pwg_query($query);
     2225  while ($row = pwg_db_fetch_assoc($result))
     2226  {
     2227    array_push($granteds[$row['cat_id']], $row['user_id']);
     2228  }
     2229
     2230  $inserts = array();
     2231 
     2232  foreach ($private_uppercats as $cat_id)
     2233  {
     2234    $grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
     2235   
     2236    foreach ($grant_to_users as $user_id)
     2237    {
     2238      array_push(
     2239        $inserts,
     2240        array(
     2241          'user_id' => $user_id,
     2242          'cat_id' => $cat_id
     2243          )
     2244        );
     2245    }
     2246  }
     2247
     2248  if (count($inserts) > 0)
     2249  {
     2250    mass_inserts(USER_ACCESS_TABLE, array_keys($inserts[0]), $inserts);
     2251  }
     2252}
     2253
     2254
     2255function get_admins($include_webmaster=true)
     2256{
     2257  $status_list = array('admin');
     2258
     2259  if ($include_webmaster)
     2260  {
     2261    $status_list[] = 'webmaster';
     2262  }
     2263 
     2264  $query = '
     2265SELECT
     2266    user_id
     2267  FROM '.USER_INFOS_TABLE.'
     2268  WHERE status in (\''.implode("','", $status_list).'\')
     2269;';
     2270
     2271  return array_from_query($query, 'user_id');
     2272}
    21702273?>
Note: See TracChangeset for help on using the changeset viewer.