<%@language = "javascript" %>
<%  Server.ScriptTimeout=6000; %>
<% /*
     $Revision$
     $Id$

    File:               mjb_incl_scen.asp
    Description:        Invoerscherm voor het opnemen van periodieke taken in een scenario
    Parameters:
        ins_keys        Array van object keys.
        srtcont_keys    Array van soort controlesopdracht keys

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/discxalg3d.inc" -->
<!-- #include file="../INS/ins.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: [] })
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
<%
    var posting = getQParamInt("post", 0) == 1;
    var groupby = getQParamInt("groupby", 9);

    var authparamsCTRSEN = user.checkAutorisation("WEB_CTRSEN");
    var hasWriteCTRSEN = authparamsCTRSEN.ALGwritelevel < 9 && authparamsCTRSEN.PRSwritelevel < 9;
    user.anything_todo_or_abort(hasWriteCTRSEN); // Er zijn enige WEB_CTRSEN schrijf rechten nodig.

    if (!posting)
    { %>
        <script type="text/javascript">
          $(function()
          {
            var insKeyString = FcltMgr.dialogArguments().insKeyString;
            var srtcontrolekeyArray = FcltMgr.dialogArguments().srtcontrolekeyArray;
            var scenariokeyArray = FcltMgr.dialogArguments().scenariokeyArray;
            var deelsrtcontrstatusArray = FcltMgr.dialogArguments().deelsrtcontrstatusArray;
            var isfreezeyearArray = FcltMgr.dialogArguments().isfreezeyearArray;
            var ctrdisciplinekeyArray = FcltMgr.dialogArguments().ctrdisciplinekeyArray;
            var aantaltaken = FcltMgr.dialogArguments().aantaltaken;
            $("#ins_keys").val(insKeyString);
            $("#srtcont_keys").val(srtcontrolekeyArray);
            $("#scen_key_arr").val(scenariokeyArray);
            $("#deelsrtcontrstatus_arr").val(deelsrtcontrstatusArray);
            $("#isfreezeyear_arr").val(isfreezeyearArray);
            $("#ctrdisc_keys").val(ctrdisciplinekeyArray);
            $("#aantaltaken").val(aantaltaken);
            var groupby = FcltMgr.dialogArguments().groupby;
            if (groupby < 9)
            {
              var scenario = FcltMgr.dialogArguments().scenario;
              var actsit = FcltMgr.dialogArguments().actsit;
              var showempty = FcltMgr.dialogArguments().showempty;
              var dist_key_arr = FcltMgr.dialogArguments().dist_key_arr;
              var loc_key_arr = FcltMgr.dialogArguments().loc_key_arr;
              var bld_key_arr = FcltMgr.dialogArguments().bld_key_arr;
              var disc_key_arr = FcltMgr.dialogArguments().disc_key_arr;
              var srtgroep_key_arr = FcltMgr.dialogArguments().srtgroep_key_arr;
              var srtdeel_key_arr = FcltMgr.dialogArguments().srtdeel_key_arr;
              var moredetail = FcltMgr.dialogArguments().moredetail;
              var srtgebouw_key_arr = FcltMgr.dialogArguments().srtgebouw_key_arr;
              var groep_str_arr = FcltMgr.dialogArguments().groep_str_arr;
              var categorie_key_arr = FcltMgr.dialogArguments().categorie_key_arr;
              var srtcontrole_key_arr = FcltMgr.dialogArguments().srtcontrole_key_arr;
              var frequentie_arr = FcltMgr.dialogArguments().frequentie_arr;
              var kp_key_arr = FcltMgr.dialogArguments().kp_key_arr;
              var incbtw = FcltMgr.dialogArguments().incbtw;
              var showunfin = FcltMgr.dialogArguments().showunfin;
              var toyear = FcltMgr.dialogArguments().toyear;
              var groupby = FcltMgr.dialogArguments().groupby;
              var deel = FcltMgr.dialogArguments().deel;
              var fitness_score1_from = FcltMgr.dialogArguments().fitness_score1_from;
              var fitness_score1_through = FcltMgr.dialogArguments().fitness_score1_through;
              var fitness_score1_from_neg = FcltMgr.dialogArguments().fitness_score1_from_neg;
              var fitness_score1_through_neg = FcltMgr.dialogArguments().fitness_score1_through_neg;
              var fitness_score1_from_pos = FcltMgr.dialogArguments().fitness_score1_from_pos;
              var fitness_score1_through_pos = FcltMgr.dialogArguments().fitness_score1_through_pos;
              var priority_score2_from = FcltMgr.dialogArguments().priority_score2_from;
              var priority_score2_through = FcltMgr.dialogArguments().priority_score2_through;
              var mjbMoved = FcltMgr.dialogArguments().mjbMoved;
              var mjbFreezed = FcltMgr.dialogArguments().mjbFreezed;
              var mjbXcped = FcltMgr.dialogArguments().mjbXcped;
              var jaren = FcltMgr.dialogArguments().jaren;
              $("#scenario").val(scenario);
              $("#actsit").val(actsit);
              $("#showempty").val(showempty);
              $("#dist_key_arr").val(dist_key_arr);
              $("#loc_key_arr").val(loc_key_arr);
              $("#bld_key_arr").val(bld_key_arr);
              $("#disc_key_arr").val(disc_key_arr);
              $("#srtgroep_key_arr").val(srtgroep_key_arr);
              $("#srtdeel_key_arr").val(srtdeel_key_arr);
              $("#moredetail").val(moredetail);
              $("#srtgebouw_key_arr").val(srtgebouw_key_arr);
              $("#groep_str_arr").val(groep_str_arr);
              $("#categorie_key_arr").val(categorie_key_arr);
              $("#srtcontrole_key_arr").val(srtcontrole_key_arr);
              $("#frequentie_arr").val(frequentie_arr);
              $("#kp_key_arr").val(kp_key_arr);
              $("#incbtw").val(incbtw);
              $("#showunfin").val(showunfin);
              $("#toyear").val(toyear);
              $("#groupby").val(groupby);
              $("#deel").val(deel);
              $("#fitness_score1_from").val(fitness_score1_from);
              $("#fitness_score1_through").val(fitness_score1_through);
              $("#fitness_score1_from_neg").val(fitness_score1_from_neg);
              $("#fitness_score1_through_neg").val(fitness_score1_through_neg);
              $("#fitness_score1_from_pos").val(fitness_score1_from_pos);
              $("#fitness_score1_through_pos").val(fitness_score1_through_pos);
              $("#priority_score2_from").val(priority_score2_from);
              $("#priority_score2_through").val(priority_score2_through);
              $("#mjbMoved").val(mjbMoved);
              $("#mjbFreezed").val(mjbFreezed);
              $("#mjbXcped").val(mjbXcped);
              $("#jaren").val(jaren);
            }
            document.forms.u2.submit();
          });
        </script>
      </head>

      <body class="fclt-modal"
            id="mod_mjbinclscen">
            <% MODAL_START(); %>
        <div class="busyloading" style="width:100%;position: top"><span><%=I("fa-fclt-spinner fa-4x")%></span></div>
          <form name="u2" id="u2" action="mjb_incl_scen.asp?post=1&groupby=<%=groupby%>"  method="post">
            <input type="hidden" name="ins_keys" id="ins_keys" value="">
            <input type="hidden" name="srtcont_keys" id="srtcont_keys" value="">
            <input type="hidden" name="scen_key_arr" id="scen_key_arr" value="">
            <input type="hidden" name="deelsrtcontrstatus_arr" id="deelsrtcontrstatus_arr" value="">
            <input type="hidden" name="isfreezeyear_arr" id="isfreezeyear_arr" value="">
            <input type="hidden" name="ctrdisc_keys" id="ctrdisc_keys" value="">
            <input type="hidden" name="aantaltaken" id="aantaltaken" value="">
            <input type="hidden" name="groupby" id="groupby" value="">
<%          if (groupby < 9)
            { %>
              <input type="hidden" name="scenario" id="scenario" value="">
              <input type="hidden" name="actsit" id="actsit" value="">
              <input type="hidden" name="showempty" id="showempty" value="">
              <input type="hidden" name="dist_key_arr" id="dist_key_arr" value="">
              <input type="hidden" name="loc_key_arr" id="loc_key_arr" value="">
              <input type="hidden" name="bld_key_arr" id="bld_key_arr" value="">
              <input type="hidden" name="disc_key_arr" id="disc_key_arr" value="">
              <input type="hidden" name="srtgroep_key_arr" id="srtgroep_key_arr" value="">
              <input type="hidden" name="srtdeel_key_arr" id="srtdeel_key_arr" value="">
              <input type="hidden" name="moredetail" id="moredetail" value="">
              <input type="hidden" name="srtgebouw_key_arr" id="srtgebouw_key_arr" value="">
              <input type="hidden" name="groep_str_arr" id="groep_str_arr" value="">
              <input type="hidden" name="categorie_key_arr" id="categorie_key_arr" value="">
              <input type="hidden" name="srtcontrole_key_arr" id="srtcontrole_key_arr" value="">
              <input type="hidden" name="frequentie_arr" id="frequentie_arr" value="">
              <input type="hidden" name="kp_key_arr" id="kp_key_arr" value="">
              <input type="hidden" name="incbtw" id="incbtw" value="">
              <input type="hidden" name="showunfin" id="showunfin" value="">
              <input type="hidden" name="toyear" id="toyear" value="">
              <input type="hidden" name="deel" id="deel" value="">
              <input type="hidden" name="fitness_score1_from" id="fitness_score1_from" value="">
              <input type="hidden" name="fitness_score1_through" id="fitness_score1_through" value="">
              <input type="hidden" name="fitness_score1_from_neg" id="fitness_score1_from_neg" value="">
              <input type="hidden" name="fitness_score1_through_neg" id="fitness_score1_through_neg" value="">
              <input type="hidden" name="fitness_score1_from_pos" id="fitness_score1_from_pos" value="">
              <input type="hidden" name="fitness_score1_through_pos" id="fitness_score1_through_pos" value="">
              <input type="hidden" name="priority_score2_from" id="priority_score2_from" value="">
              <input type="hidden" name="priority_score2_through" id="priority_score2_through" value="">
              <input type="hidden" name="mjbMoved" id="mjbMoved" value="">
              <input type="hidden" name="mjbFreezed" id="mjbFreezed" value="">
              <input type="hidden" name="mjbXcped" id="mjbXcped" value="">
              <input type="hidden" name="jaren" id="jaren" value="">
<%          }
            protectRequest.inputToken();
%>
          </form>
        <% MODAL_END(); %>
      </body>
<%  }
    else
    {
      protectRequest.validateToken();

      var ins_key_arr = getFParamKeyArray("ins_keys");
      var srtcont_key_arr = getFParamKeyArray("srtcont_keys", []);
      var scen_key_arr = getFParamKeyArray("scen_key_arr", []);
      var deelsrtcontrstatus_arr = getFParamIntArray("deelsrtcontrstatus_arr", []);
      var isfreezeyear_arr = getFParamIntArray("isfreezeyear_arr", []);
      var ctrdisc_key_arr = getFParamKeyArray("ctrdisc_keys", []);
      var aantaltaken = getFParamInt("aantaltaken", 0);
      var multi = ins_key_arr.length > 1;
      //var inflatiepct = S("mjb_inflation");
      //var inflatiefactor = 1 + (inflatiepct / 100);
      var mjb_start_year = S("mjb_start_year");
      var mjb_freeze_year = Math.max(S("mjb_freeze_year"), new Date().getFullYear());

      if (groupby < 9)
      {
        var scenario = getFParamInt("scenario", 1);
        var actsit = getFParamInt("actsit", 0) == 1;
        var showempty = getFParamInt("showempty", 0) == 1;
        var dist_key_arr = getFParamKeyArray("dist_key_arr", []); // District array
        var loc_key_arr = getFParamKeyArray("loc_key_arr", []); // Locatie array
        var bld_key_arr = getFParamKeyArray("bld_key_arr", []); // Gebouw array

        var disc_key_arr = getFParamKeyArray("disc_key_arr", []);
        var srtgroep_key_arr = getFParamKeyArray("srtgroep_key_arr", []);
        var srtdeel_key_arr = getFParamKeyArray("srtdeel_key_arr", []);
        var moredetail = getFParamKeyArray("moredetail", []);
        var srtgebouw_key_arr = getFParamKeyArray("srtgebouw_key_arr", []);
        var groep_str_arr = getFParamArray("groep_str_arr", []); // Groep
        var categorie_key_arr = getFParamKeyArray("categorie_key_arr", []); // Categorie
        var srtcontrole_key_arr = getFParamKeyArray("srtcontrole_key_arr", []); // Taak
        var frequentie_arr = getFParamIntArray("frequentie_arr", []); // Array met frequenties.
        var kp_key_arr = getFParamKeyArray("kp_key_arr", []); // Kostenplaats.
        var incbtw = getFParamInt("incbtw", 0) == 1; // Lijst inclusief BTW weergeven.
        var showunfin = getFParamInt("showunfin", 0) == 1; // Alleen onvoltooide regels.
        var toyear = getFParamInt("toyear"); // Tot aan jaar.
        //var inflatiepct = S("mjb_inflation");
        //var inflatiefactor = 1 + (inflatiepct / 100);
        var deel = getFParam("deel", ""); // Identieficatie
        var jaren = getFParamIntArray("jaren", []); // Jaren

        // FORM score velden.
        var fitness_score1_from = getFParamInt("fitness_score1_from", -1);               // Conditie score van.
        var fitness_score1_through = getFParamInt("fitness_score1_through", -1);         // Conditie score t/m.
        var fitness_score1_from_neg = getFParamInt("fitness_score1_from_neg", -1);       // Negatieve afwijking conditie score van.
        var fitness_score1_through_neg = getFParamInt("fitness_score1_through_neg", -1); // Negatieve afwijking conditie score t/m.
        var fitness_score1_from_pos = getFParamInt("fitness_score1_from_pos", -1);       // Positieve afwijking conditie score van.
        var fitness_score1_through_pos = getFParamInt("fitness_score1_through_pos", -1); // Positieve afwijking conditie score t/m.
        var priority_score2_from = getFParamInt("priority_score2_from", -1);             // Prioriteitsscore van.
        var priority_score2_through = getFParamInt("priority_score2_through", -1);       // Prioriteitsscore t/m.

        // FORM status checkboxes.
        var mjbMoved  = getFParamInt("mjbMoved", 0) == 1; // Verschoven.
        var mjbFreezed = getFParamInt("mjbFreezed", 0) == 1; // In behandeling.
        var mjbXcped = getFParamInt("mjbXcped", 0) == 1; // Aangepast.

        // Start building the query to fetch all objects satisfying
        var mjbparams = { niveau: groupby,   // Het niveau (betekenis) van de keys (district(1), locatie(2), gebouw(3), discipline(4), groep(5), objectsoort(6), object(7))
                          keys: ins_key_arr,
                          scenario: 1,
                          fulldetails: true,
                          actsit: actsit, // Parameter actsit alleen van invloed op scenario_key > 1.
                          //showempty: showempty, // Niet meegeven. Hieronder wordt bepaald of de lege regels meegenomen worden.
                          dist_key_arr: dist_key_arr,
                          loc_key_arr: loc_key_arr,
                          bld_key_arr: bld_key_arr,
                          disc_key_arr: disc_key_arr,
                          srtgroep_key_arr: srtgroep_key_arr,
                          srtdeel_key_arr: srtdeel_key_arr,
                          moredetail: moredetail,
                          srtgebouw_key_arr: srtgebouw_key_arr,
                          groep_str_arr: groep_str_arr,
                          categorie_key_arr: categorie_key_arr,
                          srtcontrole_key_arr: srtcontrole_key_arr,
                          frequentie_arr: frequentie_arr,
                          kp_key_arr: kp_key_arr,
                          incbtw: incbtw,
                          showunfin: showunfin,
                          //inflatiefactor: inflatiefactor,
                          toyear: toyear,
                          groupby: 9, // Ik wil alle objecten opvragen.
                          deel: deel,
                          fitness_score1_from : fitness_score1_from,
                          fitness_score1_through : fitness_score1_through,
                          fitness_score1_from_neg : fitness_score1_from_neg,
                          fitness_score1_through_neg : fitness_score1_through_neg,
                          fitness_score1_from_pos : fitness_score1_from_pos,
                          fitness_score1_through_pos : fitness_score1_through_pos,
                          priority_score2_from : priority_score2_from,
                          priority_score2_through : priority_score2_through,
                          mjbMoved: mjbMoved,
                          mjbFreezed: mjbFreezed,
                          mjbXcped: mjbXcped,
                          jaren: jaren,
                          addToScenario: true
                        };
        var mjblist_sql = ins.getmjblist_sql(mjbparams);
        // De mjblist_sql bevat nu alle objecten (ins_deel_key) van de aangevinkte regels uit het mjb overzicht en levert voor elk object ook de ins_srtcontrole waarde op.

        var result = {key: "", success: true, multi: multi, start: true };

        var oRs = Oracle.Execute(mjblist_sql);
        user.anything_todo_or_abort(!oRs.eof, L("lcl_mjb_inclscen_mes_n").format(0, aantaltaken)); // We klagen niet over enkele wel en enkele niet

        ins_key_arr = [];
        srtcont_key_arr = [];
        scen_key_arr = [];
        deelsrtcontrstatus_arr = [];
        isfreezeyear_arr = [];
        ctrdisc_key_arr = [];
        while (!oRs.eof)
        {
          if (!showempty)
          { // De lege regels eruit filteren.
            var isLegeRegel = true;
            for (var j = 0; j < jaren.length; j++)
            {
              if (oRs(String(jaren[j])).Value != null) // Wel regels met een bedrag van 0 i.p.v. null tonen. Die moeten wel geaccodeerd worden ook al kosten deze niets.
              { // Er staat een bedrag op de regel.
                isLegeRegel = false;
                break;
              }
            }
            if (isLegeRegel)
            {
              oRs.MoveNext();
              continue; // Lege regel niet tonen.
            }
          }

          ins_key_arr[ins_key_arr.length] = oRs("ins_deel_key").Value;
          srtcont_key_arr[srtcont_key_arr.length] = oRs("ins_srtcontrole_key").Value;
          scen_key_arr[scen_key_arr.length] = oRs("ins_scenario_key").Value;
          deelsrtcontrstatus_arr[deelsrtcontrstatus_arr.length] = oRs("ins_deelsrtcontrole_status").Value == null? -1 : oRs("ins_deelsrtcontrole_status").Value;
          isfreezeyear_arr[isfreezeyear_arr.length] = oRs("isfreezeYear").Value;
          ctrdisc_key_arr[ctrdisc_key_arr.length] = oRs("ctr_discipline_key").Value;
          oRs.MoveNext();
        }
        oRs.Close();
      }

      var tobeincluded = 0;
      var ingesloten = [];
      var ingeslotensrtc = [];
      var ingeslotenscen = [];
      var ingeslotendeelscs = [];
      var ingeslotenisfy = [];
      var ingeslotenctrd = [];
      // Bepaal de objecten in de selectie die
      // ook echt opgenomen kunnen of mogen worden in het scenario.
      for (var i = 0; i < ins_key_arr.length; i++)
      {
        // Elke taak wordt gecontroleerd of deze toegevoegd mag worden. Dit gebeurt door de functie "func_enabled_deel" aan te roepen die het in de "canAddToScen" parameter stopt.
        // De query in die functie om de benodigde gegevens (isScenario, deelsrtcontrole_status, isfreezeyear) op te halen kost veel tijd. Daarom krijgt men vaak een script timeout.
        // De benodigde gegevens kunnen ook al met de query van de functie ins.getmjblist_sql bepaald worden. De rechten kunnen we hier ook zelf bepalen.
        // Dus vanwege zeer veel tijdwinst gaan we zelf canAddToScen bepalen.

        // Voor CTR alleen discipline autorisatie met 3D ja/nee en read/write autorisatie (fac_functie_min_level = 3)
        var ctrresult = user.func_enabled("CTR",
                                          ctrdisc_key_arr[i],
                                          null, // alg_key is nvt
                                          null, // prs_key in nvt
                                          false, // pessimist (checkOptimistic)
                                          true); // nog even optional (isOptional)
        var hasWrite = false;
        if (ctrresult.canWrite("WEB_CTRUSE") || ctrresult.canWrite("WEB_CTRSEN")) // Heb ik schrijf rechten om periodieke taken uit te voeren in de actuele situatie (WEB_CTRUSE) of bij scenario's (WEB_CTRSEN)?
          var hasWrite = true;
        else
        { // Dan kijken we of de objectbeheerder het object mag wijzigen en de user de objectbeheerder is.
          if (S("ins_can_edit_own_objects"))
          {
            var sql_b = "SELECT d.prs_perslid_key_beh"
                     + "  FROM ins_deel d"
                     + " WHERE d.ins_deel_key = " + ins_key_arr[i];
            var oRs_b = Oracle.Execute(sql_b);
            var beheerder_key = oRs_b("prs_perslid_key_beh").value;
            var objectbeheerder = (beheerder_key == user_key);
            oRs_b.Close();
            hasWrite = objectbeheerder;
          }
        }
        var isScenario = scen_key_arr[i] > 1;

        var canAddToScen = (hasWrite && !isScenario) &&
                           ((deelsrtcontrstatus_arr[i] != 2 && deelsrtcontrstatus_arr[i] != 3 && deelsrtcontrstatus_arr[i] != 5) || !isfreezeyear_arr[i]);

        //var this_ins = ins.func_enabled_deel(ins_key_arr[i], {srtcont_key: srtcont_key_arr[i]});
        if (canAddToScen) // Mag ik nieuwe exceptions (xcp) waarden van de taak voor het nieuwe scenario wijzigen?
        {
          ingesloten.push(ins_key_arr[i]);
          ingeslotensrtc.push(srtcont_key_arr[i]);
          ingeslotenscen.push(scen_key_arr[i]);
          ingeslotendeelscs.push(deelsrtcontrstatus_arr[i]);
          ingeslotenisfy.push(isfreezeyear_arr[i]);
          ingeslotenctrd.push(ctrdisc_key_arr[i]);
          tobeincluded++;
        }
      }
      user.anything_todo_or_abort(tobeincluded > 0, L("lcl_mjb_inclscen_mes_n").format(0, aantaltaken)); // We klagen niet over enkele wel en enkele niet.

      lcl.set_dialect(ctrdisc_key_arr[0], "INS_TAB_DISCIPLINE_KEY");

      var sql_scen = "SELECT COUNT(ins_scenario_key) aantal"
                   + "     , MAX(ins_scenario_key) maxkey"
                   + "  FROM ins_scenario"
                   + " WHERE ins_scenario_verwerkt IS NULL"
                   + "   AND ins_scenario_key > 1";
      var oRs = Oracle.Execute(sql_scen);
      var aantal = oRs("aantal").Value;
      var maxkey = oRs("maxkey").Value;
      var hassenarios = aantal > 0;
      oRs.Close();
%>
      <script>
        var hassenarios = <%=hassenarios? 1 : 0%> == 1;

        function afsluiten(jdata)
        { // Sluit onszelf.
            FcltMgr.closeDetail(window, { warning: jdata.warning, success: true });
        }

        var newinvoer = false;
        async function mjb_inclscen()
        {
          if ($("#scenario").val() > 0 || newinvoer)
          {
            // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
            if (!await validateForm("u2"))
              return false;

            $.post($("form[name=u2]")[0].action,
                   $("[name=u2]").serialize(),
                   FcltCallbackAndThenAlways(afsluiten),
                   "json");
            return true; // disable button
          }
          else
          { // Nieuw scenario. Invoervelden voor nieuw scenario zichtbaar maken en selectbox verbergen.
            $("#mjbexistscen").hide();
            $("#mjbnewscen").show();
            FcltMgr.resized(window);
            $("#scen_key").val(-1); // Nieuw scenario => scen_key waarde -1 geven.
            $("#scenoms").addClass("required");
            newinvoer = true;
            return false; // Button niet disablen.
          }
        }

        $(function()
        {
          if (!hassenarios)
            mjb_inclscen();
        })

        function mld_cancel()
        {
          FcltMgr.closeDetail(window, { cancel: true } );
        }

        function onChangeScenario()
        {
          $("#scen_key").val($("#scenario").val());
        }
      </script>
    </head>


    <body class="fclt-modal" id="mod_mjbinclscen">
    <% MODAL_START(); %>
      <form action="mjb_incl_scen_save.asp" method="post" name="u2">
      <% MODAL_BLOCK_START("mjbexistscen", L("lcl_mjb_scenario"), {hidden: !hassenarios, icon: "fa-tasks"}); %>
          <input type="hidden" name="ins_keys" id="ins_keys" value="<%=ingesloten.join(",")%>">
          <input type="hidden" name="srtcont_keys" id="srtcont_keys" value="<%=ingeslotensrtc.join(",")%>">
          <input type="hidden" name="scen_key_arr" id="scen_key_arr" value="<%=ingeslotenscen.join(",")%>">
          <input type="hidden" name="deelsrtcontrstatus_arr" id="deelsrtcontrstatus_arr" value="<%=ingeslotendeelscs.join(",")%>">
          <input type="hidden" name="isfreezeyear_arr" id="isfreezeyear_arr" value="<%=ingeslotenisfy.join(",")%>">
          <input type="hidden" name="ctrdisc_keys" id="ctrdisc_keys" value="<%=ingeslotenctrd.join(",")%>">
          <input type="hidden" name="aantaltaken" id="aantaltaken" value="<%=aantaltaken%>">
          <input type="hidden" name="scen_key" id="scen_key" value="<%=aantal == 1? maxkey : -1%>">
<%
          // Nieuw scenario is ook een echte keuze. Als deze alleen aanwezig is wordt de omschrijving leeg gemaakt. Daarom in sql opgenomen.
          sql = "SELECT -1"
              + "     , " +  safe.quoted_sql(L("lcl_mjb_new_scenario")) + " ins_scenario_omschrijving"
              + "     , 1"
              + "  FROM ins_scenario"
              + " UNION "
          sql = "SELECT ins_scenario_key"
              + "     , ins_scenario_omschrijving"
              + "     , 2"
              + "  FROM ins_scenario"
              + " WHERE ins_scenario_verwerkt IS NULL"
              + "   AND ins_scenario_key <> 1"  // niet die actieve
              + " ORDER BY 3, ins_scenario_omschrijving";
          FCLTselector("scenario",
                       sql,
                       { label: L("lcl_mjb_scenarios"),
                         onChange: "onChangeScenario()",
                         initKey: -1,
                         emptyOption: L("lcl_mjb_new_scenario"),
                         emptyIsRealValue: true
                       });
          MODAL_BLOCK_END();
          MODAL_BLOCK_START("mjbnewscen", L("lcl_mjb_new_scenario"), {hidden: hassenarios, icon: "fa-plus"});
            RWFIELDTR("scenoms",  "fldscenoms fld", L("lcl_mjb_scenario"), "", {maxlength: 30});

            RWTEXTAREATR("scenopm",
                         "fldtxt",
                         L("lcl_mjb_scen_opm"),
                         "",
                         {html: "rows='8' cols='80'"});

          MODAL_BLOCK_END();

        var buttons = [];
        buttons.push({title: L("lcl_ok"), action:"mjb_inclscen()", singlepress: true, id: "btn_submit", icon: "fa-fclt-save"});       // Opnemen in scenario.
        buttons.push({title: L("lcl_cancel"),  action:"mld_cancel()", icon: "fa-fclt-cancel"});
        SIMPLE_BLOCK_START();
          CreateButtons(buttons);
        SIMPLE_BLOCK_END();

        IFACE.FORM_END();
%>
      </form>
      <% MODAL_END(); %>
    </body>
<%  } %>
</html>
<% ASPPAGE_END(); %>
