simplify code by using new function add_permission_on_category()
git-svn-id: http://piwigo.org/svn/trunk@11729 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
424eed990e
commit
7bd96c6da2
2 changed files with 4 additions and 87 deletions
|
|
@ -143,50 +143,9 @@ DELETE
|
||||||
;';
|
;';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
}
|
}
|
||||||
else if (isset($_POST['grant_users_submit'])
|
else if (isset($_POST['grant_users_submit']))
|
||||||
and isset($_POST['grant_users'])
|
|
||||||
and count($_POST['grant_users']) > 0)
|
|
||||||
{
|
{
|
||||||
$query = '
|
add_permission_on_category($page['cat'], $_POST['grant_users']);
|
||||||
SELECT id
|
|
||||||
FROM '.CATEGORIES_TABLE.'
|
|
||||||
WHERE id IN ('.implode(',', get_uppercat_ids(array($page['cat']))).')
|
|
||||||
AND status = \'private\'
|
|
||||||
;';
|
|
||||||
$private_uppercats = array_from_query($query, 'id');
|
|
||||||
|
|
||||||
// We must not reinsert already existing lines in user_access table
|
|
||||||
$granteds = array();
|
|
||||||
foreach ($private_uppercats as $cat_id)
|
|
||||||
{
|
|
||||||
$granteds[$cat_id] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = '
|
|
||||||
SELECT user_id, cat_id
|
|
||||||
FROM '.USER_ACCESS_TABLE.'
|
|
||||||
WHERE cat_id IN ('.implode(',', $private_uppercats).')
|
|
||||||
AND user_id IN ('.implode(',', $_POST['grant_users']).')
|
|
||||||
;';
|
|
||||||
$result = pwg_query($query);
|
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
array_push($granteds[$row['cat_id']], $row['user_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$inserts = array();
|
|
||||||
|
|
||||||
foreach ($private_uppercats as $cat_id)
|
|
||||||
{
|
|
||||||
$user_ids = array_diff($_POST['grant_users'], $granteds[$cat_id]);
|
|
||||||
foreach ($user_ids as $user_id)
|
|
||||||
{
|
|
||||||
array_push($inserts, array('user_id' => $user_id,
|
|
||||||
'cat_id' => $cat_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
|
||||||
|
|
@ -64,51 +64,9 @@ DELETE FROM '.USER_ACCESS_TABLE.'
|
||||||
;';
|
;';
|
||||||
pwg_query($query);
|
pwg_query($query);
|
||||||
}
|
}
|
||||||
else if (isset($_POST['trueify'])
|
else if (isset($_POST['trueify']))
|
||||||
and isset($_POST['cat_false'])
|
|
||||||
and count($_POST['cat_false']) > 0)
|
|
||||||
{
|
{
|
||||||
$uppercats = get_uppercat_ids($_POST['cat_false']);
|
add_permission_on_category($_POST['cat_false'], $page['user']);
|
||||||
$private_uppercats = array();
|
|
||||||
|
|
||||||
$query = '
|
|
||||||
SELECT id
|
|
||||||
FROM '.CATEGORIES_TABLE.'
|
|
||||||
WHERE id IN ('.implode(',', $uppercats).')
|
|
||||||
AND status = \'private\'
|
|
||||||
;';
|
|
||||||
$result = pwg_query($query);
|
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
array_push($private_uppercats, $row['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrying to authorize a category which is already authorized may cause
|
|
||||||
// an error (in SQL statement), so we need to know which categories are
|
|
||||||
// accesible
|
|
||||||
$authorized_ids = array();
|
|
||||||
|
|
||||||
$query = '
|
|
||||||
SELECT cat_id
|
|
||||||
FROM '.USER_ACCESS_TABLE.'
|
|
||||||
WHERE user_id = '.$page['user'].'
|
|
||||||
;';
|
|
||||||
$result = pwg_query($query);
|
|
||||||
|
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
array_push($authorized_ids, $row['cat_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$inserts = array();
|
|
||||||
$to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
|
|
||||||
foreach ($to_autorize_ids as $to_autorize_id)
|
|
||||||
{
|
|
||||||
array_push($inserts, array('user_id' => $page['user'],
|
|
||||||
'cat_id' => $to_autorize_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue