<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->

<%
FCLTHeader.Requires({ plugins:["suggest", "jQuery", "kenmerk"],
                      js: ["../sle/sleutel_search.js"]
                    });

/***** Get webform parameters *****/
var urole = getQParamSafe("urole");
var fronto = (urole == "fo");
var backo = (urole == "bo");
var minfo = (urole == "mi");

var sletype = getQParamSafe("sletype", ""); // C=cilinders, S=sleutels

var loc_key = getQParamInt("locatie_key", -1); // Locatie
var bld_key = getQParamInt("gebouw_key", -1); // Gebouw
var flr_key = getQParamInt("verdieping_key", -1); // Verdieping
var room_key = getQParamInt("ruimte_key", -1); // Ruimte
var wpl_key = getQParamInt("werkplek_key", -1); // Werkplek
var deel = getQParam("deel", ""); // Identificatie

var dep_key = getQParamInt("dep_key", -1); // Organisatie key
var prs_key = getQParamInt("prs_key", -1); // Persoon key
/***** End get webform parameters *****/

var autfunction = "";
switch(urole)
{
  case "fo": autfunction = "WEB_SLEFOF";
           break;
  case "bo": autfunction = "WEB_SLEBOF";
           break;
}
// De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
var authparams = user.checkAutorisation(autfunction);

var authparamsSLEBOF = user.checkAutorisation("WEB_SLEBOF", true);
var authparamsSLEFOF = user.checkAutorisation("WEB_SLEFOF", true);
%>

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

    // Sleutels
    var sql = "SELECT sd.ins_srtdeel_key"
            + "  FROM ins_srtdeel sd"
            + " WHERE sd.ins_srtgroep_key = " + S("sle_ins_srt_groep_key");
    oRs = Oracle.Execute(sql);
    var sle_ins_srtdeelstr = "";
    while (!oRs.eof)
    {
      sle_ins_srtdeelstr += (sle_ins_srtdeelstr != ""? "," : "") + oRs("ins_srtdeel_key").value;
      oRs.MoveNext();
    }

    // Cilinders
    var sql = "SELECT sd.ins_srtdeel_key"
            + "  FROM ins_srtdeel sd"
            + " WHERE sd.ins_srtgroep_key = " + S("cil_ins_srt_groep_key");
    oRs = Oracle.Execute(sql);
    var cil_ins_srtdeelstr = "";
    while (!oRs.eof)
    {
      cil_ins_srtdeelstr += (cil_ins_srtdeelstr != ""? "," : "") + oRs("ins_srtdeel_key").value;
      oRs.MoveNext();
    }
%>

    <script type="text/javascript">
      function getSrtdeelString()
      {
        // srtdeel waarde ophalen (radio button of hidden veld)
        if ("<%=sletype%>" == "S") // alleen sleutels
          return $("#sle_ins_srtdeelstr").val();
        else if ("<%=sletype%>" == "C") // alleen cilinders
          return $("#cil_ins_srtdeelstr").val();
        else if ($('#sletype_s').is(':checked'))
          return $("#sle_ins_srtdeelstr").val();
        else if ($('#sletype_c').is(':checked'))
          return $("#cil_ins_srtdeelstr").val();
      }

      function doSubmit()
      {
<%      if (backo)
        { %>
          // Submitten met kenmerken
          doSubmitWithKenmerken();
<%      }
        else
        { %>
          document.forms.u2.submit();
<%      } %>
      }

<%    if (backo)
      { %>
        async function myModal(init)
        {
          var lsrtdeel_key_str = getSrtdeelString()
          var url = "../INS/load_kenmerk.asp";
          var titel = L("lcl_ins_kenmerken");
          var pdata = { srtdeel: lsrtdeel_key_str.split(","),
                        urole: "<%=urole%>",
                        advanced: 1,
                        hasFilter: 1,
                        bewerkniveau: "S"
                      };
          await showKenmerkModal(url, titel, init, pdata)
        }
<%    } %>
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" target="workFrame" action="sle_search_list.asp" method="get">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") }); %>
<%      SEARCH_BLOCK_START();%>
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="user_key" value="<%=user_key%>">
        <input type="hidden" id="sle_ins_srtdeelstr" value="<%=sle_ins_srtdeelstr%>">
        <input type="hidden" id="cil_ins_srtdeelstr" value="<%=cil_ins_srtdeelstr%>">
