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

     File:      bes/opdr_search.asp
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/bedrijfselector.inc" -->
<!-- #include file="../Shared/adresselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/srtgroepselector.inc" -->
<!-- #include file="../Shared/srtdeelselector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->

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

/***** Get webform parameters *****/
var urole = getQParamSafe("urole", "bo");
var fronto = urole == "fo";
var backo = (urole == "bo" || urole == "br");
var minfo = (urole == "mi");
var frontend = (urole == "fe" || (!fronto && !backo && !minfo));

var date_from = getQParamDate("date_from", null);
var date_to = getQParamDate("date_to", null);
var prs_key = getQParamInt("prs_key", -1); // Requestor_key
var disc = getQParamInt("disc", -1); // catalogus
var srtgroup = getQParamInt("srtgroup", -1); // groep
var srtdeel = getQParamInt("srtdeel", -1); // item (select box)
var dep_key = getQParamInt("dep_key", -1);
var kp = getQParam("kp", "");
var item = getQParam("item", ""); // item (input box)
var opm = getQParam("opm", ""); // opmerking (input box)
var supplier = getQParamInt("supplier", -1); // leverancier
var opdr_key = getQParamInt("opdr_key", ""); // Opdracht nummer

var opdrRej = getQParamInt("opdrRej", 0) == 1; // Afgemeld
var opdrOpen = getQParamInt("opdrOpen", 0) == 1; // Open
var opdrDelivered = getQParamInt("opdrDelivered", 0) == 1; // Geleverd
var opdrClosed = getQParamInt("opdrClosed", 0) == 1; // Archief
if (!opdrOpen && !opdrDelivered && !opdrClosed)
  opdrOpen = true;
/***** End get webform parameters *****/


var autfunction = "";
switch(urole)
{
  case "bo": autfunction = "WEB_BESBOF"; // Backoffice: Bestellingen. Belstelopdrachten overzicht bekijken met WEB_BESBOF.
             break;
  case "br": autfunction = "WEB_BESBOR"; // Backoffice:Bestelopdrachten. Belstelopdrachten overzicht bekijken met WEB_BESBOR.
             break;
}

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

// De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
user.auth_required_or_abort(authparams);

sql = "SELECT count(*) aantal"
    + " FROM bes_v_aanwezigdiscipline bd, bes_disc_params bdp"
    + " WHERE bdp.bes_ins_discipline_key = bd.ins_discipline_key"
    + " AND bes_disc_params_for_others = 1"
oRs = Oracle.Execute(sql);
var has_bes_disc_params_for_others = (oRs("aantal").value != 0); // minimaal 1 discipline waarvoor "Bestelling voor" kan worden gebruikt.
oRs.Close();
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
  </head>

  <body id="searchbody">
    <form name="u2" target="workFrame" action="opdr_search_list.asp" method="get">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") }); %>
      <% SEARCH_BLOCK_START(); %>
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="user_key" value="<%=user_key%>">
            <!-- Opdrachtnummer -->
            <tr class="primsearch">
              <td class="label"><label for="ordernum"><%=L("lcl_ord_order_num")%></label></td>
              <td><input type="text" class="fldshort" name="ordernum" value="<%=opdr_key%>"></td>
            </tr>


<%             // <!-- Leverancier -->
                FCLTbedrijfselector("sSuppl_key", // supplier
                                  "sgSuppl",
                                  { companyKey: supplier,
                                    label: L("lcl_bes_Supplier"),
                                    trclass: "primsearch",
                                    filtercode: "B",
                                    whenEmpty: L("lcl_search_generic")
                                  });
            //<!-- Aanvrager -->

               FCLTpersoonselector("sName_key", // requestor
                                    "sgPerson",
                                    { perslidKey: prs_key,
                                      label: L("lcl_rfo_requestor"),
                                      filtercode: "BES",
                                      trclass: "primsearch",
                                      autlevel: authparams.PRSreadlevel,
                                      whenEmpty: L("lcl_search_generic")  // want filter
                                    });
            // <!-- Bestelling voor -->
            if (has_bes_disc_params_for_others)
               FCLTpersoonselector("personFor",
                                    "sgPersonFor",
                                    { label: L("lcl_bes_order_for"),
                                      filtercode: 'BESV',
                                      trclass: "primsearch",
                                      whenEmpty: L("lcl_search_generic")  // want filter
                                    });
            // <!-- Organisatie -->
              FCLTafdelingselector("sDept_key", // organisation
                                   "sgDept",
                                   { departmentKey: dep_key,
                                     label: L("lcl_dep_name_level2"), // Nu Afdeling, was L("lcl_prs_organisatie") => Organisatie
                                     trclass: "secsearch",
                                     autlevel: authparams.PRSreadlevel, // Was voorheen niet aanwezig
                                     whenEmpty: L("lcl_search_generic")  // want filter
                                   });

           // <!-- Afleveradres -->
