<%@ LANGUAGE = JavaScript %>
<% /*
    $Revision$
    $Id$

    File:           contour_search.asp
    Description:
    Parameters:
    Context:
    Note:           Als we een verdieping_key meekrijgen en die heeft
                    concept-oppervlaktes dan doen we concept als default
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->

<%
FCLTHeader.Requires({ plugins:["jQuery", "kenmerk"] });

var locatie_key = getQParamInt("locatie_key", -1); // Locatie
var gebouw_key = getQParamInt("gebouw_key", -1); // Gebouw of terrein
var verdieping_key = getQParamInt("verdieping_key", -1); // Verdieping
var autosearch = getQParamInt("autosearch", 0) == 1;

if (gebouw_key > 0)
{
    var sql = "SELECT 'B' bttype"
            + "  FROM alg_gebouw"
            + " WHERE alg_gebouw_key = " + gebouw_key
            + " UNION "
            + "SELECT 'T' bttype"
            + "  FROM alg_terreinsector"
            + " WHERE alg_terreinsector_key = " + gebouw_key
    var oRs = Oracle.Execute(sql);
    var bttype = oRs("bttype").value;
}

autfunction = 'WEB_CADBOF';
var authparams = user.checkAutorisation(autfunction);

var concept = 0;
if (verdieping_key > 0 || (gebouw_key > 0 && bttype == "T"))
{
  sql = "SELECT cad_tekening_filenaam"
      + "  FROM cad_tekening ct"
      + " WHERE cad_tekening_verwijder IS NULL"
      + "   AND cad_tekening_type = 'P'"
      + (verdieping_key > 0
         ? "   AND ct.alg_verdieping_key = " + verdieping_key
         : "   AND ct.alg_locatie_key = " + locatie_key
           + " AND ct.alg_verdieping_key IS NULL");
  oRs = Oracle.Execute(sql);
  var fname = oRs("cad_tekening_filenaam").value;
  fname = fname.replace(/\.dwg$/i,'');
  fname = fname.replace(/\.dwf$/i,'');
  var fullnameConcept = S("flexfilespath") + "/cad/concept/" + fname + ".dwf";
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  concept = fso.FileExists(fullnameConcept);
}

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      $(function() {<% if (autosearch) { %> document.forms.u2.submit();<%}%>});
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" target="workFrame" action="cad_contour_search_list.asp" method="get">
    <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
    SEARCH_BLOCK_START();%>
            <!-- Reservation number -->
               <%
              FCLTplaatsselector(authparams.ALGreadlevel, { locatiekey: locatie_key,
                                                            gebouwkey:  gebouw_key,
                                                            verdiepingkey: verdieping_key,
                                                            terrein: true,
                                                            startlevel: 2, // locatie
                                                            eindlevel: 4, // verdieping
                                                            whenEmpty: L("lcl_search_generic"),  // want filter bttype?
                                                            filtercode: "EXP"
                                                          });
SEARCH_BLOCK_END();
SEARCH_BLOCK_START();
%>
            <tr><td></td>
              <td><label for="actueel"><input type="radio" id='actueel' name='concept' value='0' <%=!concept?"checked":""%>><%=L("lcl_fg_actueel")%></label><br />
                  <label for="concept"><input type="radio" id='concept' name='concept' value='1' <%=concept?"checked":""%>><%=L("lcl_fg_concept")%></label>
              </td>
            </tr>
<%
      SEARCH_BLOCK_END();

      var buttons =  [ {title: L("lcl_overview_list"), action: "document.forms.u2.submit();", id: "bSearch", icon: "fa-clipboard-list" } ];
      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">
      </iframe>
    </div>
  </body>
</html>
<% ASPPAGE_END(); %>
