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

    File:               get_fac_info_ajax.asp
    Description:        Ophalen van allerlei info om client-side data te hebben
    Parameters:         init_key
                        niveau
    Context:
    Note:
    Sample:             appl/fac/get_fac_info_ajax.asp?parent_key=1&niveau=G

*/ %>

<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc"-->
<!-- #include file="./fac.inc"-->

<%
var req_info = getQParam("req_info");
var sql = "";
var result = {};

switch (req_info)
{
    case "menu":
    {
        var module = getQParam("module");
        var soort = getQParamInt("soort", 0);
        var parent_key = getQParamInt("parent_key", -1);
        var child_key = getQParamInt("child_key", -1);
        var init_key = getQParamInt("init_key", -1);
        sql = "";
        if (soort > 0)
        {
            sql = "SELECT ins_srtdiscipline_key sel_key"
                + "     , " + lcl.xsql("ins_srtdiscipline_omschrijving", "ins_srtdiscipline_key") + " sel_oms"
                + "  FROM ins_v_aanwezigsrtdiscipline"
                + " WHERE ins_srtdiscipline_module = " + safe.quoted_sql_upper(module)
                + " ORDER BY 2";
        }
        else
        {
            sql = "SELECT ins_discipline_key sel_key"
                + ", " + lcl.xsql("ins_discipline_omschrijving", "ins_discipline_key") + " sel_oms"
                + "  FROM ins_tab_discipline"
                + " WHERE ins_discipline_verwijder IS NULL"
                + "   AND ins_discipline_module = " + safe.quoted_sql_upper(module)
                + (parent_key > -1 ? " AND ins_srtdiscipline_key = " + parent_key : "")
                + " ORDER BY ins_discipline_module, 2";
        }
        var new_lov = [];
        var oRs = Oracle.Execute(sql);
        while (!oRs.eof)
        {
            new_lov.push({key: oRs("sel_key").value,
                          oms: oRs("sel_oms").value,
                          sel: oRs("sel_key").value == init_key
                         });
            oRs.MoveNext();
        }
        oRs.Close();
        result.module = module;
        result.soort = soort;
        result.lov = new_lov;
        break;
    }
    case "menuitem":
    {
        var fac_menuitem_key = getQParamInt("menuitem_key");
        result = {};
        sql = "SELECT mi.*,"
            + "       f.fac_functie_code,"
            + "       f.fac_functie_module,"
            + "       lcl.l (f.fac_functie_omschrijving, 1) fac_functie_omschrijving"
            + " FROM fac_menuitems mi, fac_functie f"
            + " WHERE mi.fac_functie_key = f.fac_functie_key(+)"
            + "   AND mi.fac_menuitems_key = " + fac_menuitem_key;
        var oRs = Oracle.Execute(sql);
        if (!oRs.eof)
        {
            var sysFkey = oRs("fac_functie_key").value;
            result = {
                label:          L(oRs("fac_menuitems_label").value, { autolcl: true }),
                groep:          oRs("fac_menuitems_groep").value,
                module:         oRs("fac_menuitems_module").value,
                url:            oRs("fac_menuitems_url").value,
                sysFunc:        (sysFkey ? oRs("fac_functie_omschrijving").value + " (" + oRs("fac_functie_code").value + ")" : ""),
                sysFmod:        oRs("fac_functie_module").value,
                sysFrw:         oRs("fac_menuitems_rw").value,
                sysFsrtdisc:    oRs("fac_menuitems_srtdisc").value,
                sysFdisc:       oRs("fac_menuitems_disc").value,
                image:          oRs("fac_menuitems_image").value,
                alert:          oRs("fac_menuitems_oms").value
            };
        }
        oRs.Close();
        break;
    }
    case "faq_func":
    {
        var disc_key = getQParamInt("discipline_key");
        var faq_key = getQParamInt("faq_key", -1);
        var this_faq = fac.func_enabled_faq(faq_key, { "disc_key": disc_key }); // params.disc_key gaat voor de opgeslagen catalogus
        result.canBOwrite = this_faq.canBOwrite;
        break;
    }
    case "get_company":
    {
        result = { success: true, bedrijf_key: -1, bedrijf_naam: "" };
        var afd_key = getQParamInt("afd_key", -1);
        var sql = "SELECT b.prs_bedrijf_key"
                + "     , b.prs_bedrijf_naam"
                + "  FROM prs_v_aanwezigafdeling a"
                + "     , prs_v_aanwezigbedrijf b"
                + " WHERE a.prs_bedrijf_key = b.prs_bedrijf_key"
                + "   AND a.prs_afdeling_key = " + afd_key;
        var oRs = Oracle.Execute(sql);
        if (!oRs.EoF) {
            result.bedrijf_key = oRs("prs_bedrijf_key").value;
            result.bedrijf_naam = oRs("prs_bedrijf_naam").value;
        }
        oRs.Close();
        break;
    }
}
Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
