'GIS Config Menu'

@classmethod
def menu_gis(cls, **attr):

    settings = current.deployment_settings
    if (not settings.get_gis_menu()):
        return None
    T = current.T
    db = current.db
    auth = current.auth
    s3db = current.s3db
    request = current.request
    s3 = current.session.s3
    _config = s3.gis_config_id
    if ('_config' in request.get_vars):
        try:
            config = int(request.get_vars._config)
        except ValueError:
            pass
        else:
            if ((_config is None) or (_config != config)):
                s3.gis_config_id = config
                cfg = current.gis.get_config()
                s3.location_filter = cfg.region_location_id
                if settings.has_module('event'):
                    table = s3db.event_config
                    query = (table.config_id == config)
                    incident = db(query).select(table.incident_id, limitby=(0, 1)).first()
                    if incident:
                        s3.incident = incident.incident_id
                    else:
                        s3.incident = None
        cache = None
    else:
        cache = s3db.cache
    table = s3db.gis_menu
    ctable = s3db.gis_config
    query = (table.pe_id == None)
    if auth.is_logged_in():
        query |= (table.pe_id == auth.user.pe_id)
    query &= (table.config_id == ctable.id)
    configs = db(query).select(ctable.id, ctable.name, cache=cache)
    gis_menu = MM(settings.get_gis_menu(), c=request.controller, f=request.function, **attr)
    args = request.args
    if len(configs):
        gis_menu(MM({'name': T('Default'), 'id': 'gis_menu_id_0', 'request_type': 'load'}, args=args, vars={'_config': 0}))
        for config in configs:
            gis_menu(MM({'name': config.name, 'id': ('gis_menu_id_%s' % config.id), 'value': (_config == config.id), 'request_type': 'load'}, args=args, vars={'_config': config.id}))
    return gis_menu
