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

     File:      res_search.asp

     Parameters:
                  planbord: indien meegegeven (1) dan is het ALLEEN mogelijk planbords op te vragen
                  park:     indien meegegeven (1) dan is het ALLEEN mogelijk parkeerplaatsen op te vragen
                            Dit betekent ook minder selectiemogelijkheden en iets aangepaste terminologie
                            Merk op dat secsearch velden dan bij gebrek aan More knop ook vanzelf onbereikbaar zijn
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="./res.inc" -->

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

/***** Get webform parameters *****/
var urole = getQParamSafe("urole");
var fronto = urole == "fo";
var backo = (urole == "bo");
var minfo = (urole == "mi");
var frontend = (urole == "fe" || (!fronto && !backo && !minfo));

var res_key = getQParamInt("res_key", -1); // reserveringskey
var searchtext = getQParam("searchtext", "");

var planbordonly = getQParamInt("planbord", 0) == 1;
var show_park = getQParamInt("park", 0);

var autoexec = getQParamInt("autoexec", frontend? (planbordonly? 1 : 0) : -1); // 0=ruimte overzicht, 1=ruimte planbord, 2=voorzien planbord
var autostart = getQParamInt("autostart", 1); // 0=niet automatisch starten, &1=automatisch starten

var mld_opdr_key = getQParamInt("mld_opdr_key", -1); // opdracht/resource mode

var srtact = getQParamInt("srtact", -1);
if (srtact > 0)
    lcl.set_dialect(srtact, "RES_SRTACTIVITEIT_KEY");
// else mixed srtact, terugvallen op de default

var list_days = fronto?S("res_fo_list_days"):(frontend?S("res_fe_list_days"):0); // default date offset (in workdays!) for calendar 2
var cal_intv = 0;
// Bepaal einddatum
if (list_days > 0)
{
  sql = "SELECT fac.DatumTijdPlusUitvoerTijd(SYSDATE, " + list_days + ", 'DAGEN') - SYSDATE"
      + " FROM dual";
  oRs = Oracle.Execute(sql);
  cal_intv = oRs(0).Value;
  oRs.close();
}
var date_from = getQParamDate("date_from", null);
var date_to = getQParamDate("date_to", null);

if (minfo)
{
  if (!date_from && date_to)
    date_from = date_to;
  else if (date_from && !date_to)
    date_to = date_from;
  else if (!date_from && !date_to)
  {
    var dt = new Date(); // Vandaag
    dt = new Date(dt.getFullYear(), dt.getMonth(), 1); // Eerste dag van de huidige maand
    date_to = new Date(dt.setDate(0)); // Laatste dag van de vorige maand
    date_from = new Date(dt.setDate(1)); // Eerste dag van de vorige maand
  }
}
else
{
  var today = new Date ();
  var nextday = new Date ();
  if (cal_intv > 0 && (autoexec == -1 || autoexec == 0))
    nextday.setDate(nextday.getDate() + cal_intv);
  else
    nextday = today;
  // Er moet zeker gelden dat date_from < date_to
  var date_from = (!date_from? (date_to && date_to < today? date_to : today) : date_from);
  var date_to = (!date_to? (date_from && date_from > nextday? date_from : nextday) : date_to);
}

var prs_key = getQParamInt("prs_key", -1); // Requestor_key
var host_key = getQParamInt("host_key", -1); // Host_key
var dep_key = getQParamInt("dep_key", -1);
var kp = getQParam("kp", "");
var reg_key = getQParamInt("regio_key", -1); // Regio
var dist_key = getQParamInt("district_key", -1); // District
var loc_key = getQParamInt("locatie_key", -1); // locatie
// Als er geen locatie is meegegeven, dan nemen we voor de FE
// de locatie van de (een) eigen werkplek, om het resultaat
// binnen de perken te houden als de locatie verplicht is
// door vriendelijk alvast de eigen loc in te vullen.
if (loc_key == -1 && frontend && S("res_search_require_locatie") == 1)
    loc_key = user.alg_locatie_key();
