aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/cat_perm.php10
-rw-r--r--admin/include/functions.php52
2 files changed, 26 insertions, 36 deletions
diff --git a/admin/cat_perm.php b/admin/cat_perm.php
index d8f3694e7..fa24e21be 100644
--- a/admin/cat_perm.php
+++ b/admin/cat_perm.php
@@ -99,8 +99,16 @@ DELETE
$cat_ids = array_merge($cat_ids, get_subcat_ids(array($page['cat'])));
}
+ $query = '
+SELECT id
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.implode(',', $cat_ids).')
+ AND status = \'private\'
+;';
+ $private_cats = array_from_query($query, 'id');
+
$inserts = array();
- foreach ($cat_ids as $cat_id)
+ foreach ($private_cats as $cat_id)
{
foreach ($grant_groups as $group_id)
{
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 0142bd023..f2a854bde 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2255,12 +2255,16 @@ function add_permission_on_category($category_ids, $user_ids)
}
// make sure categories are private and select uppercats or subcats
- $cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids($category_ids)).",".implode(',', get_uppercat_ids($category_ids)) : implode(',', get_uppercat_ids($category_ids));
+ $cat_ids = get_uppercat_ids($category_ids);
+ if (isset($_POST['apply_on_sub']))
+ {
+ $cat_ids = array_merge($cat_ids, get_subcat_ids($category_ids));
+ }
+
$query = '
-SELECT
- id
+SELECT id
FROM '.CATEGORIES_TABLE.'
- WHERE id IN ('.$cat_ids.')
+ WHERE id IN ('.implode(',', $cat_ids).')
AND status = \'private\'
;';
$private_cats = array_from_query($query, 'id');
@@ -2269,35 +2273,11 @@ SELECT
{
return;
}
-
- // We must not reinsert already existing lines in user_access table
- $granteds = array();
- foreach ($private_cats as $cat_id)
- {
- $granteds[$cat_id] = array();
- }
-
- $query = '
-SELECT
- user_id,
- cat_id
- FROM '.USER_ACCESS_TABLE.'
- WHERE cat_id IN ('.implode(',', $private_cats).')
- AND user_id IN ('.implode(',', $user_ids).')
-;';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- $granteds[ $row['cat_id'] ][] = $row['user_id'];
- }
-
+
$inserts = array();
-
foreach ($private_cats as $cat_id)
{
- $grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
-
- foreach ($grant_to_users as $user_id)
+ foreach ($user_ids as $user_id)
{
$inserts[] = array(
'user_id' => $user_id,
@@ -2305,11 +2285,13 @@ SELECT
);
}
}
-
- if (count($inserts) > 0)
- {
- mass_inserts(USER_ACCESS_TABLE, array_keys($inserts[0]), $inserts);
- }
+
+ mass_inserts(
+ USER_ACCESS_TABLE,
+ array('user_id','cat_id'),
+ $inserts,
+ array('ignore'=>true)
+ );
}