Ignore:
Timestamp:
Jul 13, 2011, 4:04:02 PM (13 years ago)
Author:
plg
Message:

simplify code by using new function add_permission_on_category()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_perm.php

    r8728 r11729  
    6565  pwg_query($query);
    6666}
    67 else if (isset($_POST['trueify'])
    68          and isset($_POST['cat_false'])
    69          and count($_POST['cat_false']) > 0)
     67else if (isset($_POST['trueify']))
    7068{
    71   $uppercats = get_uppercat_ids($_POST['cat_false']);
    72   $private_uppercats = array();
    73 
    74   $query = '
    75 SELECT id
    76   FROM '.CATEGORIES_TABLE.'
    77   WHERE id IN ('.implode(',', $uppercats).')
    78     AND status = \'private\'
    79 ;';
    80   $result = pwg_query($query);
    81   while ($row = pwg_db_fetch_assoc($result))
    82   {
    83     array_push($private_uppercats, $row['id']);
    84   }
    85 
    86   // retrying to authorize a category which is already authorized may cause
    87   // an error (in SQL statement), so we need to know which categories are
    88   // accesible
    89   $authorized_ids = array();
    90 
    91   $query = '
    92 SELECT cat_id
    93   FROM '.USER_ACCESS_TABLE.'
    94   WHERE user_id = '.$page['user'].'
    95 ;';
    96   $result = pwg_query($query);
    97 
    98   while ($row = pwg_db_fetch_assoc($result))
    99   {
    100     array_push($authorized_ids, $row['cat_id']);
    101   }
    102 
    103   $inserts = array();
    104   $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
    105   foreach ($to_autorize_ids as $to_autorize_id)
    106   {
    107     array_push($inserts, array('user_id' => $page['user'],
    108                                'cat_id' => $to_autorize_id));
    109   }
    110 
    111   mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
     69  add_permission_on_category($_POST['cat_false'], $page['user']);
    11270}
    11371
Note: See TracChangeset for help on using the changeset viewer.