var bld_key = getQParamInt("gebouw_key", -1); // gebouw
var floor_key = getQParamInt("verdieping_key", -1); // verdieping
var room_key = getQParamIntArray("ruimte_key", []); // ruimte
var roomcat = (getQParamInt("roomcat", 1) == 1); // Standaard aangevinkt
var objcat = (getQParamInt("objcat", 1) == 1); // Standaard aangevinkt
var artcat = (getQParamInt("artcat", 1) == 1); // Standaard aangevinkt
var suppresscont = (getQParamInt("suppresscont", 0) == 1); // Onderdruk doorlopende reserveringen
var sortout = getQParamInt("sortout", 1); // Sortering, standaard 1
var group = getQParamInt("groupby", -1); // Groepering, standaard -1 (backo), 4 (maninfo)
var alg_startlevel = getQParamInt("alg_startlevel", 2); // Startlevel van plaatsselector (Locatie)
var alg_endlevel = getQParamInt("alg_endlevel", 5); // Endlevel van plaatsselector
var secsearch_alg_level = getQParamInt("secsearch_alg_level", 3); // Endlevel van plaatsselector voor secsearch
var act_key_arr = getQParamKeyArray("act_key", []); // Activiteit
var roomcatalogue_key_arr = getQParamIntArray("roomcatmulti", []); // Ruimte soort catalogus
var obj_key_arr = getQParamIntArray("objcatmulti", []); // Voorzieningen catalogus
var art_key_arr = getQParamIntArray("artcatmulti", []); // Verbruiksartikelen catalogus
var article_arr = getQParamIntArray("art", []); // Verbruiksartikelen
var artgroup = getQParam("artgroup", -1); // Artikelgroep
var sortout = getQParamInt("sortout", -1); // Sortering
var group = getQParamInt("groupby", -1); // Groepering
var resstatus = getQParamInt("resstatus", -1); // fo_status
var resourcetypes = getQParamIntArray("resourcetypes", [1, 2, 3]);
var alleen_personen = resourcetypes.length == 1 && resourcetypes[0] == 4;

var res_actual = getQParamInt("res_actual", 1) == 1; // Standaard aangevinkt indien niet meegegeven
var res_deleted = getQParamInt("res_deleted", 0) == 1; // Standaard niet aangevinkt indien niet meegegeven
// minimaal één van beiden moet aangekruist zijn
if (!res_actual && !res_deleted)
  res_actual = true;

var res_open      = (getQParamInt("res_open", 1) == 1);                // Standaard aangevinkt indien niet meegegeven
var res_finished  = (getQParamInt("res_finished", (minfo? 1 : 0)) == 1); // Standaard niet aangevinkt indien niet meegegeven, behalve voor minfo
var res_closed    = (getQParamInt("res_closed", (minfo? 1 : 0)) == 1); // Standaard niet aangevinkt indien niet meegegeven, behalve voor minfo
// minimaal één van beiden moet aangekruist zijn (dit wordt op veel te veel plekken gecheckt)
if (!res_open && !res_finished && !res_closed)
  res_open = true;

var res_approved     = (getQParamInt("res_approved",     (frontend?0:1)) == 1); // Standaard aangevinkt (frontend uit).
var res_notapproved  = (getQParamInt("res_notapproved",  1) == 1);              // Standaard aangevinkt.
var res_tobeapproved = (getQParamInt("res_tobeapproved", (frontend?0:1)) == 1); // Standaard aangevinkt (frontend uit).
// minimaal één van beiden moet aangekruist zijn
if (!res_approved && !res_notapproved)
  res_approved = true;

var show_activity_selector = true;

/***** End get webform parameters *****/

var autfunction = "";
switch(urole)
{
  case "fe": autfunction = "WEB_RESUSE";
             break;
  case "fo": autfunction = "WEB_RESFOF";
             break;
  case "bo": autfunction = "WEB_RESBOF";
             break;
  case "mi": autfunction = "WEB_RESBAC";
             break;
}

// De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
var authparams = user.checkAutorisation(autfunction);

var initcollapsed = getQParamInt("initcollapsed", 0);
var collapseThreshold = getQParamInt("collapsethreshold", 0); // klap automatisch open als er maximaal zoveel regels zijn.

// Heeft deze CUST res_ruimte?
var sql = "SELECT COUNT(*) aantal"
        + "  FROM res_ruimte"
        + " WHERE res_ruimte_verwijder IS NULL";
var oRs = Oracle.Execute(sql);
var hasResruimte = (oRs("aantal").Value > 0);
oRs.Close();

