auth_admin::acl_delete PHP Method

acl_delete() public method

Remove local permission
public acl_delete ( $mode, $ug_id = false, $forum_id = false, $permission_type = false )
    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();
    }

Usage Example

         unset($l_ug_list);
     }
     unset($auth_submode);
     unset($auth_setting);
     trigger_error($_CLASS['core_user']->lang['AUTH_UPDATED']);
     break;
 case 'delete':
     $sql = "SELECT auth_option_id\r\n\t\t\tFROM " . FORUMS_ACL_OPTIONS_TABLE . "\r\n\t\t\tWHERE auth_option LIKE '{$sql_option_mode}_%'";
     $result = $_CLASS['core_db']->query($sql);
     if ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
         $option_id_ary = array();
         do {
             $option_id_ary[] = $row['auth_option_id'];
         } while ($row = $_CLASS['core_db']->fetch_row_assoc($result));
         foreach ($ug_data as $id) {
             $auth_admin->acl_delete($ug_type, $forum_id[$mode], $id, $option_id_ary);
         }
         unset($option_id_ary);
     }
     $_CLASS['core_db']->free_result($result);
     // Do we need to recache the moderator lists? We do if the mode
     // was mod or auth_settings['mod'] is a non-zero size array
     if ($mode == 'mod' || isset($auth_settings['mod']) && sizeof($auth_settings['mod'])) {
         cache_moderators();
     }
     // Logging ... first grab user or groupnames ...
     $sql = $ug_type == 'group' ? 'SELECT group_name as name, group_type FROM ' . GROUPS_TABLE . ' WHERE group_id' : 'SELECT username as name FROM ' . USERS_TABLE . ' WHERE user_id';
     $sql .= ' IN (' . implode(', ', array_map('intval', $ug_data)) . ')';
     $result = $_CLASS['core_db']->query($sql);
     $l_ug_list = '';
     while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {