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

    File:           prs_bedrijf_search.asp
    Description:   Toont zoekvelden voor lijst van bedrijven
    Parameters:
    Context:       Vanuit menu
    Note:

*/ %>

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

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

/***** Get webform parameters *****/

var loc_key = getQParamInt("locatie_key", -1);

var intern = getQParamInt("intern", 0);
var isIntern = (intern == 1);
var isSysteem = (intern == 2);

// optional prefilling params
var pcompanyName = getQParam("pcompanyName", -1);
var pcompanyNr = getQParam("pcompanyNr", -1);
var pbezoekPostcode = getQParam("pbezoekPostcode", -1);
var pbezoekPlaats = getQParam("pbezoekPlaats", -1);
var pdienst_key = getQParamInt("pdienst_key", -1);
var preltype_key = getQParamInt("prelatietype_key", -1);
var pcontactPrs = getQParam("pcontactPrs", -1);

var isleverancier = getQParamInt("leverancier", 1) == 1;
var isuitvoerende = getQParamInt("uitvoerende", 1) == 1;
var iscontract = getQParamInt("contract", 1) == 1;
var ishuurder = getQParamInt("huurder", 1) == 1;
var isnothing = getQParam("nothing", 0) == 1;

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

// So what authorization must we check?
// Voor gewone bedrijven (0) is het WEB_RELMAN, WEB_RELUSE
// Voor interne bedrijven (1) is het WEB_PRSMAN
// Voor systeembedrijven (2) is het WEB_PRSSYS
if (isSysteem)
  var autfunction = ["WEB_PRSSYS"];
else if (isIntern)
  var autfunction = ["WEB_PRSMAN"];
else
  var autfunction = ["WEB_RELMAN", "WEB_RELUSE"];

if (user.iamContact())
  autfunction.push("WEB_EXTREL");
if (S("bgt_enabled") == 1)
  autfunction.push("WEB_BGTUSE");

var authparams = user.checkAutorisation(autfunction, true);

user.auth_required_or_abort(authparams);

// VALIDATE AND PREPARE
var there_is_dienst = false;
var tsql = "SELECT prs_dienst_key FROM prs_dienst";
var toRs = Oracle.Execute( tsql );
there_is_dienst = !toRs.eof;
toRs.close();
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
<% if (xd.enabled()) { %>
      function xdclicked()
      {
        var doxd = document.getElementById("xd").checked;
        $(".noxd").toggle(!doxd); // Kan want geen secsearch
        $(".onlyxd").toggleClass('hidden', !doxd);
      }
<% } %>
      function doSubmit()
      {
<% if (xd.enabled()) { %>
        if ($("#xd").is(":checked"))
        {
              $("form[name=u2]").attr("action", "prs_bedrijf_search_list_xd.asp");
        } else {
              $("form[name=u2]").attr("action", "prs_bedrijf_search_list.asp");
        }
<% } %>
        // Submitten met kenmerken
        doSubmitWithKenmerken();
      }

      async function myModal(init)
      {
        var lvl = "";
        var key = 0;
        var bld_key = "";
        var url = "load_kenmerk.asp?disc=" + "&urole=bo" + "&advanced=1" + "&hasFilter=1" + "&niveau=B" + "&intern=<%=intern%>";
        var titel = "";
        await showKenmerkModal(url, titel, init)
      }
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" method="get" action="prs_bedrijf_search_list.asp" target="workFrame">
      <input type="hidden" name="intern" value="<%=intern%>">
