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

     File:      res_search_ppi.asp
     Parameters:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/plaatsselector.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 = "mi";

var cal_intv = 0; // default date offset (in workdays?!) for calendar 2
var date_from = getQParamDate("date_from", null);
var date_to = getQParamDate("date_to", null);
var time_from = getQParam("time_from", null);
var time_to = getQParam("time_to", null);
var dis_key = getQParamInt("district_key", -1); // District
var loc_key = getQParamInt("locatie_key", -1); // Locatie
var bld_key = getQParamInt("gebouw_key", -1); // Gebouw
var floor_key = getQParamInt("verdieping_key", -1); // Verdieping
var room_key = getQParamIntArray("ruimte_key", [-1]); // Ruimte
var roomcat_key_arr = getQParamIntArray("roomcatmulti", [-1]); // Ruimte soort catalogus
var group = getQParamInt("groupby", -1); // Groepering
var dayschedule = getQParamInt("dayschedule", 0) == 1; // Dagverdeling standaard niet aangevinkt indien niet meegegeven
var start_time = S("res_t1");
var end_time = S("res_t2");

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
}
if (time_from == null)
{
  var setup_time = S("res_rap_t1") == -1 ? S("res_t1") : S("res_rap_t1");
  var res_rap_t1h = Math.floor(setup_time);
  if (res_rap_t1h < 10) res_rap_t1h = "0" + res_rap_t1h;
  var res_rap_t1m = Math.floor((setup_time - res_rap_t1h)*60);
  if (res_rap_t1m < 10) res_rap_t1m = "0" + res_rap_t1m;
  time_from = res_rap_t1h + ":" + res_rap_t1m
}
if (time_to == null)
{
  setup_time = S("res_rap_t2") == -1 ? S("res_t2") : S("res_rap_t2");
  var res_rap_t2h = Math.floor(setup_time);
  if (res_rap_t2h < 10) res_rap_t2h = "0" + res_rap_t2h;
  var res_rap_t2m = Math.floor((setup_time - res_rap_t2h)*60);
  if (res_rap_t2m < 10) res_rap_t2m = "0" + res_rap_t2m;
  time_to = res_rap_t2h + ":" + res_rap_t2m
}
  var setup_time = S("res_t1");
  var res_rap_t1h = Math.floor(setup_time);
  if (res_rap_t1h < 10) res_rap_t1h = "0" + res_rap_t1h;
  var res_rap_t1m = Math.floor((setup_time - res_rap_t1h)*60);
  if (res_rap_t1m < 10) res_rap_t1m = "0" + res_rap_t1m;
  var time_start = res_rap_t1h + ":" + res_rap_t1m

  setup_time = S("res_t2");
  var res_rap_t2h = Math.floor(setup_time);
  if (res_rap_t2h < 10) res_rap_t2h = "0" + res_rap_t2h;
  var res_rap_t2m = Math.floor((setup_time - res_rap_t2h)*60);
  if (res_rap_t2m < 10) res_rap_t2m = "0" + res_rap_t2m;
  var time_stop = res_rap_t2h + ":" + res_rap_t2m
/***** End get webform parameters *****/

var autfunction = "WEB_RESBAC";

// 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">
      async function doSubmit()
      {
        if (!await validateForm("u2"))
          return false;
        document.forms.u2.submit();
      }
      $(function() {
        $("#time_from, #time_to").timePicker({
            step: 60,
            startTime : "<%=time_start%>",
            endTime   : "<%=time_stop%>",
            columns   : <%=S("timepickercolumns")%>,
            onChange  : function () {
              $timeInput = $(this).parents("div.time-holder").prev("input.fldtime")
              $timeInput.removeClass("bad");
              $timeInput.trigger("change");
            }
        });
        $("#time_from, #time_to").on("change blur", function() {
            if ($("#time_from").val() > $("#time_to").val())
            {
              $("#time_from").val($("#time_to").val());
            }
        });
      });
    </script>
  </head>

  <body id="searchbody">
      <form name="u2" action="res_search_list_ppi.asp" target="workFrame" method="post">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
      SEARCH_BLOCK_START();%>
        <input type="hidden" name="urole" value="<%=urole%>">
            <!-- Periode -->
