<%@ 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" -->
<!-- #include file="../Shared/calendar.inc" -->
<%
FCLTHeader.Requires({ plugins:["jQuery"],
                      js: ["./bez_search.js", "jquery.timepicker-table.js"],
                      css: ["timePicker-table.css"]
                    });

/***** 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));

if (minfo)
{
  var date_from = getQParamDate("date_from", null);
  var date_to = getQParamDate("date_to", null);

  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
    var dateto = dt.setDate(0); // Laatste dag van de vorige maand
    var datefrom = dt.setDate(1); // Eerste dag van de vorige maand

    date_from = new Date(parseInt(datefrom, 10));
    date_to = new Date(parseInt(dateto, 10));
  }
}
else
{
  var date_from = getQParamDate("date_from", new Date);
  var date_to = getQParamDate("date_to", new Date);
}

var time_hour = (new Date()).getHours();
var time_min = (new Date()).getMinutes();
var vis_end = time_hour + (time_min / 60) + S("vis_bo_end_interval");
if (vis_end > S("vis_t2"))
  vis_end = S("vis_t2");
var starttimedate = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), Math.floor(S("vis_t1")), (S("vis_t1") - Math.floor(S("vis_t1"))) * 60)
var endtimedate = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), Math.floor(vis_end), Math.round((vis_end - Math.floor(vis_end)) * 60))
// padout functie zet een voorloop nul voor één cijfer (Shared.inc)
var starttime = padout(Math.floor(S("vis_t1"))) + ":" + padout((S("vis_t1") - Math.floor(S("vis_t1"))) * 60);
var endtime = padout(Math.floor(vis_end)) + ":" + padout(Math.round((vis_end - Math.floor(vis_end)) * 60));
var step = S("vis_h") * 60;

var regio_key = getQParamInt("regio_key", -1); // Regio
var district_key = getQParamInt("district_key", -1);
var locatie_key = getQParamInt("locatie_key", (!minfo? user.alg_locatie_key() : -1)); // Als geen input en wel eigen werkplek dan eigen locatie
var gebouw_key = getQParamInt("gebouw_key", -1);
var verdieping_key = getQParamInt("verdieping_key", -1);

var afspr_key = getQParamInt("afspr_key", "", true); // Afspraak nummer
var prs_key = getQParamInt("prs_key", -1); // Aanvrager key
var host_key = getQParamInt("host_key", -1); // Bezoek voor / gastheer key
var dep_key = getQParamInt("dep_key", -1);
var searchtext = getQParam("searchtext", ""); // Zoektekst
var groupby = getQParamInt("groupby", 0); // Groepering, default waarde district(=0)
var alg_startlevel = getQParamInt("alg_startlevel", -1); // Startlevel van plaatsselector
var bezPark = getQParamInt("bezPark", 0) == 1;

var bezExpect = getQParam("bezExpect", 1) == 1;
var bezInside = getQParam("bezInside", S("vis_bo_show_all")) == 1; // Als S("vis_bo_show_all") == 1 dan alle checkboxen geselecteerd
var bezDepart = getQParam("bezDepart", S("vis_bo_show_all")) == 1; // Als S("vis_bo_show_all") == 1 dan alle checkboxen geselecteerd
var bezClosed = getQParam("bezClosed", S("vis_bo_show_all")) == 1; // Als S("vis_bo_show_all") == 1 dan alle checkboxen geselecteerd
if (!bezExpect && !bezInside && !bezDepart && !bezClosed)
  bezExpect = true;

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

var autfunction = "";
switch(urole)
{
  case "fe": autfunction = "WEB_BEZUSE";
           break;
  case "fo": autfunction = "WEB_BEZFOF";
           break;
  case "bo": autfunction = "WEB_BEZBOF";
           break;
  case "mi": autfunction = "WEB_BEZBAC";
           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 vis_checkout_enable = (<%=S("vis_checkout_enable")%> == 1);

          $(document).ready(function()
         {
<%         if (frontend) { %>
             document.forms.u2.submit();
<%         } %>
<%         else { %>
<%           if (!minfo) { %>
               if ($("#locatiekey").val() > 0)
               {
                 document.forms.u2.submit();
               }


<%           } %>
<%         } %>
         });

    </script>
  </head>

  <body>
    <div id="search">
      <form name="u2" target="workFrame" action="bez_search_list.asp" method="get">
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="user_key" value="<%=user_key%>">
        <input type="hidden" name="contactonly" value="<%=getQParamInt("contactonly",0)%>">
<%    BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1"><!-- start column 1 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%          if (fronto || backo)
            { %>
              <!-- Afspraaknummer -->
              <tr class="primsearch">
                <td class="label"><label for="afspr_key"><%=L("lcl_vis_appointment_no")%>:</label></td>
                <td><input type="text" class="fldafspnum" name="afspr_key" value="<%=afspr_key%>"></td>
              </tr>
<%          }

            if (!frontend)
            { %>
              <!-- Zoektekst -->
              <tr class="primsearch">
                <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>
<%          }

            if (!frontend)
            {
              // <!-- Datum -->
                FCLTcalendar( "date_from",
                              { label : L("lcl_period_from"),
                                datum: starttimedate,
                                trclass: "primsearch",
                                volgnr: 1,
                                timeField: true,
                                timeStep: step,
                                startTime: starttime,
                                endTime: endtime,
                                timeClass: "secsearch"

                              });
              // <!-- Datum tot -->
                FCLTcalendar( "date_to",
                              { label: L("lcl_period_to"),
                                datum: endtimedate,
                                trclass: (minfo ? "primsearch" : "secsearch"),
                                volgnr: 2,
                                timeField: true,
                                timeStep: step,
                                startTime: starttime,
                                endTime: endtime,
                                timeClass: "secsearch"
                              });
            }

            // Parkeerplaats
            if (minfo)
                CHECKBOXTR(L("lcl_park"), "fldbezpark", "bezPark", bezPark)

            if (minfo)
            {
              // <!-- Groepering -->
                sql = "SELECT        1, " + safe.quoted_sql(L("lcl_district")) + " FROM DUAL"
                    + " UNION SELECT 2, " + safe.quoted_sql(L("lcl_location")) + " FROM DUAL"
                    + " UNION SELECT 3, " + safe.quoted_sql(L("lcl_building")) + " FROM DUAL"
                    + " UNION SELECT 4, " + safe.quoted_sql(L("lcl_month"))    + " FROM DUAL"
                    + " UNION SELECT 5, " + safe.quoted_sql(L("lcl_week"))    + " FROM DUAL"
                    + " UNION SELECT 6, " + safe.quoted_sql(L("lcl_day"))    + " FROM DUAL"
                    + " ORDER BY 1";
                FCLTselector("groupby",
                             sql,
                             { initKey: groupby,
                               label: L("lcl_BEZ_group")
                             });

            } %>
            </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td valign=top>
            <table>
<%          if (!frontend)
            { // <!-- Locatie, gebouw en verdieping -->
                  if (minfo)
                  {
                    var startlevel = 1; // district
                    var endlevel = 3; // gebouw
                  }
                  else // front of backo
                  {
                    var startlevel = 2; // locatie
                    if (S("vis_afspraak_onrgoed_uses_keys") == 1)
                      var endlevel = 4; // verdieping
                    else
                      var endlevel = 2; // locatie
                  }
                  FCLTplaatsselector(authparams.ALGreadlevel,
                                      { regiokey: regio_key,
                                        districtkey: district_key, // indien startlevel 2 is, dan wordt deze parameter niet gebruikt
                                        locatiekey: locatie_key,
                                        gebouwkey: gebouw_key, // indien eindlevel 2 is, dan wordt deze parameter niet gebruikt
                                        verdiepingkey: verdieping_key, // indien eindlevel 2 is, dan wordt deze parameter niet gebruikt
                                        startlevel: alg_startlevel >= 0? alg_startlevel : startlevel,
                                        eindlevel: endlevel,
                                        filtercode: "BEZ",
                                        secsearch: 4, // verdieping en hoger
                                        whenEmpty: L("lcl_search_generic")  // want filter
                                      });
            }

            if (!fronto || minfo)
            {
              // <!-- Aanvrager -->
              FCLTpersoonselector("sName_key", // requestor
                                  "sgPerson",
                                  { perslidKey: prs_key,
                                    label: L("lcl_vis_contactperson"),
                                    filtercode: "BEZR",
                                    trclass: "secsearch",
                                    autlevel: authparams.PRSreadlevel,
                                    whenEmpty: L("lcl_search_generic")  // want filter
                                  });
            }

            if (fronto || (S("vis_bo_search_host") && backo) || minfo)
            { // Akzo wil dit expliciet ook in de backoffice
              // <!-- Bezoek voor -->
              FCLTpersoonselector("sHost_key",
                                  "sgHost",
                                  { perslidKey: host_key,
                                    label: L("lcl_vis_visit"),
                                    filtercode: "BEZH",
                                    trclass: "primsearch",
                                    autlevel: authparams.PRSreadlevel,
                                    whenEmpty: L("lcl_search_generic")  // want filter
                                  });
            }

            if (minfo)
            {
              //<!-- Organisatie -->
                FCLTafdelingselector("sDept_key", // organisation
                                     "sgDept",
                                     { departmentKey: dep_key,
                                       label: L("lcl_dep_name_level2"), // Nu Afdeling, was L("lcl_bes_organisation") => Organisatie
                                       trclass: "secsearch",
                                       autlevel: authparams.PRSreadlevel, // Was voorheen niet aanwezig
                                       whenEmpty: L("lcl_search_generic")  // want filter
                                     });
            }

            if (backo)
            { // <!-- Statuses -->
              %>
              <tr class="primsearch">
                <td class="label"><label><%=L("lcl_bes_Bes_status")%>:</label></td>
                <td>
                  <div style="white-space: nowrap;">
                    <input type="checkbox" class="fldbezexpext" name="bezExpect" id="bezExpect" onClick="checkCheckboxes();" value="1" <%=bezExpect? "checked" : ""%>>
                    <label for="bezExpect"><%=L("lcl_vis_expected")%></label>
<%                  if (S("vis_checkout_enable") == 1)
                    { %>
                      <input type="checkbox" class="fldbezinside" name="bezInside" id="bezInside" onClick="checkCheckboxes();" value="1" <%=bezInside? "checked" : ""%>>
                      <label for="bezInside"><%=L("lcl_vis_inside")%></label>
                      <input type="checkbox" class="fldbezdepart" name="bezDepart" id="bezDepart" onClick="checkCheckboxes();" value="1" <%=bezDepart? "checked" : ""%>>
                      <label for="bezDepart"><%=L("lcl_vis_departed")%></label>
<%                  }
                    else
                    { %>
                      <input type="checkbox" class="fldbezclosed" name="bezClosed" id="bezClosed" onClick="checkCheckboxes();" value="1" <%=bezClosed? "checked" : ""%>>
                      <label for="bezClosed"><%=L("lcl_vis_processed")%></label>
<%                  } %>
                  </div>
                </td>
              </tr>
<%          } %>
            </table>
          </td><!-- end column 2-->
        </tr>
<%    BLOCK_END();
      var buttons = [{ title: L("lcl_search"), action: "document.forms.u2.submit();"}];
      if (!frontend)
          buttons.push({ title: L("lcl_shared_more"), action: "iface_toggleSecondarySearchblock()", id: "btnMoreLess"});
      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">
      </iframe>
    </div>
  </body>
</html>