<% if (isSysteem) {  // en ernstig verkorte versie van de filters
        SEARCH_PAGE_START({ header: L("lcl_filterblok") });
        SEARCH_BLOCK_START();
%>
            <tr class="primsearch">
              <td class="label"><label for="companyName"><%=L("lcl_prs_companies_name_sys")%></label></td>
              <td><input type="text" class="fld wildcard" name="companyName" <%=(pcompanyName != -1) ? "value='" + safe.htmlattr(pcompanyName) + "'" : ""%>></td>
            </tr>
<% 
        SEARCH_BLOCK_END();
} else {

        SEARCH_PAGE_START({ header: L("lcl_filterblok") });
        SEARCH_BLOCK_START();%>
<%
            if (xd.enabled())
                RWCHECKBOXTR("xd", "fldxd", L("lcl_xd_crossdomain"), false, {html: "onclick='xdclicked()'"});
%>
            <tr class="primsearch">
              <td class="label"><label for="companyName"><%=L("lcl_prs_companies_name")%></label></td>
              <td><input type="text" class="fld wildcard" name="companyName" <%=(pcompanyName != -1) ? "value='" + safe.htmlattr(pcompanyName) + "'" : ""%>></td>
            </tr>

            <tr class="primsearch">
              <td class="label"><label for="companyNr"><%=L("lcl_prs_companies_leverancier_nr")%></label></td>
              <td><input type="text" class="fld wildcard" name="companyNr" <%=(pcompanyNr != -1) ? "value='" + safe.htmlattr(pcompanyNr) + "'" : ""%>></td>
            </tr>
            <tr class="primsearch">
              <td class="label"><label for="bezoekPostcode"><%=L("lcl_prs_companies_bezoek_postcode")%></label></td>
              <td><input type="text" class="fld wildcard" name="bezoekPostcode" <%=(pbezoekPostcode != -1) ? "value='" + safe.htmlattr(pbezoekPostcode) + "'" : ""%>></td>
            </tr>
            <tr class="primsearch">
              <td class="label"><label for="bezoekPlaats"><%=L("lcl_prs_companies_bezoek_plaats")%></label></td>
              <td><input type="text" class="fld wildcard" name="bezoekPlaats" <%=(pbezoekPlaats != -1) ? "value='" + safe.htmlattr(pbezoekPlaats) + "'" : ""%>></td>
            </tr>
<%
              var sqlrelatietype = "SELECT prs_relatietype_key"
                                 + "     , " + lcl.xsqla("prs_relatietype_omschrijving", "prs_relatietype_key")
                                 + "  FROM prs_relatietype"
                                 + " WHERE prs_relatietype_verwijder IS NULL"
                                 + " ORDER BY UPPER(" + lcl.xsql("prs_relatietype_omschrijving", "prs_relatietype_key") + ")";
              FCLTselector("relatietypekey",
                           sqlrelatietype,
                           { label: L("prs_relatietype"),
                             initKey: preltype_key,
                             trclass: "primsearch noxd",
                             emptyOption: L("lcl_search_generic")
                           });

SEARCH_BLOCK_END();
SEARCH_BLOCK_START();

           if (there_is_dienst && !isIntern)
              { %>
                <!-- Locatie en gebouw -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="loctekst"><%=L("lcl_location")%></label></td>
                  <td>
                    <input type="text" class="fld" name="loctekst" value="">
                  </td>
                </tr>
<%                FCLTplaatsselector(authparams.PRSreadlevel, { locatiekey: loc_key,
                                                                startlevel: 2, // locatie
                                                                eindlevel: 3, // gebouw
                                                                trclass: "noxd",
                                                                whenEmpty: L("lcl_search_generic"),  // want filter
                                                                filtercode: "EXP"
                                                              });
%>

                <!-- Uitvoerende -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="diensttekst"><%=L("lcl_prs_companies_dienst")%></label></td>
                  <td>
                    <input type="text" class="fld" name="diensttekst" value="">
                  </td>
                </tr>
<%                 FCLTdienstselector("dienstkey","dienstkey",
                             { label: L("lcl_prs_companies_dienst"),
                               dienstKey : pdienst_key,
                               trclass:"primsearch noxd",
                               whenEmpty: L("lcl_search_generic")
                             });
              } %>
              <tr class="primsearch">
                <td class="label"><label for="contactPrs"><%=L("lcl_prs_companies_contact_person")%></label></td>
                <td><input type="text" class="fld wildcard" name="contactPrs" <%=(pcontactPrs != -1) ? "value='" + safe.htmlattr(pcontactPrs) + "'" : ""%>></td>
              </tr>
<%            RWCHECKBOXTR("tooningids", "fldnotingids", L("lcl_prs_companies_ingids"), 0, {trclass: "primsearch noxd"})

SEARCH_BLOCK_END();
SEARCH_BLOCK_START({wide: true});

        if (!isIntern)
        { %>
          <!--  checkboxen -->
          <tr>
            <td colspan="2">
              <div id="statusboxes">
                  <input type="checkbox" class="fldcheck" name="leverancier"   id="leverancier"   value="1" <%=(isleverancier?"CHECKED":"")%>><label for="leverancier"><%=L("lcl_prs_companies_leverancier")%></label>
                  <input type="checkbox" class="fldcheck" name="uitvoerende"   id="uitvoerende"   value="1" <%=(isuitvoerende?"CHECKED":"")%>><label for="uitvoerende"><%=L("lcl_prs_companies_uitvoerende")%></label>
                  <input type="checkbox" class="fldcheck" name="contract"      id="contract"      value="1" <%=(iscontract?"CHECKED":"")%>><label for="contract"><%=L("lcl_prs_companies_contract")%></label>
                  <input type="checkbox" class="fldcheck" name="huurder"       id="huurder"       value="1" <%=(ishuurder?"CHECKED":"")%>><label for="huurder"><%=L("lcl_prs_companies_huurder")%></label>
                  <input type="checkbox" class="fldcheck" name="notype"        id="notype"        value="1" <%=(isnothing?"CHECKED":"")%>><label for="notype"><%=L("lcl_prs_companies_notype")%></label>
              </div>
            </td>
          </tr>
<%      }
SEARCH_BLOCK_END();
        } // end of isSysteem 

      var buttons =  [ {title: L("lcl_overview_list"), action:"doSubmit()", id: "bSearch", importance: 1, icon: "fa-clipboard-list" }];
      if (!isSysteem) 
          buttons.push ({title: L("lcl_shared_advanced"), action:"myModal()", id: "bAdvanced", xclass: "noxd", importance: 3, icon: "fa-filter" });
      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(); %>