%>

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

    <script type="text/javascript">
    var __mode = -1;
      async function doSubmit(mode) // 0=lijst, 1=planbord, 2=objplanbord, 3=planbord as css grid
      {
        if (isNaN(parseInt($("input[name=resnum]").val(), 10)) && !await validateForm("u2"))
            return false;

        __mode = mode;
        document.u2.action= {0:"res_search_list.asp?urole=<%=urole%>&user_key=<%=user_key%>",
                             1:"res_search_plan_room_v2.asp?urole=<%=urole%>&user_key=<%=user_key%>&width_px=" + $(window).width() + "&initcollapsed=<%=initcollapsed%>&collapsethreshold=<%=collapseThreshold%>",
                             2:"res_search_plan_obj_v2.asp?urole=<%=urole%>&user_key=<%=user_key%>&width_px=" + $(window).width()
                            }[mode]

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

<%    if (!frontend)
      { %>
        async function myModal(init)
        {
          var key = $('#act').val();
          var url = "load_kenmerk.asp?act_key_arr=" + key
                  + "&urole=<%=urole%>"
                  + "&advanced=1"
                  + "&hasFilter=1";
          var titel = L("lcl_res_kenmerken");
          await showKenmerkModal(url, titel, init)
        }
<%    }
    if (autoexec >= 0) { %>
        window.afterfiltersready = function ()
            {
                if (<%=autostart%> & 1 == 1)
                {
<%                  // autoexec -> 0=ruimte overzicht, 1=ruimte planbord, 2=voorzien planbord
                    // mode -> 0=lijst, 1=planbord (new), 2=objplanbord (new)
                    var mode;
                    switch (autoexec) {
                        case 1:
                        case 3: // MGE: Komt deze waarde van autoexec wel voor? Volgens de omschrijving hierboven niet.
                            mode = 1;
                            break;
                        case 2:
                        case 4: // MGE: Komt deze waarde van autoexec wel voor? Volgens de omschrijving hierboven niet.
                            mode = 2;
                            break;
                        default:
                            mode = 0;
                            break;
                    } %>
                    doSubmit(<%=mode%>);
                }
            };
<% } %>
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" action="res_search_list.asp" target="workFrame" method="post">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
       SEARCH_BLOCK_START(); %>
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="srtact" value="<%=srtact%>">
        <input type="hidden" name="park" value="<%=show_park%>">
        <input type="hidden" name="mld_opdr_key" value="<%=mld_opdr_key%>">
        <input type="hidden" name="resourcetypes" value="<%=resourcetypes%>">
        <input type="hidden" name="fnStep" value="1"> <!-- 1 = "parent.fnStepPlanbord" -->
        <input type="hidden" name="autosearch" id="autosearch" value="0">
        <input type="hidden" name="sort" id="sort" value="">
      <%

      if (frontend && planbordonly && autoexec==2)
      { // Dus alleen als direct voorzieningenplanbord aangeroepen wordt.
        if (obj_key_arr.length > 0)
        { // Disciplines die met parameter objcatmulti zijn meegegeven plus die bepaald uit de activiteiten die behoren bij srtact.
          show_activity_selector = false; // Als er vaste catalogi worden meegegeven, dan wegen die zwaarder dan een activiteit
%>        <input type="hidden" name="objcatmulti" id="objcatmulti" value="<%=obj_key_arr.join(",")%>">
<%      }
      }

      // <!-- Datum van -->
        FCLTcalendar("date_from",
                     { label : (frontend ? L("lcl_date") :L("lcl_period_from")),
                       datum: date_from,
                       trclass: "primsearch",
                       volgnr: 1
                     });
        // <!-- Datum tot -->
        FCLTcalendar("date_to",
                     { label: L("lcl_period_to"),
                       datum: date_to,
                       trclass: "primsearch",
                       volgnr: 2
                     });

        if (backo || minfo)
        { %>
          <!-- Checkboxen ruimten, voorzieningen en verbruiksartikelen -->
          <tr class="secsearch">
            <td class="label"></td>
            <td>
              <input type="checkbox" class="fldsuppresscont" name="suppresscont" id="suppresscont" value="1" <%=suppresscont? "checked" : ""%>>
              <label for="suppresscont"><%=L("lcl_res_suppress_cont")%></label>
            </td>
          </tr>
<%          }

        if (show_activity_selector) {
          // Activiteit
          var sql_aut = "SELECT rad.res_activiteit_key"
                      + "  FROM fac_v_webgebruiker fw"
                      + "     , fac_functie fwf"
                      + "     , res_activiteitdiscipline rad"
                      + " WHERE fw.fac_functie_key = fwf.fac_functie_key"
                      + "   AND fwf.fac_functie_code = " + safe.quoted_sql(autfunction)
                      + "   AND fw.prs_perslid_key = " + user_key
                      + "   AND rad.res_discipline_key = fw.ins_discipline_key";
          sql = "SELECT a.res_activiteit_key, "
              + "CASE WHEN sa.res_srtactiviteit_prefix IS NULL"
                + "     THEN ''"
                + "     ELSE sa.res_srtactiviteit_prefix || '-'"
                + "     END"
                + "|| "+ lcl.xsqla("a.res_activiteit_omschrijving", "a.res_activiteit_key")
              + "  FROM res_activiteit a, res_srtactiviteit sa"
              + " WHERE a.res_srtactiviteit_key = sa.res_srtactiviteit_key"
              + "   AND a.res_activiteit_key IN (" + sql_aut + ")"
              + "   AND res_activiteit_verwijder IS NULL"
              + (srtact>0?" AND a.res_srtactiviteit_key="+srtact:"")
              + " ORDER BY res_activiteit_volgnr, sa.res_srtactiviteit_prefix, UPPER("+ lcl.xsql('a.res_activiteit_omschrijving', 'a.res_activiteit_key')+")";
          FCLTselector("act",
                       sql,
                       {
                         initKey: act_key_arr.length > 0 ? act_key_arr.join(",") : "-1", // Indien geen waarde meegegeven dan "Alles" selecteren (key = -1).
                         label: L("lcl_activity"),
                         trclass: "primsearch",
                         multi: true,
                         emptyOption: L("lcl_search_generic")
                       });
        }

        // Locatie, gebouw, verdieping en ruimte
        if (!alleen_personen)
        {
          FCLTplaatsselector(authparams.ALGreadlevel, { regiokey: reg_key,
                                                        districtkey: dist_key,
                                                        locatiekey: loc_key,
                                                        gebouwkey: bld_key,
                                                        verdiepingkey: floor_key,
                                                        ruimtekey: room_key,
                                                        multitoggle: 5,
                                                        startlevel: alg_startlevel,
                                                        eindlevel: alg_endlevel,
                                                        secsearch: secsearch_alg_level, // hoger dan gebouw
                                                        filtercode: "FAC",
                                                        requiredlevel: (S("res_search_require_locatie")==1 ? 2 : null),
                                                        whenEmpty: L("lcl_search_generic")  // want filter
                                                      });
        }

        if (!show_park && autoexec != 2 && inArray(3, resourcetypes) && hasResruimte)
        {
          //<!-- Ruimte soort -->
          sql = "SELECT rd.ins_discipline_key dis_key"
                  + ", "+ lcl.xsql('rd.ins_discipline_omschrijving','rd.ins_discipline_key') +" omschrijving"
                  + " FROM res_v_aanwezigdiscipline rd"
                  + ", fac_v_webgebruiker fw"
                  + ", fac_functie fwf"
                  + " WHERE rd.ins_discipline_min_level = 3"
                  + " AND fw.ins_discipline_key = rd.ins_discipline_key"
                  + " AND fw.fac_functie_key = fwf.fac_functie_key"
                  + " AND fwf.fac_functie_code = " + safe.quoted_sql(autfunction)
                  + " AND fw.prs_perslid_key = " + user_key
                  + " ORDER BY ins_discipline_volgnr, 2";
            FCLTselector("roomcatmulti",
                         sql,
                         { initKey: roomcatalogue_key_arr.length? roomcatalogue_key_arr.join(",") : "-1", // Indien geen waarde meegegeven dan "Alles" selecteren (key = -1).
                           label: L("lcl_res_roomcat"),
                           trclass: "primsearch",
                           multi: true,
                           emptyOption: L("lcl_search_generic")
                         });
        }

        if (backo || minfo)
        {
          //<!-- Sortering -->
          sql = "SELECT 1, " + safe.qL("lcl_location") + "||', '||" + safe.qL("lcl_time") + ", 1 FROM DUAL"
                + " UNION SELECT 5, " + safe.qL("lcl_time") + ", 2 FROM DUAL"
                + " UNION SELECT 2, " + safe.qL("lcl_place") + ", 3 FROM DUAL"
                + " UNION SELECT 3, " + safe.qL("lcl_reservation") + ", 4 FROM DUAL"
                + " UNION SELECT 4, " + safe.qL("lcl_host") + ", 5 FROM DUAL"
                + " ORDER BY 3";
            FCLTselector("sortout",
                         sql,
                         { initKey: sortout,
                           label: L("lcl_res_sort"),
                           trclass: "secsearch"
                         });

            CHECKBOXTR(L("lcl_res_no_show"), "fldresnoshowonly", "res_noshowonly", false, { trclass: "secsearch"});
          %>
          <tr class="primsearch">
            <td class="label"><label><%=L("lcl_show")%></label></td>
            <td>
              <input type="checkbox" class="fldroomcat" name="roomcat" id="roomcat" onClick="checkCheckboxes()" value="1" <%=roomcat? "checked" : ""%>>
              <label for="roomcat"><%=L("lcl_show_rooms")%></label>
              <input type="checkbox" class="fldobjcat" name="objcat" id="objcat" onClick="checkCheckboxes()" value="1" <%=objcat? "checked" : ""%>>
              <label for="objcat"><%=L("lcl_reserved_object")%></label>
              <input type="checkbox" class="fldartcat" name="artcat" id="artcat" onClick="checkCheckboxes()" value="1" <%=artcat? "checked" : ""%>>
              <label for="artcat"><%=L("lcl_reserved_cons")%></label>
            </td>
          </tr>
          <%
        } // backo || minfo

        // <!-- Groepering -->
        var initGroup = -1;
        if (!minfo)
        {
          sql = "       SELECT -1, " + safe.qL("lcl_res_group_none")        + ", 1 FROM DUAL"
              + " UNION SELECT  1, " + safe.qL("lcl_res_group_reservation") + ", 2 FROM DUAL"
              + " ORDER BY 3";
          if (fronto)
            initGroup = 1;
        }
        else
        {
          sql = "       SELECT  4, " + safe.qL("lcl_res_group_none")    + ",  1 FROM DUAL"
              + " UNION SELECT  5, " + safe.qL("lcl_district")          + ",  2 FROM DUAL"
              + " UNION SELECT  6, " + safe.qL("lcl_mi_location")       + ",  3 FROM DUAL"
              + " UNION SELECT 10, " + safe.qL("lcl_building")          + ",  4 FROM DUAL"
              + " UNION SELECT  7, " + safe.qL("lcl_res_article")       + ",  5 FROM DUAL"
              + " UNION SELECT  8, " + safe.qL("lcl_res_art_number")    + ",  6 FROM DUAL"
              + " UNION SELECT 15, " + safe.qL("lcl_res_catalogus")     + ",  7 FROM DUAL"
              + " UNION SELECT 14, " + safe.qL("lcl_department")
                       + "||' + '||" + safe.qL("lcl_account")           + ",  8 FROM DUAL"
              + " UNION SELECT 12, " + safe.qL("lcl_charge_type")       + ",  9 FROM DUAL"
              + " UNION SELECT 13, " + safe.qL("lcl_charge_type_group") + ", 10 FROM DUAL"
              + " UNION SELECT  9, " + safe.qL("lcl_account")           + ", 11 FROM DUAL"
              + " UNION SELECT 11, " + safe.qL("lcl_activity")          + ", 12 FROM DUAL"
              + " UNION SELECT  1, " + safe.qL("lcl_reservation")       + ", 13 FROM DUAL"
              + " ORDER BY 3";
          initGroup = 4;
        }
        FCLTselector("groupby",
                     sql,
                     { initKey: group > 0? group : initGroup,
                       label: L("lcl_res_group"),
                       trclass: "primsearch"
                     });

        if (S("res_reservering_flags") > 1 && !frontend) // Flags checkboxen -->
        {
            for (flagkey=0; flagkey < S("res_reservering_flags"); flagkey++)
            {
                var label = "<label for='flag" + flagkey + "'>"
                          + "  <span class='resflag" + flagkey + " ress'>"
                          +      I("fa-fclt-flag" + (flagkey == 0 ? "0" : ""))
                          + "  </span> " + safe.html(L("lcl_res_flag" + flagkey))
                          + "</label>";
                RWCHECKBOXTR("flag" + flagkey, "fldcheck", (flagkey == 0 ? L("lcl_res_flags") : ""), 1, { twocols: true, posthtml: label });
            }
        }
        SEARCH_BLOCK_END();
        // Start responsive search_column 2
        SEARCH_BLOCK_START();
%>
        <!-- Reservation number -->
        <tr class="primsearch">
          <td class="label"><label for="resnum"><%=L("lcl_res_number")%></label></td>
          <td><input type="text" class="fldshort" name="resnum" id="resnum" value="<%=res_key > 0? res_key : ""%>"></td>
        </tr>
        <tr class="primsearch">
          <!-- Description/remark -->
          <td class="label"><label for="searchtext"><%=L("lcl_search_diff_fields")%></label></td>
          <td>
            <input type="text" class="fld wildcard" id="searchtext" name="searchtext" value="<%=safe.htmlattr(searchtext)%>">
          </td>
        </tr>

        <!-- Aanvrager -->
<%          if (!frontend)
        {
              FCLTpersoonselector("sName_key",
                                  "sgPerson",
                                  { perslidKey: prs_key,
                                    label: L("lcl_res_requestor"),
                                    filtercode: "RESR",
                                    trclass: "primsearch",
                                    autlevel: authparams.PRSreadlevel,
                                    whenEmpty: L("lcl_search_generic")  // want filter
                                  });

        }

        // <!-- Gastheer -->
        if (!frontend || (frontend && S("res_allow_for_others")==1))
        {
            FCLTpersoonselector("sHost_key",
                                "sgHost",
                                { perslidKey: host_key,
                                  label: L("lcl_host"),
                                  filtercode: "RESH",
                                  trclass: "primsearch",
                                  autlevel: authparams.PRSreadlevel,
                                  whenEmpty: L("lcl_search_generic")  // want filter
                                  });

        }
        // <!-- Organisatie -->
        if (!frontend)
        {
            FCLTafdelingselector("sDept_key",
                                 "sgDept",
                                 { departmentKey: dep_key,
                                   label: L("lcl_department"),
                                   autlevel: authparams.PRSreadlevel,
                                   trclass: "secsearch",
                                   whenEmpty: L("lcl_search_generic")  // want filter
                                 });

        } // fronto || minfo

        // <!-- Kostenplaats -->
        if (minfo)
        { %>
          <tr class="secsearch">
            <td class="label"><label for="kp"><%=L("lcl_res_account")%></label></td>
            <td><input type="text" class="fld wildcard" name="kp" id="kp" value="<%=safe.htmlattr(kp)%>"></td>
          </tr>
<%          } // minfo

        if (!frontend && (inArray(1, resourcetypes) || inArray(5, resourcetypes)))
        {
            var sql_ins_disc_min_level_arr = [];
            if (inArray(1, resourcetypes)) sql_ins_disc_min_level_arr.push(1);
            if (inArray(5, resourcetypes)) sql_ins_disc_min_level_arr.push(5);

            // Voorzieningen
            sql = "SELECT rd.ins_discipline_key dis_key"
                + ", "+ lcl.xsql('rd.ins_discipline_omschrijving','rd.ins_discipline_key') +" omschrijving"
                + " FROM res_v_aanwezigdiscipline rd"
                + ", fac_v_webgebruiker fw"
                + ", fac_functie fwf"
                + " WHERE rd.ins_discipline_min_level IN (" + sql_ins_disc_min_level_arr.join(", ") + ")"
                + " AND fw.ins_discipline_key = rd.ins_discipline_key"
                + " AND fw.fac_functie_key = fwf.fac_functie_key"
                + " AND fwf.fac_functie_code = " + safe.quoted_sql(autfunction)
                + " AND fw.prs_perslid_key = " + user_key
                + " ORDER BY ins_discipline_volgnr, 2";
            FCLTselector("objcatmulti",
                         sql,
                         { initKey: obj_key_arr.length? obj_key_arr.join(",") : "-1", // Indien geen waarde meegegeven dan "Alles" selecteren (key = -1).
                           label: L("lcl_res_objcat"),
                           multi: true,
                           trclass: "primsearch",
                           emptyOption: L("lcl_search_generic")
                         });
        }

        if (!frontend && inArray(2, resourcetypes))
        {
            // Verbruiksartikelen
            sql = "SELECT rd.ins_discipline_key dis_key"
                + ", "+ lcl.xsql('rd.ins_discipline_omschrijving','rd.ins_discipline_key') +" omschrijving"
                + " FROM res_v_aanwezigdiscipline rd"
                + ", fac_v_webgebruiker fw"
                + ", fac_functie fwf"
                + " WHERE rd.ins_discipline_min_level = 2"
                + " AND fw.ins_discipline_key = rd.ins_discipline_key"
                + " AND fw.fac_functie_key = fwf.fac_functie_key"
                + " AND fwf.fac_functie_code = " + safe.quoted_sql(autfunction)
                + " AND fw.prs_perslid_key = " + user_key
                + " ORDER BY ins_discipline_volgnr, 2";
            FCLTselector("artcatmulti",
                         sql,
                         { initKey: art_key_arr.length? art_key_arr.join(",") : "-1", // Indien geen waarde meegegeven dan "Alles" selecteren (key = -1).
                           label: L("lcl_res_artcat"),
                           onChange: 'updateArt("' + autfunction + '");',
                           multi: true,
                           trclass: (fronto ? "secsearch" : "primsearch"),
                           emptyOption: L("lcl_search_generic")
                         });

          if (!fronto && inArray(2, resourcetypes)) // niet interessant
          {
            // Artikelen
%>              <tr class="secsearch">
            <td class="label"><label for="artmulti"><%=L("lcl_res_art")%></label></td>
            <td>
              <div id="selectartdiv">
<%                  var sql_aut = " SELECT rd.ins_discipline_key ins_discipline_key"
                            + " FROM res_v_aanwezigdiscipline rd"
                            + ", fac_v_webgebruiker fw"
                            + ", fac_functie fwf"
                            + " WHERE rd.ins_discipline_min_level = 2"
                            + " AND fw.ins_discipline_key = rd.ins_discipline_key"
                            + " AND fw.fac_functie_key = fwf.fac_functie_key"
                            + " AND fwf.fac_functie_code = " + safe.quoted_sql(autfunction)
                            + " AND fw.prs_perslid_key = " + user_key;

                sql = "SELECT DISTINCT a.res_artikel_key"
                    + ", " + lcl.xsql('a.res_artikel_omschrijving', 'a.res_artikel_key')
                      + " || CASE"
                        + " WHEN (a.res_artikel_ingangsdatum IS NULL OR a.res_artikel_ingangsdatum <= SYSDATE) AND (a.res_artikel_vervaldatum IS NULL OR a.res_artikel_vervaldatum > SYSDATE) "
                        + " THEN ''"
                        + " ELSE " + safe.quoted_sql(L("lcl_inactive_data_suffix")) // Standaard suffix achter de omschrijving indien inactief artikel
                        + " END res_artikel_omschrijving"
                    + " FROM res_v_aanwezigartikel a"
                    + " WHERE a.res_discipline_key IN (" + sql_aut + ")"
                    // Zijn er alleen verbruiksartikelen catalogussen geselecteerd
                    + (art_key_arr.length
                      ? " AND a.res_discipline_key IN (" + art_key_arr.join(",") + ")"
                      : "")
                    + " ORDER BY 2";

                FCLTselector("artmulti",
                             sql, // sql: lege selectbox die onload wordt geladen
                             { initKey: article_arr.length? article_arr.join(",") : "-1", // Indien geen waarde meegegeven dan "Alles" selecteren (key = -1).
                               multi: true,
                               trclass: "secsearch",
                               emptyOption: L("lcl_search_generic")
                             });
%>
              </div>
            </td>
          </tr>

<%             //<!-- Artikel groep -->

            sql = "SELECT DISTINCT ra.res_artikel_groep"
                + ", ra.res_artikel_groep"
                + " FROM res_artikel ra"
                + " WHERE ra.res_artikel_groep IS NOT NULL"
                + " AND ra.res_artikel_verwijder IS NULL"
                + " ORDER BY 1";
            FCLTselector("artgroup",
                         sql,
                         { initKey: artgroup,
                           label: L("lcl_res_art_group"),
                           multi: true,
                           trclass: "secsearch",
                           emptyOption: L("lcl_search_generic"),
                           initEmpty: true // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                         });
        } // !fronto
    } // !frontend
    // Reserveringstatus
    sql = "SELECT         1, " + safe.quoted_sql(res.getfostatustext(1)) + " FROM DUAL"
        + " UNION SELECT  2, " + safe.quoted_sql(res.getfostatustext(2)) + " FROM DUAL"
        + " UNION SELECT  3, " + safe.quoted_sql(res.getfostatustext(3)) + " FROM DUAL"
        + " UNION SELECT  4, " + safe.quoted_sql(res.getfostatustext(4)) + " FROM DUAL"
        + " ORDER BY 1";  // statusvolgorde is logischer dan alfabetisch
    FCLTselector("resstatus",
                 sql,
                 { initKey: resstatus,
                   label: L("lcl_status_FO"),
                   trclass: "primsearch",
                   emptyOption: ""
                 });

        // Actuele en verwijderde reserveringen
        if (fronto)
        {
%>
              <tr class="secsearch">
                 <td class="label">
                   <input type="checkbox" class="fldresactual" id="res_actual" name="res_actual" value="1" <%=res_actual? "checked" : ""%>>
                 </td>
                 <td>
                   <label for="res_actual"><%=L("lcl_res_show_actual")%></label>
                 </td>
              </tr>
              <tr class="secsearch">
                <td class="label">
                  <input type="checkbox" class="fldresdeleted" id="res_deleted" name="res_deleted" value="1" <%=res_deleted? "checked" : ""%>>
                </td>
                <td>
                  <label for="res_deleted"><%=L("lcl_res_show_deleted")%></label>
                </td>
              </tr>
<%          } // !fronto
%>

            <!-- Open en gesloten reserveringen -->
<%          if (backo || minfo)
            {
%>
              <!-- Checkboxen ruimten, voorzieningen en verbruiksartikelen -->
              <tr class="primsearch">
                <td></td>
                <td align="left">
                  <input type="checkbox" class="fldresopen" name="res_open" id="res_open" onClick="checkCheckboxes();" value="1" <%=res_open? "checked" : ""%>>
                  <label for="res_open"><%=L("lcl_open_reservations")%></label>
                  <input type="checkbox" class="fldresfinished" name="res_finished" id="res_finished" onClick="checkCheckboxes();" value="1" <%=res_finished? "checked" : ""%>>
                  <label for="res_finished"><%=L("lcl_finished_reservations")%></label>
                  <input type="checkbox" class="fldresclosed" name="res_closed" id="res_closed" onClick="checkCheckboxes();" value="1" <%=res_closed? "checked" : ""%>>
                  <label for="res_closed"><%=L("lcl_closed_reservations")%></label>
                </td>
              </tr>
<%
            }
            if ((S("res_approval") > 0) && (backo || minfo || frontend))
            {
%>
              <tr class="primsearch">
                <td class="label"><label><%=L("lcl_res_approval")%></label></td>
                <td align="left">
<%
              if (backo || minfo)
              {
%>
                    <input type="checkbox" class="fldresnotapproved" name="res_notapproved" id="res_notapproved" onClick="checkCheckboxes();" value="1" <%=res_notapproved? "checked" : ""%>>
                    <label for="res_notapproved"><%=L("lcl_res_notapproved")%></label>
<%            }
              if (frontend)
              {
%>
                    <input type="checkbox" class="fldresnotapproved" name="res_tobeapproved" id="res_tobeapproved" onClick="checkCheckboxes();" value="1" <%=res_tobeapproved? "checked" : ""%>>
                    <label for="res_tobeapproved"><%=L("lcl_res_tobeapproved")%></label>
<%
              }
              if (backo || minfo || frontend)
              {
%>
                    <input type="checkbox" class="fldresapproved" name="res_approved" id="res_approved" onClick="checkCheckboxes();" value="1" <%=res_approved? "checked" : ""%>>
                    <label for="res_approved"><%=L("lcl_res_approved")%></label>
<%
              }
%>
                </td>
              </tr>
<%
            } // !fronto

        SEARCH_BLOCK_END();

        var buttons =  [];
        if (!planbordonly) // niet alleen planbord
          buttons.push ( {title: L("lcl_overview_list"),  action: "doSubmit(0)", importance: 1, icon: "fa-clipboard-list" } );   // Overzicht
        if (inArray(3, resourcetypes))
          buttons.push ( {title: L("lcl_planboard"),  action: "$('#autosearch').val(0);doSubmit(1)", importance: 1, icon: "fa-calendar-day" } );
        if (!backo && autoexec != 1)
          buttons.push ( {title: (show_park ? L("lcl_planboard")+" "+L("lcl_park") : L("lcl_reserved_object_planboard")),  action: "doSubmit(2)", importance: 1, icon: "fa-calendar-alt"} );
        if (!show_park)
          buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess", importance: 3, icon: "fa-chevron-right" } );
        if (!frontend && !show_park)
          buttons.push ( {title: L("lcl_shared_advanced"),  action: "myModal()", 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, {widthToo: __mode == 1 || __mode == 2});"
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html>
<% ASPPAGE_END(); %>
