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

    File:               cad_reserveerbaar.asp
    Description:        Maak een object vanuit de tekening al dan niet reserveerbaar

    Parameters:
        ins_key
        disc_key        res-discipline
    Context:            Vanuit cad_thema click-url ../cad/cad_reserveerbaar.asp?disca_key=5&ins_key=
    Note:
*/
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file='../CAD/FGII.inc'-->

<%
user.checkAutorisation("WEB_RESMSU");

var ins_key = getQParamInt("ins_key");
var disc_key = getQParamInt("disc_key");
var alg_scope = getQParamInt("alg_scope", 2); // default locatie

var transitParam = buildTransitParam(["ins_key", "disc_key", "alg_scope"]);

// Is hij al reserveerbaar (??in onze catalogus??)
var res_deel_key = -1;
var nnFuture = 0;
var sql = "SELECT res_deel_key"
        + "     , res_discipline_key"
        + "  FROM res_deel"
        + " WHERE res_ins_deel_key = " + ins_key
        + "   AND res_deel_verwijder IS NULL";
var oRs = Oracle.Execute(sql);
if (!oRs.EOF)
{
  disc_key = oRs("res_discipline_key").Value;
  res_deel_key = oRs("res_deel_key").Value;
  var sql = "SELECT COUNT(*) cnt"
          + "  FROM res_rsv_deel"
          + " WHERE res_deel_key = " + res_deel_key
          + " AND res_rsv_deel_verwijder IS NULL"
          + " AND res_rsv_deel_van > SYSDATE";
  var oRsf = Oracle.Execute(sql);
  var nnFuture = oRsf("cnt").Value;
  oRsf.Close();
}
oRs.Close()

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>

      <script>

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

        function cad_reserveerbaar()
        {
            var data = {};
            protectRequest.dataToken(data);
            $.post("cad_reserveerbaar_save.asp?res_deel_key=<%=res_deel_key%><%=transitParam%>",
                   data,
                   FcltCallbackClose,
                   "json");
          //$.post(url, data, FcltCallbackAndThen(myRefresh), "json");
          result = true;
        }

        $(function()
        {
          FcltMgr.resized(window);
        });

      </script>
  </head>

  <body class="fclt-modal" id="mod_cadreserveerbaar">
  <% MODAL_START(); %>
    <form id="u2" name="reserveerbaarform" action="cad_reserveerbaar_save.asp" method="post">
<%    MODAL_BLOCK_START("cadReserveerbaar", L("lcl_obj_reserveerbaar"), { "icon": "fa-calendar-edit" });

    var sql = "SELECT ins_deel_omschrijving"
            + "     , " + lcl.xsqla("sd.ins_srtdeel_omschrijving", "sd.ins_srtdeel_key")
            + "  FROM ins_deel d"
            + "     , ins_srtdeel sd"
            + "     , ins_srtgroep sg"
            + "     , ins_discipline di"
            + " WHERE sd.ins_srtdeel_key = d.ins_srtdeel_key"
            + "   AND sd.ins_srtgroep_key = sg.ins_srtgroep_key"
            + "   AND sg.ins_discipline_key = di.ins_discipline_key"
            + "   AND ins_deel_key = " + ins_key;
    var oRs = Oracle.Execute(sql);

    ROFIELDTR("flddeel", L("lcl_obj_identification"), oRs("ins_deel_omschrijving").Value);
//      ROFIELDTR("fld", L("lcl_discipline"), disc);
//      ROFIELDTR("fld", L("lcl_obj_group"), group);
    ROFIELDTR("fld", L("lcl_obj_sort"), oRs("ins_srtdeel_omschrijving").Value);// + " (" + srtcode + ")");
    oRs.Close();

    if (nnFuture > 0)
    {
        ROFIELDTR("fld", "Toekomstige reserveringen"/*L("lcl_res_catalogus")*/, nnFuture);
    }
    else
    {
        var sql = "SELECT ins_discipline_key, " + lcl.xsqla("rd.ins_discipline_omschrijving", "rd.ins_discipline_key")
                + "  FROM res_discipline rd"
                + " WHERE ins_discipline_key = " + disc_key;
        var oRs = Oracle.Execute(sql);
        ROFIELDTR("fld", L("lcl_res_catalogus"), oRs("ins_discipline_omschrijving").Value);
        oRs.Close();
    }

    MODAL_BLOCK_END();
    var buttons =  [ ];
    if (nnFuture == 0)
        buttons.push({title: (res_deel_key>0?"Niet ":"") + L("lcl_obj_reserveerbaar"), icon: "fa-fclt-save", action: "cad_reserveerbaar()", singlepress: true, id:"btn_cad_submit", importance: 1});
    buttons.push({title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "cad_cancel()", importance: 3});

    SIMPLE_BLOCK_START();
    CreateButtons(buttons);
    SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
