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

    File:           bez_afspraak_bo_new.asp
    Description:    Nieuwe bezoeker bij de bo (bezoekersbalie)
                    Biedt eventuele pool-reserveringen aan. Als die er niet zijn
                    ga direct door naar een nieuwe afspaak
    Parameters:     urole
    Context:        Modal popupje
    Note:           We tonen hoogstens een lijstje van één locatie

*/ %>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/iface.inc" -->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!--#include file="bez.inc" -->
<%
FCLTHeader.Requires({ plugins: [],
                      js: ["jquery-ui.js", "../bez/bez.js"]
                    })

var loc_key_arr = getQParamKeyArray("loc_key", []);
if (!loc_key_arr.length)
    loc_key_arr = [user.alg_locatie_key()];
autfunction = "WEB_BEZBOF"; // Daar is dit scherm voor bedoeld
var authparams = user.checkAutorisation(autfunction);
%>

<html>
  <head>
<%
   FCLTHeader.Generate();
%>
    <script type="text/javascript">
      function bez_own_bez()
      {
        FcltMgr.closeDetail(window, { res_key: -1 } );
      }

      function bez_gotores(row)
      {
        var res_key = row.getAttribute("ROWKEY");
        FcltMgr.closeDetail(window, { res_key: res_key } );
      }

      function bez_cancel(mode)
      {
        FcltMgr.closeDetail(window, { cancel: true } );
      }
    </script>
  </head>

  <body class="fclt-modal" id="mod_respool">
  <% MODAL_START();
    MODAL_BLOCK_START("resSelectpool", L("lcl_select_respool"), { icon: "fa-clock", nopadding: true });

    // Alle pool-reserveringen op de huidige locatie
    var sql = "SELECT rrr.res_reservering_key"
            + "     , MIN(rrr.res_rsv_ruimte_van) res_rsv_ruimte_van"
            + "     , MAX(rrr.res_rsv_ruimte_tot) res_rsv_ruimte_tot"
            + "     , MIN(res_rsv_ruimte_omschrijving) res_rsv_ruimte_omschrijving"
            + "  FROM res_ruimte rr, "
            + "       res_ruimte_opstelling rro,"
            + "       res_v_aanwezigrsv_ruimte rrr ,"
            + "       res_reservering r ,"
            + "       res_v_aanwezigalg_ruimte RES_RA,"
            + "       alg_gebouw ALG_G,"
            + "       alg_verdieping ALG_V,"
            + "       alg_v_aanwezigruimte ALG_R"
            + " WHERE rrr.res_reservering_key = r.res_reservering_key"
            + "   AND res_reservering_ispool = 1"
            + "   AND rr.res_ruimte_key = rro.res_ruimte_key"
            + "   AND rro.res_ruimte_opstel_key = rrr.res_ruimte_opstel_key"
            + "   AND rr.res_ruimte_key = RES_RA.res_ruimte_key"
            + "   AND ALG_R.alg_ruimte_key = RES_RA.alg_ruimte_key"
            + "   AND ALG_R.alg_verdieping_key = ALG_V.alg_verdieping_key"
            + "   AND ALG_V.alg_gebouw_key = ALG_G.alg_gebouw_key"
            + "   AND ALG_G.alg_locatie_key IN (" + loc_key_arr.join(",") + ")"
            + "   AND res_rsv_ruimte_van BETWEEN TRUNC(SYSDATE) AND SYSDATE + " + S("res_pool_early")/60/24
            + "   AND res_rsv_ruimte_tot BETWEEN SYSDATE - " + S("res_pool_late")/60/24 + " AND TRUNC(SYSDATE+1)"
            + " GROUP BY rrr.res_reservering_key"
            + " ORDER BY rrr.res_reservering_key";

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "res_reservering_key",
                                   ID: "lokettable",
                                   noSetSummary: true,
                                   noPrint:true,
                                   emptySetString: "" // Doen we zelf verderop
                                  });

    rst.addColumn(new Column({ hasActions: true, caption: L("lcl_resnr"),         content:"res_reservering_key" }));
    rst.addColumn(new Column({ hasActions: true, caption: L("lcl_descr"),         content:"res_rsv_ruimte_omschrijving" }));
    rst.addColumn(new Column({ hasActions: true, caption: L("lcl_res_starttime"), content:"res_rsv_ruimte_van", datatype: "time" }));
    rst.addColumn(new Column({ hasActions: true, caption: L("lcl_res_endtime"),   content:"res_rsv_ruimte_tot", datatype: "time" }));

    rst.addAction({ action: "bez_gotores", isDefault: true } );

%>  </table><%
    var cnt = rst.processResultset();
    if (cnt <= 0)
    {
        Response.Write("<script>bez_own_bez();</script>");
    }

    MODAL_BLOCK_END();

    var buttons =  [ {title: L("lcl_res_ownafspr"), icon: "fa-calendar-plus", action: "bez_own_bez()" },
                     {title: L("lcl_cancel"),       icon: "fa-fclt-cancel", action: "bez_cancel()" } ];
    SIMPLE_BLOCK_START();
    CreateButtons(buttons);
    SIMPLE_BLOCK_END();

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