<%
        if (fronto)
        { %>
          <input type="hidden" name=free value="">
<%      }
        var label = L("lcl_obj_identification");
        %>
            <!-- groep -->
            <%
            if (sletype == "S") // alleen sleutels
            {
                 var label = L("lcl_sle_sleutel");
                %><input type="hidden" name="sletype" id="sletype_s" value="S"><%
            }
            else if (sletype == "C") // alleen cilinders
            {
                 var label = L("lcl_cil_cilinder");
                %><input type="hidden" name="sletype" id="sletype_c" value="C"><%
            }
            else // toggle
            {
                %><tr><td class="label"></td><td>
<%                  if (authparamsSLEFOF)
                    { %>
                      <label for="sletype_s"><input type="radio" name="sletype" id="sletype_s" value="S" checked="1"><%=L("lcl_sle_sleutels")%></label>
<%                  }
                    if (authparamsSLEBOF)
                    { %>
                      <label for="sletype_c"><input type="radio" name="sletype" id="sletype_c" value="C"><%=L("lcl_cil_cilinders")%></label>
<%                  } %>
                  </td></tr>
<%
            } %>

<%          if (backo)
            { %>
              <!-- Object -->
              <tr class="primsearch">
                <td class="label"><label for="deel"><%=label%></label></td>
                <td><input type="text" class="fldshort" name="deel" value="<%=safe.htmlattr(deel)%>"></td>
              </tr>
<%          }
SEARCH_BLOCK_END();
SEARCH_BLOCK_START();
         if (backo)
            {
              FCLTplaatsselector(authparams.ALGreadlevel,
                                    { locatiekey: loc_key,
                                      gebouwkey: bld_key,
                                      verdiepingkey: flr_key,
                                      ruimtekey: room_key,
                                      werkplekkey: wpl_key, // indien eindlevel 5 is, dan wordt deze parameter niet gebruikt
                                      terrein: true,
                                      onLocChange: "UnSelectOwner()",
                                      onGebChange: "UnSelectOwner()",
                                      onVerChange: "UnSelectOwner()",
                                      onRuiChange: "UnSelectOwner()",
                                      onWerChange: "UnSelectOwner()",
                                      startlevel: 2, // locatie
                                      eindlevel: 5, // ruimte/werkplek
                                      whenEmpty: L("lcl_search_generic"),  // want filter
                                      filtercode: "EXP"
                                    });

              //<!-- Afdeling/Organisatie -->
              FCLTafdelingselector("sDept_key", // organisation
                                   "sgDept",
                                   { departmentKey: dep_key,
                                     label: L("lcl_prs_organisatie"), // Organisatie, is eigenlijk afdeling: dep_name_level2
                                     autlevel: authparams.PRSreadlevel, // Was voorheen niet aanwezig
                                     trclass: "primsearch",
                                     onChange: "UnSelectPos",
                                     whenEmpty: L("lcl_search_generic")  // want filter
                                   });
            }

            //<!-- Persoon -->
            FCLTpersoonselector("sName_key", // requestor
                                "sgPerson",
                                { perslidKey: prs_key,
                                  label: L("lcl_obj_bind_p"),
                                  autlevel: authparams.PRSreadlevel, // Was voorheen niet aanwezig
                                  onChange: (fronto? null : "UnSelectPos"),
                                  trclass: "primsearch",
                                  whenEmpty: L("lcl_search_generic")  // want filter
                                });
%>
<%      SEARCH_BLOCK_END();
        var buttons =  [ {title: L("lcl_overview_list"), action: "doSubmit()", importance: 1, icon: "fa-clipboard-list" } ];
        if (backo)
        {
          buttons.push({title: L("lcl_shared_advanced"), action: "myModal()", id: "bAdvanced", importance: 3, icon: "fa-filter" });
        }
        SIMPLE_BLOCK_START();
        CreateButtons(buttons, { entersubmit: true, showIcons: true} );
        SIMPLE_BLOCK_END();
        SEARCH_PAGE_END();

%>
      </form>

    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload='FcltMgr.iframeLoaded(this)'
              frameborder="0" scrolling="no">
      </iframe>
    </div>

  </body>
</html>
<% ASPPAGE_END(); %>
