<%@ 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 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 gegeven, dan nemen we voor de FE
// de locatie van de (een) eigen werkplek, om het resultaat
// binnen de perken te houden (dat doen we door loc verplicht te stellen)
// en vriendelijk alvast de eigen loc in te vullen.
if (loc_key == -1 && frontend)
    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 = getQParamInt("ruimte_key", -1); // 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 act = getQParamInt("act_key", -1); // Activiteit
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", frontend?2:5); // Endlevel van plaatsselector
var room_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 = getQParamInt("artgroup", -1); // Artikelgroep
var sortout = getQParamInt("sortout", -1); // Sortering
var group = getQParamInt("groupby", -1); // Groepering
var resstatus = getQParamInt("resstatus", -1); // fo_status

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 = (getFParamInt("res_open", 1) == 1); // Standaard aangevinkt indien niet meegegeven
var res_closed = (getFParamInt("res_closed", (minfo? 1 : 0)) == 1); // Standaard niet aangevinkt indien niet meegegeven, behalve voor minfo
// minimaal één van beiden moet aangekruist zijn
if (!res_open && !res_closed)
  res_open = true;

var res_approved = getFParamInt("res_approved", 1); // Standaard aangevinkt.
var res_notapproved = getFParamInt("res_notapproved", 1); // Standaard aangevinkt.
// minimaal één van beiden moet aangekruist zijn
if (!res_approved && !res_notapproved)
  res_approved = 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);
%>

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

    <script type="text/javascript">
      var __mode = -1;
      function doSubmit(mode) // 0=lijst, 1=planbord, 2=objplanbord
      {
        if (isNaN(parseInt($("input[name=resnum]").val(), 10)) && !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.asp?urole=<%=urole%>&user_key=<%=user_key%>&width_px=" + $(window).width(),
                             2:"res_search_plan_obj.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 && ! fronto)
      { %>
        function myModal()
        {
          if ($('#act').val() == -1)
          {
            alert(L("lcl_res_select_activity"));
            return;
          }

          var key = $('#act').val();
          var url = "load_kenmerk.asp?act_key=" + $('#act').val()
                  + "&urole=<%=urole%>"
                  + "&advanced=1";
          var titel = "<%=L("lcl_res_kenmerken")%>";
          showKenmerkModal(url, titel)
        }
<%    }
    if (autoexec>=0) { %>
        $(document).ready(function() {doSubmit(<%=autoexec%>)});

<% } %>
    </script>
  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" action="res_search_list.asp" target="workFrame" method="post">
        <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="fnStep" value="parent.fnStepPlanbord">
        <input type="hidden" name="autosearch" id="autosearch" value="0">
<%
      if (frontend && planbordonly && autoexec==2)
      { // Dus alleen als direct voorzieningenplanbord aangeroepen wordt.
        if (act > -1)
        {
%>        <input type="hidden" name="act" id="act" value="<%=act%>">  <%
        }
        if (srtact > -1)
        {
          var sql = "SELECT distinct ad.res_discipline_key"
                  + "  FROM res_activiteitdiscipline ad"
                  + "     , res_activiteit ra"
                  + " WHERE ad.res_activiteit_key = ra.res_activiteit_key"
                  + "   AND ra.res_srtactiviteit_key = " + srtact;
          if (act > -1)
            sql += " AND ra.res_activiteit_key = " + act;
          var oRs = Oracle.Execute(sql);
          while (!oRs.eof)
          {
            obj_key_arr.push(oRs("res_discipline_key").Value);
            oRs.MoveNext();
          }
          oRs.Close();
        }

        if (obj_key_arr.length > 0)
        { // Disciplines die met parameter objcatmulti zijn meegegeven plus die bepaald uit de activiteiten die behoren bij srtact.
%>        <input type="hidden" name="objcatmulti" id="objcatmulti" value="<%=obj_key_arr.join(",")%>">  <%
        }
      }

      BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1"><!-- start column 1 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <!-- Reservation number -->
            <tr class="primsearch">
              <td class="label"><label for="resnum"><%=L("lcl_res_number")%>:</label></td>
              <td><input type="text" class="fldresnum" name="resnum" value="<%=res_key > 0? res_key : ""%>"></td>
            </tr>

<%          // <!-- 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>
<%          }
            // <!-- Locatie, gebouw, verdieping en ruimte -->
            FCLTplaatsselector(authparams.ALGreadlevel, { regiokey: reg_key,
                                                          districtkey: dist_key,
                                                          locatiekey: loc_key,
                                                          gebouwkey: bld_key,
                                                          verdiepingkey: floor_key,
                                                          ruimtekey: room_key,
                                                          startlevel: alg_startlevel,
                                                          eindlevel: alg_endlevel,
                                                          secsearch: frontend?null:3, // hoger dan gebouw
                                                          filtercode: "FAC",
                                                          requiredlevel: (S("res_search_require_locatie")==1 ? 2 : null),
                                                          whenEmpty: L("lcl_search_generic")  // want filter
                                                        });
            // <!-- Reserveringstatus -->
            //if (!frontend)
            {
              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 2";
              FCLTselector("resstatus",
                           sql,
                           { initKey: resstatus,
                             label: L("lcl_status_FO"),
                             trclass: "primsearch",
                             emptyOption: ""
                           });

              //<!-- Activiteit -->
              sql = "SELECT 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 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,
                             label: L("lcl_activity"),
                             emptyOption: "",
                             selectjustone: true,
                             trclass: "primsearch"
                           });
            } // !frontend

            if (backo || minfo)
            { %>
            
<%            if (!frontend && ! fronto)
              {
                //<!-- 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"
                               });
              }

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

                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

            if (S("res_reservering_flags") > 1 && !frontend) // Flags checkboxen -->
            {
%>
              <tr>
                <td class="label"><label><%=L("lcl_res_flags")%>:&nbsp;</label></td>
                <td>
<%                  // Vlag0 heeft dezelfde betekenis als 'geen vlag' en krijgt geen vinkje
                    for (flagkey=1; flagkey < S("res_reservering_flags"); flagkey++)
                    {
%>
                        <label for="flag<%=flagkey%>" title='<%=safe.htmlattr(L("lcl_res_flag"+flagkey))%>'><input type="checkbox" name="flag<%=flagkey%>"><img src='../Pictures/resflag<%=flagkey%>.png'></label>
<%
                    }
%>
                </td>
              </tr>
<%
            }