<%          // <!-- Datum van -->
            FCLTcalendar("date_from",
                         { label : L("lcl_period_from"),
                           datum: date_from,
                           trclass: "primsearch",
                           required: true,
                           volgnr: 1
                         });
            // <!-- Datum tot -->
            FCLTcalendar("date_to",
                         { label: L("lcl_period_to"),
                           datum: date_to,
                           trclass: "primsearch",
                           required: true,
                           volgnr: 2
                         });

            // <!-- District, locatie, gebouw, verdieping en ruimte -->
            FCLTplaatsselector(authparams.ALGreadlevel, { districtkey: dis_key,
                                                          locatiekey: loc_key,
                                                          gebouwkey: bld_key,
                                                          verdiepingkey: floor_key,
                                                          ruimtekey: room_key,
                                                          multitoggle: 5,
                                                          startlevel: 1, // District
                                                          eindlevel: 5, // Ruimte
                                                          secsearch: 3, // gebouw en hoger
                                                          whenEmpty: L("lcl_search_generic"),  // want filter
                                                          filtercode: "EXP"
                                                        });

SEARCH_BLOCK_END();
SEARCH_BLOCK_START(); %>

            <!-- time_from -->
            <tr class="primsearch">
              <td class="label"><label for="time_from"><%=L("lcl_res_starttime")%></label></td>
              <td>
                <span class="input-icon-wrapper">
                  <input class="fldtime required" type="text"  value="<%=safe.htmlattr(time_from)%>" id="time_from" name="time_from">
                  <span class="timeklikker" onclick='$("#time_from")[0].click(); FcltMgr.stopPropagation(event);'><%=I("fa-clock")%></span>
                </span>
              </td>
            </tr>
            <!-- time_to -->
            <tr class="primsearch">
              <td class="label"><label for="time_to"><%=L("lcl_res_endtime")%></label></td>
              <td>
                <span class="input-icon-wrapper">
                  <input class="fldtime required" type="text"  value="<%=safe.htmlattr(time_to)%>" id="time_to" name="time_to">
                  <span class="timeklikker" onclick='$("#time_to")[0].click(); FcltMgr.stopPropagation(event);'><%=I("fa-clock")%></span>
                </span>
              </td>
            </tr>
            <!-- 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: roomcat_key_arr.join(","),
                           label: L("lcl_res_roomcat"),
                           trclass: "primsearch",
                           multi: true,
                           emptyOption: L("lcl_search_generic")
                         }); %>

            <!-- Groepering -->
<%          sql = "SELECT 5, " + safe.quoted_sql(L("lcl_district")) + ", 1 FROM DUAL"
                + " UNION SELECT 6, " + safe.quoted_sql(L("lcl_mi_location")) + ", 2 FROM DUAL"
                + " UNION SELECT 10, " + safe.quoted_sql(L("lcl_building")) + ", 3 FROM DUAL"
                + " UNION SELECT 14, " + safe.quoted_sql(L("lcl_room")) + ", 4 FROM DUAL"
                + " UNION SELECT 15, " + safe.quoted_sql(L("lcl_res_roomcat")) + ", 5 FROM DUAL"
                + " UNION SELECT 16, " + safe.quoted_sql(L("lcl_month")) + ", 6 FROM DUAL"
                + " UNION SELECT 18, " + safe.quoted_sql(L("lcl_weekday")) + ", 7 FROM DUAL"
                + " UNION SELECT 19, " + safe.quoted_sql(L("lcl_date")) + ", 8 FROM DUAL"
                + " ORDER BY 3";
            FCLTselector("groupby",
                         sql,
                         { initKey: group,
                           label: L("lcl_res_group"),
                           trclass: "primsearch"
                         }); %>

<%          CHECKBOXTR(L("lcl_res_dayschedule"), "fldresdaysched", "dayschedule", dayschedule, {html: ' value="1"'}); %>


<%    SEARCH_BLOCK_END();

      var buttons =  [];
      buttons.push ( {title: L("lcl_res_PPI"), action:"doSubmit(1)", importance: 1, icon: "fa-chart-area" } ); // Overzicht Prestatie Performance Indicatoren (PPI)
      buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess", importance: 3, icon: "fa-chevron-right" } );
      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">
    </div>

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