<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           mgt_generic_select.asp

    Description:    Ingang om generiek tabel data te bekijken
    Context:        Vanuit user_tables.asp

    Notes:          Alleen voor FACFAC
                    Vooralsnog geforceerd readonly
*/
%>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_generic_select.inc" -->

<%
    Application("otap_environment") == "O" || user.checkAutorisation("WEB_FACFAC");

    var sql = getQParam("sql");

    var model = model_generic_select(sql, "WEB_FACFAC");

    var params = { "transit": { "sql": sql  },
                   "show": {} // zodat je kunt doorklikken
                 };

    // Meeste velden geforceerd readonly
    for (var fld in model.fields)
    {
        var field = model.fields[fld];
        field.readonly = true;
    }

    params.search = {};
    if ("id" in model.fields)
    {
        params.search.labels = [{ "lbl": "Primary key", "txt" : "{0}".format(model.fields["id"].dbs)}];
        if (model.fields["id"].seq)
        {
            var sql = "SELECT last_number currval"
                    + "  FROM user_sequences"
                    + " WHERE sequence_name = " + safe.quoted_sql_upper(model.fields["id"].seq);
            var oRs = Oracle.Execute(sql)
            var curval = oRs(0).Value;
            oRs.Close();
            params.search.labels.push({ "lbl": "Sequence", "txt" : "{0} (next: {1})".format(model.fields["id"].seq, curval)});
        }
    }
    else // geen id. Dan kun je niet doorklikken. Toon dan maar alle kolommen
    {
        params.search.labels = [{ "lbl": "Primary key", "txt" : "No single NUMBER primary key detected. Record clicking not available."}];
        params.list = { columns : [] };
        for (var fld in model.fields)
        {
            params.list.columns.push(fld);
        }
    }

    if ("estimated_rows" in model && model.estimated_rows < S("qp_maxrows"))
        params.search.autosearch = true;

    if (getQParamInt("scf_multi", 0) == 0 && model.nrfields > 10)
        params.multicolumn = true;

    var orderby = getQParamSafe("scf_orderby", "");
    if (orderby && orderby in model.fields)
        model.gparams.GET.orderbys = [orderby];

    // Toevoegen en delete staan we niet toe
    model.REST_POST   = null;
    model.REST_DELETE = null;

    scaffolding(model, params);
%>
<% ASPPAGE_END(); %>
