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

    File:               fac_fiatering_search.asp
    Description:        Zoekscherm voor overzicht fiatteringsverzoeken
    Parameters:         None
    Globals:
    Context:            - Vanuit hoofdmenu om overzicht te tonen

    Note:               Wordt zowel voor MLD als voor BES en OFFERTES gebruikt
                        Het echte fiatteren/afwijzen gebeurt telkens door
                        onder bes/mld een functie aan te roepen
*/
%>

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

<%
FCLTHeader.Requires({plugins:["jQuery"], js: ["jquery-ui.js"]});

var autosearch = getQParamInt("autosearch", 1) == 1;
var opdrtype_key = getQParamInt("opdrtype_key", -1); // Opdrachttype
var kpgrp_key_arr = getQParamIntArray("kpgrp_key", [-1]); // Kostenplaatsgroep.
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 getOpen = getQParamInt("open", 0) == 1;
var getClosed = getQParamInt("close", 0) == 1;
var getRejected = getQParamInt("reject", 0) == 1;
if (!getOpen && !getClosed && !getRejected)
  getOpen = true;
var betreft = getQParamArray("betreft", []); // Betreft module BES, CNT, FIN, MLDOF, MLDOP of RES.

%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">

<% if (xd.enabled()) { %>
      function xdclicked()
      {
        if (document.getElementById("xd").checked)
        {
          $(".noxd").addClass("hidden");
        }
        else
        {
          $(".noxd").removeClass("hidden");
        }
      }
<% } %>

			function doSubmit()
			{
<% if (xd.enabled()) { %>
                if ($("#xd").is(":checked"))
                {
                      $("form[name=u2]").attr("action", "fac_fiattering_list_xd.asp");
                } else {
                      $("form[name=u2]").attr("action", "fac_fiattering_list.asp");
                }
<% } %>
				document.forms.u2.submit();
			}

<%
			if (autosearch)
    	{
%>
				$(doSubmit);
<%
	  	}
%>
    </script>
  </head>
  <body id="searchbody">
    <form name="u2" method="get" action="fac_fiattering_list.asp" target="workFrame">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
      SEARCH_BLOCK_START();
            if (xd.enabled())
                RWCHECKBOXTR("xd", "fldxd", L("lcl_xd_crossdomain"), false, {html: "onclick='xdclicked()'"});
%>
              <!-- Locatie/gebouw -->
<%
// Weet niet zeker of het volgende dekkend is
//var autfunctions = 'WEB_MLDUSE,WEB_INSMAN,WEB_INSUSE,WEB_ALGMAN,WEB_ALGUSE,WEB_MLDBO2,WEB_ORDBO2,WEB_MLDBOF';
//var authparams = user.checkAutorisation(autfunctions.split(","));

              FCLTplaatsselector(-1,
                                 { districtkey: dis_key,
                                   locatiekey: loc_key,
                                   gebouwkey: bld_key,
                                   multitoggle: 3,
                                   multionchange: true,
                                   startlevel: 1, // district
                                   eindlevel: 3, // gebouw
                                   terrein: true,
                                   trclass: "noxd",
                                   whenEmpty: L("lcl_search_generic"),  // want filter
                                   filtercode: "EXP"
                                 });
SEARCH_BLOCK_END();
SEARCH_BLOCK_START();
              if (betreft.length > 1)
              {
                %><input type="hidden" name="betreft" value="<%=safe.htmlattr(betreft.join(","))%>"><%
              }
              else
              {
                  sql = "SELECT 'BES'"
                      + ", " + safe.quoted_sql(L("lcl_fin_bestellingen")) + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'CNT'"
                      + ", " + safe.quoted_sql(L("lcl_fin_contracten"))
                      + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'FIN'"
                      + ", " + safe.quoted_sql(L("lcl_fin_invoices"))
                      + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'MLDOF'"
                      + ", " + safe.quoted_sql(L("lcl_fin_offertes"))
                      + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'MLDOP'"
                      + ", " + safe.quoted_sql(L("lcl_fin_opdrachten"))
                      + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'MLDIN'"
                      + ", " + safe.quoted_sql(L("lcl_mld_concepten"))
                      + " FROM DUAL"
                      + " UNION"
                      + " SELECT 'RES'"
                      + ", " + safe.quoted_sql(L("lcl_fin_catering_order"))
                      + " FROM DUAL"
                      + " ORDER BY 2";
                  FCLTselector("betreft",
                               sql,
                               { initKey: betreft.length? betreft[0] : null,
                                 label: L("lcl_fac_betreft"),
                                 trclass: "primsearch",
                                 emptyOption: L("lcl_search_generic"),
                                 emptyKey: ""
                               });
              }
              sql = "SELECT mld_typeopdr_key"
                  + ", mld_typeopdr_omschrijving"
                  + " FROM mld_typeopdr"
                  + " ORDER BY 2";
              FCLTselector("opdrtype_key",
                           sql,
                           { initKey: opdrtype_key,
                             label: L("lcl_mld_typeopdr"),
                             trclass: "primsearch noxd",
                             emptyOption: "",
                             initEmpty: true
                           });
              sql = "SELECT prs_kostenplaatsgrp_key"
                  + "     , DECODE (prs_kostenplaatsgrp_nr, NULL, '', prs_kostenplaatsgrp_nr || ' - ') || prs_kostenplaatsgrp_oms oms"
                  + "  FROM prs_kostenplaatsgrp";
              FCLTselector("kpgrp_key_arr",
                           sql,
                           { initKey: kpgrp_key_arr,
                             label: L("lcl_prs_kostenpl_group"),
                             trclass: "primsearch noxd",
                             emptyOption: "",
                             multi: true,
                             initEmpty: true
                           });
SEARCH_BLOCK_END();
SEARCH_BLOCK_START({wide: true});
%>


        <!-- Status checkboxen -->
        <tr>
          <td colspan="2">
            <div id="statusboxes">
              <label><%=L("lcl_status")%></label>
              <input id="copen" name="open" type="checkbox" value="1" <%=getOpen?"checked":""%>><label for="copen"><%=L("lcl_bes_chek1")%></label>
              <input id="cclose" name="close" type="checkbox" value="1" <%=getClosed?"checked":""%>><label for="cclose"><%=L("lcl_fac_gefiatteerd")%></label>
              <input id="creject" name="reject" type="checkbox" value="1" <%=getRejected?"checked":""%>><label for="creject"><%=L("lcl_fac_afgewezen")%></label>
            </div>
          </td>
        </tr>

<%      SEARCH_BLOCK_END();

        var buttons = [{title: L("lcl_overview_list"), action: "doSubmit()", 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(); %>