%>
            </table>
            <!-- end column 1 -->
          </td>

          <td class="searchkolom2"><!-- start column 2 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <tr class="primsearch">
              <!-- Description/remark -->
              <td class="label"><label for="searchtext"><%=L("lcl_search_diff_fields")%>:</label></td>
              <td>
                <input type="text" class="fldsrch" 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 (S("res_allow_for_others")==1 && (fronto || frontend))  // HSUM#19233
            {
                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 (fronto || minfo)
            {
                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="fldkp" name="kp" value="<%=safe.htmlattr(kp)%>"></td>
              </tr>
              <tr><td height="10"></td></tr>
<%          } // minfo

            if (!show_park && autoexec != 2)
            {
              //<!-- 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_v_webfunctie 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: room_key_arr.length? room_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_all")
                             });
            }
            if (backo || minfo)
            {
              // <!-- 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_v_webfunctie fwf"
                    + " WHERE rd.ins_discipline_min_level=1"
                    + " 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: "secsearch",
                               emptyOption: L("lcl_all")
                             });

              // <!-- 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_v_webfunctie 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,
                               xtrclass: "secsearch",
                               emptyOption: L("lcl_all")
                             });

              // <!-- Artikelen -->
%>              <tr class="secsearch">
                <td class="label"><label for="art"><%=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_v_webfunctie 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_all")
                                 });
%>
                  </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_all"),
                               initEmpty: true // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                             });
            } // backo || minfo
%>
            <!-- 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="open"><%=L("lcl_open_reservations")%></label>
                  <input type="checkbox" class="fldresclosed" name="res_closed" id="res_closed" onClick="checkCheckboxes();" value="1" <%=res_closed? "checked" : ""%>>
                  <label for="closed"><%=L("lcl_closed_reservations")%></label>
                </td>
              </tr>
<%            if (S("res_approval") > 0)
              { %>
              <tr class="primsearch">
                <td></td>
                <td align=left>
                    <input type="checkbox" class="fldresnotapproved" name="res_notapproved" id="res_notapproved" onClick="checkCheckboxes();" value="1" <%=res_notapproved? "checked" : ""%>>
                    <label for="closed"><%=L("lcl_res_notapproved")%></label>
                    <input type="checkbox" class="fldresapproved" name="res_approved" id="res_approved" onClick="checkCheckboxes();" value="1" <%=res_approved? "checked" : ""%>>
                    <label for="closed"><%=L("lcl_res_approved")%></label>
                </td>
              </tr>
<%            } %>
<%          } // !fronto
%>
            </table>
          </td>

        </tr>
<%
      BLOCK_END();
        var buttons =  [];
        if (!planbordonly) // niet alleen planbord
          buttons.push ( {title: L("lcl_overview_list"),  action: "doSubmit(0)" } );   // Overzicht
        if (!show_park && autoexec != 2)  // PF: van mij mag backo ook best planbord zien?
          buttons.push ( {title: L("lcl_planboard"),  action: "$('#autosearch').val(0);doSubmit(1)" } );
        if (!backo && autoexec != 1)
          buttons.push ( {title: show_park ? L("lcl_planboard") : L("lcl_reserved_object_planboard"),  action: "doSubmit(2)" } );
        if (!frontend && !show_park)
        {
          buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess" } );
          if (!fronto) { // Geavanceerd vereist een activiteit, en die hebben alleen bo en mi
            buttons.push ( {title: L("lcl_obj_advanced"),  action: "myModal()" } );
          }
        }
        CreateButtons(buttons, { entersubmit: true} );
%>
      </form>
    </div> <!-- search -->

    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload="FcltMgr.iframeLoaded(this, __mode == 1 || __mode == 2)"
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html>
