function acl_delete($mode, $ug_id = false, $forum_id = false, $permission_type = false)
{
global $db;
if ($ug_id === false && $forum_id === false) {
return;
}
$option_id_ary = array();
$table = $mode == 'user' ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
$id_field = $mode . '_id';
$where_sql = array();
if ($forum_id !== false) {
$where_sql[] = !is_array($forum_id) ? 'forum_id = ' . (int) $forum_id : $db->sql_in_set('forum_id', array_map('intval', $forum_id));
}
if ($ug_id !== false) {
$where_sql[] = !is_array($ug_id) ? $id_field . ' = ' . (int) $ug_id : $db->sql_in_set($id_field, array_map('intval', $ug_id));
}
// There seem to be auth options involved, therefore we need to go through the list and make sure we capture roles correctly
if ($permission_type !== false) {
// Get permission type
$sql = 'SELECT auth_option, auth_option_id
FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\tWHERE auth_option " . $db->sql_like_expression($permission_type . $db->get_any_char());
$result = $db->sql_query($sql);
$auth_id_ary = array();
while ($row = $db->sql_fetchrow($result)) {
$option_id_ary[] = $row['auth_option_id'];
$auth_id_ary[$row['auth_option']] = ACL_NO;
}
$db->sql_freeresult($result);
// First of all, lets grab the items having roles with the specified auth options assigned
$sql = "SELECT auth_role_id, {$id_field}, forum_id\n\t\t\t\tFROM {$table}, " . ACL_ROLES_TABLE . " r\n\t\t\t\tWHERE auth_role_id <> 0\n\t\t\t\t\tAND auth_role_id = r.role_id\n\t\t\t\t\tAND r.role_type = '{$permission_type}'\n\t\t\t\t\tAND " . implode(' AND ', $where_sql) . '
ORDER BY auth_role_id';
$result = $db->sql_query($sql);
$cur_role_auth = array();
while ($row = $db->sql_fetchrow($result)) {
$cur_role_auth[$row['auth_role_id']][$row['forum_id']][] = $row[$id_field];
}
$db->sql_freeresult($result);
// Get role data for resetting data
if (sizeof($cur_role_auth)) {
$sql = 'SELECT ao.auth_option, rd.role_id, rd.auth_setting
FROM ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_ROLES_DATA_TABLE . ' rd
WHERE ao.auth_option_id = rd.auth_option_id
AND ' . $db->sql_in_set('rd.role_id', array_keys($cur_role_auth));
$result = $db->sql_query($sql);
$auth_settings = array();
while ($row = $db->sql_fetchrow($result)) {
// We need to fill all auth_options, else setting it will fail...
if (!isset($auth_settings[$row['role_id']])) {
$auth_settings[$row['role_id']] = $auth_id_ary;
}
$auth_settings[$row['role_id']][$row['auth_option']] = $row['auth_setting'];
}
$db->sql_freeresult($result);
// Set the options
foreach ($cur_role_auth as $role_id => $auth_row) {
foreach ($auth_row as $f_id => $ug_row) {
$this->acl_set($mode, $f_id, $ug_row, $auth_settings[$role_id], 0, false);
}
}
}
}
// Now, normally remove permissions...
if ($permission_type !== false) {
$where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));
}
$sql = "DELETE FROM {$table}\n\t\t\tWHERE " . implode(' AND ', $where_sql);
$db->sql_query($sql);
$this->acl_clear_prefetch();
}