/*           FCLTselector("adr_key",
                          "SELECT mld_adres_key, mld_adres_naam"
                          + " FROM mld_adres"
                          + " WHERE mld_adres_verwijder IS NULL"
                          + " ORDER BY 2",
               {    emptyOption: "",
                    label : L("lcl_bes_del_place"),
                    trclass: "secsearch"
               }); */
          FCLTadresselector("adr_key", "sgAdres",
                          {
                             label: L("lcl_delivery_address"), /* zelfde als lcl_bes_del_place */
                             whenEmpty: L("lcl_search_generic"),
                             filtercode: "A",
                             trclass: "secsearch"
                          }) ;

            if (!frontend && S("bes_bestelopdr_flags") > 1) // Flags checkboxen -->
            {
                for (flagkey=0; flagkey < S("bes_bestelopdr_flags"); flagkey++)
                {
                    var label = "<label for='flag" + flagkey + "'>"
                              + "  <span class='besopdrflag" + flagkey + " besopdrs'>"
                              +      I("fa-fclt-flag" + (flagkey == 0 ? "0" : ""))
                              + "  </span> " + safe.html(L("lcl_bestelopdr_flag" + flagkey))
                              + "</label>";
                    RWCHECKBOXTR("flag" + flagkey, "fldcheck", (flagkey == 0 ? L("lcl_bestelopdr_flags") : ""), 1, { twocols: true, posthtml: label });
                }
            }
 SEARCH_BLOCK_END();
 SEARCH_BLOCK_START();

              // Datum van
              FCLTcalendar("date_from",
                           { label : L("lcl_period_from"),
                             datum: date_from,
                             initEmpty: date_from? false : true,
                             trclass: "primsearch",
                             volgnr: 1
                           });
              // Datum tot
              FCLTcalendar("date_to",
                           { label: L("lcl_period_to"),
                             datum: date_to,
                             initEmpty: date_to? false : true,
                             trclass: "primsearch",
                             volgnr: 2
                           });
              // Catalogus
              FCLTdisciplineselector("disc",
                                     "sgDisc",
                                     { label: L("lcl_bes_Catalogus"),
                                       module: "BES",
                                       disc_key: disc,
                                       srtdisc_key: null,
                                       autRW: "R",
                                       perslidKey: user_key,
                                       autfunctionKey: authparams.autfunctionkey,
                                       trclass: "primsearch",
                                       onChange: "onChangeDiscipline",
                                       whenEmpty: L("lcl_search_generic")  // want filter
                                     });
              //Groep
              FCLTsrtgroepselector("srtgroep",
                                   "sgSrtgroep",
                                   { label: L("lcl_obj_group"),
                                     module: "BES",
                                     srtgroep_key: srtgroup,
                                     autfunction: autfunction,
                                     trclass: "primsearch",
                                     onChange: "onChangeSrtgroep",
                                     urlAdd: [{urlParam: "disc_key", field: "disc"}],
                                     whenEmpty: L("lcl_search_generic")  // want filter
                                   });
              // Item select box
              FCLTsrtdeelselector("srtdeel",
                                  "sgSrtdeel",
                                  { label: L("lcl_bes_srtdeel"),
                                    module: "BES",
                                    srtdeel_key: srtdeel,
                                    autfunction: autfunction,
                                    trclass: "primsearch",
                                    onChange: "onChangeSrtdeel",
                                    urlAdd: [{urlParam: "srtgroep_key", field: "srtgroep"},
                                             {urlParam: "disc_key", field: "disc"}],
                                    whenEmpty: L("lcl_search_generic")  // want dit is een filter
                                  });
%>
            <!-- Item input box -->
            <tr class="secsearch">
              <td class="label"><label for="item"><%=L("lcl_bes_srtdeel")%></label></td>
              <td><input type="text" class="fld wildcard" name="item" value="<%=safe.htmlattr(item)%>">
            </tr>
            <!-- Kostenplaats -->
            <tr class="secsearch">
              <td class="label"><label for="kp"><%=L("lcl_bes_ordernr")%></label></td>
              <td><input type="text" class="fld wildcard" name="kp" value="<%=safe.htmlattr(kp)%>"></td>
            </tr>
            <!-- bes_bestelopdr_item_opmerking/omschrijv -->
            <tr class="secsearch">
              <td class="label"><label for="opm"><%=L("lcl_bes_item_comment")%></label></td>
              <td><input type="text" class="fld wildcard" name="opm" value="<%=safe.htmlattr(opm)%>"></td>
            </tr>
<% SEARCH_BLOCK_END();
SEARCH_BLOCK_START({wide: true}); %>
        <!-- Statuses -->
        <tr class="primsearch">
          <td colspan="2">
            <div id="statusboxes">
            <nobr>
              <label><%=L("lcl_bes_Bes_status")%></label>
              <input type="checkbox" class="fldopdropen" name="opdrOpen" id="opdrOpen" onClick="checkCheckboxesOpdr();" value="1" <%=opdrOpen? "checked" : ""%>>
              <label for="opdrOpen"><%=L("lcl_bes_chek1")%></label>
              <input type="checkbox" class="fldopdrdelivered" name="opdrDelivered" id="opdrDelivered" onClick="checkCheckboxesOpdr();" value="1" <%=opdrDelivered? "checked" : ""%>>
              <label for="opdrDelivered"><%=L("lcl_bes_chek2")%></label>
              <input type="checkbox" class="fldopdrrej" name="opdrRej" id="opdrRej" onClick="checkCheckboxesOpdr();" value="1" <%=opdrRej? "checked" : ""%>>
              <label for="opdrRej"><%=L("lcl_bes_chek5")%></label>
              <input type="checkbox" class="fldopdrclosed" name="opdrClosed" id="opdrClosed" onClick="checkCheckboxesOpdr();" value="1" <%=opdrClosed? "checked" : ""%>>
              <label for="opdrClosed"><%=L("lcl_bes_chek4")%></label>
            </nobr>
          </td>
        </tr>
<%    SEARCH_BLOCK_END();
      SIMPLE_BLOCK_START();
      var buttons = [{ title: L("lcl_overview_list"), action: "document.forms.u2.submit();", importance: 1, icon: "fa-clipboard-list"}];
      if (!frontend)
            buttons.push({ title: L("lcl_shared_more"), action: "iface_toggleSecondarySearchblock();",  id: "btnMoreLess", importance: 3, icon: "fa-chevron-right"});
      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(); %>
