<%@ language="javascript"%>

<% /*
     $Revision$
     $Id$

    File:               SLE/sle_edit_srtdeel.asp
    Description:        Main interface to add/edit sleutels en cilinders

    Parameters:         ins_srtdeel_key: objectsoort key

    Context:            submit naar sle_edit_srtdeel_save.asp!

    Note:     NEEDS REVISION TODO!


*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../ins/ins_flexkenmerk.inc" -->

<%
FCLTHeader.Requires({ plugins:["jQuery"],
                      js: ["../sle/sle_edit_srtdeel.js"]})

var urole = "bo"; // eventjes voor de flex

var authparamsSLEBOF = user.checkAutorisation("WEB_SLEBOF");
user.auth_required_or_abort(authparamsSLEBOF.ALGwritelevel < 9 && authparamsSLEBOF.PRSwritelevel < 9);

var ins_srtdeel_key = getQParamInt("ins_srtdeel_key");
var sletype = getQParamSafe("sletype", "S"); // C=cilinders, S=sleutels
var couple = getQParamInt("couple", 0) == 1;
if (couple)
    sletype = "S";

var srtcode = "";
var srtomschr = "";
if (ins_srtdeel_key > 0) // bestaande sleutel/cilinder
{
  var sql = "SELECT s.ins_srtdeel_code"
          + "     , s.ins_srtdeel_omschrijving"
          + "     , g.ins_srtgroep_key"
          + "     , dis.ins_discipline_omschrijving"
          + "  FROM ins_srtdeel s"
          + "     , ins_srtgroep g"
          + "     , ins_tab_discipline dis"
          + " WHERE s.ins_srtgroep_key = g.ins_srtgroep_key"
          + " AND g.ins_discipline_key = dis.ins_discipline_key"
          + " AND ins_srtdeel_key = " + ins_srtdeel_key;
  oRs = Oracle.Execute(sql);
  srtcode = oRs("ins_srtdeel_code").value;
  srtomschr = oRs("ins_srtdeel_omschrijving").value;
  var srtgroep_key = oRs("ins_srtgroep_key").value;
  sletype = (srtgroep_key == S("sle_ins_srt_groep_key")? "S" : "C");
}

// Bepaal of er kenmerken zijn
if (couple)
  var srtgroep = S("sle_ins_srt_groep_key") + ", " + S("cil_ins_srt_groep_key");
else
  var srtgroep = (sletype == "S"? S("sle_ins_srt_groep_key") : S("cil_ins_srt_groep_key"));

var sql = "SELECT k.ins_kenmerk_key"
        + " FROM ins_srtkenmerk t"
        + ", ins_kenmerk k"
        + ", ins_srtdeel s"
        + ", ins_srtgroep g"
        + " WHERE s.ins_srtgroep_key IN (" + srtgroep + ")"
        + " AND ins_kenmerk_bewerkniveau = 'S'"
        + " AND (   (    k.ins_srtinstallatie_key = s.ins_srtdeel_key"
        + " AND k.ins_kenmerk_niveau = 'S')"
        + " OR (    k.ins_srtinstallatie_key = s.ins_srtgroep_key"
        + " AND k.ins_kenmerk_niveau = 'G')"
        + " OR (    k.ins_srtinstallatie_key = g.ins_discipline_key"
        + " AND k.ins_kenmerk_niveau = 'D')"
        + " )"
        + " AND k.ins_srtkenmerk_key = t.ins_srtkenmerk_key"
        + " AND g.ins_srtgroep_key = s.ins_srtgroep_key"
        + " AND k.ins_kenmerk_verwijder IS NULL"
        + " AND t.ins_srtkenmerk_verwijder IS NULL";
oRs = Oracle.Execute(sql);
var uitleen_flex_present = false;
if (!oRs.eof) uitleen_flex_present = true;
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type='text/javascript'>
      var ins_srtdeel_key = <%=ins_srtdeel_key%>;
      var sle_cil_koppelen = <%=S("sle_cil_koppelen")%>;
      function sleClose(params)
      {
        if (!params.keepForm)
        {
            $("#sel_items tr.sleroom").remove(); // wissen ruimtes voor volgende sleutel
            $("#srtcode,#srtomschr").val("");
            $("#sleaantal").val(1);
        }
        FcltMgr.closeDetail(window, params); // verder naar de parent
      }

    </script>
  </head>
  <body class="editmode">
<%  SUBFRAME_START();
    var buttons = [];
    buttons.push({title: L("lcl_submit"), action:"sle_submit()", icon: "fa-fclt-save" })
    buttons.push( {title: L("lcl_cancel"), action:"sle_cancel()", icon: "fa-fclt-cancel" } );

    IFRAMER_HEADER((sletype == "S"? L("lcl_sle_sleutel_set") : L("lcl_cil_cilinder_set")), buttons);
%>
      <form name="u2"
            action="sle_edit_srtdeel_save.asp?ins_srtdeel_key=<%=ins_srtdeel_key%>"
            method="post"
            target="hidFrameSubmit"
            onSubmit="sle_submit();">
<%     
        BLOCK_START("sleIns", (sletype == "S" ? L("lcl_sle_sleutel_set") : L("lcl_cil_cilinder_set")), { icon: (sletype == "S" ? "fa-key" : "fa-minus-circle fa-rotate-90") });
%>
        <input type="hidden" name="sletype" id="sletype" value="<%=sletype%>">
<%

        RWFIELDTR("srtcode", "fldshort", sletype == "S"? L("lcl_sle_sleutel_code") : L("lcl_cil_cilinder_code"), srtcode,
                  { required: true,
                    maxlength: 10
                  });

        RWFIELDTR("srtomschr", "fld", L("lcl_descr"), srtomschr,
                  { required: true,
                    maxlength: 100
                  });

        if (couple)
        {
          RWFIELDTR("sleaantal", "fldshort", L("lcl_sle_sleaantal"), 1,
                    { required: true,
                      maxlength: 3,
                      datatype: "number"
                    });
        }
        BLOCK_END();

        if (couple)
        {
        BLOCK_START("sleRuimte", L("lcl_sle_ruimte"), { icon: "fa-map-marker" });
          FCLTplaatsselector(authparamsSLEBOF.ALGwritelevel, { startlevel: 2, // Locatie
                                                               eindlevel: 5, // Ruimte
                                                               autoselect: true,
                                                               filtercode: "EXP"
                                                             });
%>
          <tr>
            <td></td><td>
            <div id="addroomslebuttons">
<%
    buttons = [{ title: L("lcl_sle_room_add_btn"), icon: "fa-plus", action: "AddItem();FcltMgr.resized(window);", id:"btn_sle_morerooms" }];
    CreateButtons(buttons, { showIcons: true });
%>
            </div>
            </td>
          </tr>

          <tr>
            <td colspan="2">
              <label><%=L("lcl_sle_ruimte")%></label>
              <!-- SELECTED ITEMS -->
              <table id="sel_items" cellspacing="0" cellpadding="0" width="100%">
              <tr>
                <th width="24"></th>
                <th><%=L("lcl_sle_ruimte_omschr")%> </th>
              </tr>
              </table>
            </td>
          </tr>
<%
          BLOCK_END();
        }
        if (uitleen_flex_present) // Je ziet alleen flexkenmerken als ze er zijn
        {
              generateFlexKenmerkBlock({ urole: urole,
                                         bewerkniveau: "S",
                                         niveau: "S", // sleutels
                                         srtdeel_key: ins_srtdeel_key,
                                         srtgroep_key: (sletype == "S"? S("sle_ins_srt_groep_key") : S("cil_ins_srt_groep_key")),
                                         srtdeelkey_array: ins_srtdeel_key > 0? [ins_srtdeel_key] : [],
                                         reado: false
                                       });
        }
        if (uitleen_flex_present && couple) // Bij aanmaken sleutel/cilinder sets ook de cilinder flexkenmerken tonen.
        {
          generateFlexKenmerkBlock({ urole: urole,
                                     bewerkniveau: "S",
                                     srtgroep_key: S("cil_ins_srt_groep_key"),
                                     srtdeelkey_array: [],
                                     reado: false,
                                     nameprefix: "kk",
                                     extraserie: true
                                   });
        }
IFACE.FORM_END();
%>
      </form>
      <% SUBFRAME_END(); %>
      <iframe src="../Shared/empty.html"
              FcltClose="sleClose"
              name="hidFrameSubmit"
              style="display:none"></iframe>
  </body>
</html><% ASPPAGE_END(); %>
