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

    File:           ctr_scenario.asp

    Description:    fac_management aanroep van model_ctr_scenario

    Context:

    Notes:
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_ctr_scenario.inc" -->

<%
var this_model = new model_ctr_scenario();

var authparamsCTRMGT = user.checkAutorisation("WEB_CTRMGT", true);
var authparamsCTRSEN = user.checkAutorisation("WEB_CTRSEN", true);
var authparamsINSUSE = user.checkAutorisation("WEB_INSUSE", true);
var hasReadCTRMGT = authparamsCTRMGT && authparamsCTRMGT.ALGreadlevel < 9 && authparamsCTRMGT.PRSreadlevel < 9;
var hasReadCTRSEN = authparamsCTRSEN && authparamsCTRSEN.ALGreadlevel < 9 && authparamsCTRSEN.PRSreadlevel < 9;
var hasReadINSUSE = authparamsINSUSE && authparamsINSUSE.ALGreadlevel < 9 && authparamsINSUSE.PRSreadlevel < 9;

// Om de WEB_CTRSEN schrijf rechten (hasCTRSENWrite) te bepalen gebruiken we hier dezelfde methode als in mjb_incl_scen_save.asp.
// 1 Willekeurig object en controle ophalen om 1 maal de rechten te checken.
// Alleen kijken naar 1) MJOB objecten.
//                    2) de taakcategorieën die CTRUSE schrijf rechten hebben.
//                       Level of 3D authorization is 3: 3 = Read and Write separately authorizable (Ja/Nee).
var sql = "SELECT ins_srtcontrole_key"
        + "  FROM ins_v_defined_inspect di"
        + " WHERE di.ctr_ismjob = 1"
        + "   AND EXISTS (SELECT 1"
        + "                 FROM fac_v_webgebruiker w"
        + "                    , fac_functie f"
        + "                WHERE w.prs_perslid_key = " + user_key
        + "                  AND w.fac_functie_key = f.fac_functie_key"
        + "                  AND ins_discipline_key = di.ctr_discipline_key"
        + "                   AND fac_gebruiker_alg_level_write = -1"
        + "                  AND fac_functie_code = 'WEB_CTRUSE')"
        + " ORDER BY ins_deel_key DESC"
var oRs = Oracle.Execute(sql);
var srtcont_key = oRs("ins_srtcontrole_key").Value;
oRs.Close();

var sql = "SELECT isc.ctr_discipline_key"
        + "  FROM ins_srtcontrole isc"
        + " WHERE isc.ins_srtcontrole_key = " + srtcont_key;
var oRs = Oracle.Execute(sql);
ctr_disc_key = [oRs("ctr_discipline_key").Value];
oRs.Close();

// Voor CTR alleen discipline autorisatie met 3D ja/nee en read/write autorisatie (fac_functie_min_level = 3)
var ctrresult = user.func_enabled("CTR",
                                  ctr_disc_key,
                                  null, // alg_key is nvt
                                  null, // prs_key in nvt
                                  false, // pessimist (checkOptimistic)
                                  true); // nog even optional (isOptional)
var hasCTRSENWrite = ctrresult.canWrite("WEB_CTRSEN"); // Heb ik schrijf rechten om periodieke taken te begroten bij scenario's?

var buttons = [];
if (hasReadCTRMGT) buttons.push({ title: L("lcl_mjb_inst_scen"), action: "commit_scenario", icon: "fa-cog" });
if (hasCTRSENWrite) buttons.push({ title: L("lcl_mjb_copy_current"), action: "copy_current", icon: "fa-copy" });

scaffolding(this_model,
    {
        "search": {
            "autosearch": true
        },
        "list": {
            "columns": [
                "id",
                "name",
                "created",
                "name",
                "nrelements"
            ],
            "default_action": (hasReadCTRSEN && hasReadINSUSE? "scf_mjb_console" : null),
            "actions": [
                { action: "scf_show", caption: L("lcl_edit") }
            ],
            "requires": {
              js: ["./ctr_scenario.js"]
            }
        },
        "show": {
            "modal": true,
            requires: { js: ["./ctr_scenario.js"] },
            no_clone: S("fac_usrrap_mode") != 1,
            buttons: buttons
        },
        "layout": {
            "miscellaneous": {
                "icon": "fa-object-group"
            }
        }
    });
%>
<% ASPPAGE_END(); %>
