<%@ 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 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 = getQParamInt("ruimte_key", -1); // Ruimte
var room_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


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
}
/***** 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">
      function doSubmit()
      {
        if (!validateForm("u2"))
          return false;
        document.forms.u2.submit();
      }

      $(document).ready(function()
                        {
                          return;
                        });
    </script>
  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" action="res_search_list_ppi.asp" target="workFrame" method="post">
        <input type="hidden" name="urole" value="<%=urole%>">
<%      BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1"><!-- start column 1 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <!-- 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,
                                                          startlevel: 1, // District
                                                          eindlevel: 5, // Ruimte
                                                          secsearch: 3, // gebouw en hoger
                                                          whenEmpty: L("lcl_search_generic")  // want filter
                                                        }); %>
            </table>
            <!-- end column 1 -->
          </td>

          <td class="searchkolom2"><!-- start column 2 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <!-- 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.join(","),
                           label: L("lcl_res_roomcat"),
                           trclass: "primsearch",
                           multi: true,
                           emptyOption: L("lcl_all")
                         }); %>

            <!-- 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"'}); %>

            </table>
          </td>
        </tr>
<%    BLOCK_END();

      var buttons =  [];
      buttons.push ( {title: L("lcl_res_PPI"), action:"doSubmit(1)" } ); // Overzicht Prestatie Performance Indicatoren (PPI)
      buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess" } );
      //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)"
              frameborder="0" scrolling="no">
    </div>

  </body>
</html>
