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

     File:               bes_voorraad_search.asp
     Description:        Filterscherm voor overzicht voorraad bestellingen
     Parameters:         urole                Rol van de gebruiker (frontend, frontoffice, backoffice, management info)
                         disc                 Inkoop catalogus
     Globals:
     Context:
     Note:
*/ %>

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

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

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

var disc = getQParamInt("disc", -1); // Inkoop catalogus
var srtgroup = getQParamInt("srtgroup", -1); // groep
var srtdeel = getQParamInt("srtdeel", -1); // item (key voor select box)
var tebestellen = getQParamInt("tebestellen", 0) == 1; // Te bestellen
/***** End get webform parameters *****/

var autfunction = "";
switch(urole)
{
  case "fe": autfunction = "WEB_BESUSE";
             break;
  case "fo": autfunction = "WEB_BESFOF";
             break;
  case "bo": autfunction = "WEB_BESBOF";
             break;
  case "mi": autfunction = "WEB_BESBAC";
             break;
}

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

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

    <script type="text/javascript">
      function doSubmit()
      {
        document.forms.u2.submit();
      }
    </script>
  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" target="workFrame" action="bes_voorraad_search_list.asp" method="get">
<%    BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <input type="hidden" name="urole" value="<%=urole%>">
        <tr>
          <td class="searchkolom1"><!-- start column 1 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%          // <!-- Catalogus -->
            sql = "SELECT bd.ins_discipline_key"
                + ", "+ lcl.xsqla('bd.ins_discipline_omschrijving','bd.ins_discipline_key')
                + " FROM bes_discipline bd"
                + " WHERE bd.ins_discipline_verwijder IS NULL"
                + " AND bd.ins_discipline_key IN"
                  + " (SELECT dp.bes_ins_discipline_key_inkoop"
                  + " FROM bes_disc_params dp"
                  + " WHERE dp.bes_ins_discipline_key_inkoop IS NOT NULL)"
                + " AND ins_discipline_key IN"
                  + " (SELECT ins_discipline_key"
                  + " FROM fac_v_webgebruiker g"
                  + ", fac_functie f"
                  + " WHERE g.prs_perslid_key = " + user_key
                  + " AND f.fac_functie_key = g.fac_functie_key "
                  + " AND f.fac_functie_code = " + safe.quoted_sql(autfunction) + ")"
                + " ORDER BY upper("+ lcl.xsql('bd.ins_discipline_omschrijving','bd.ins_discipline_key') +")";
            FCLTselector("disc",
                         sql,
                         { initKey: disc,
                           label: L("lcl_bes_Catalogus"),
                           onChange: 'updateSrtGroup("' + autfunction + '");', // discChanged
                           trclass:"primsearch",
                           emptyOption: ""
                         });
                         %>

            <!-- Groep -->
<%          FCLTselector("srtgroup",
                         "", // sql: lege selectbox die onload wordt geladen
                         { initKey: srtgroup,
                           label: L("lcl_bes_srtgroup"),
                           onChange: 'updateSrtDeel("' + autfunction + '");', // srtgroupChanged
                           trclass: "secsearch",
                           emptyOption: ""
                         }); %>

            <!-- Item select box -->
<%          FCLTselector("srtdeelmulti",
                         "", // sql: lege selectbox die onload wordt geladen
                         { initKey: srtdeel,
                           label: L("lcl_bes_srtdeel"),
                           trclass: "secsearch",
                           emptyOption: ""
                         }); %>
            <script type="text/javascript">
              // Laad de groupen en de items
              // Selecteer eventueel de initiële groepen en items die meegegeven kunnen worden
              $(document).ready(function()
                                {
                                  updateSrtGroup("<%=autfunction%>", "<%=srtgroup%>", "<%=srtdeel%>");
                                });
            </script>
            </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td valign=top>
            <table>
            <!-- Zoektekst -->
            <tr class="primsearch">
              <td class="label"><label for="searchtekst"><%=L("lcl_search_diff_fields")%>:</label></td>
              <td>
                <input type="text" class="fldsrch wildcard" name="searchtekst" value="">
              </td>
            </tr>

            <!-- Statuses -->
            <tr class="primsearch">
              <td class="label"><label><%=L("lcl_bes_Bes_status")%>:</label></td>
              <td>
                <nobr>
                  <input type="checkbox" class="fldtebestellen" name="tebestellen" id="tebestellen" value="1" <%=tebestellen? "checked" : ""%>>
                  <label for="rfoNew"><%=L("lcl_bes_te_bestellen")%></label>
                </nobr>
              </td>
            </tr>
            </table>
          </td><!-- end column 2-->
        </tr>
        </table>
<%    BLOCK_END();

      var buttons =  [{ title: L("lcl_search"), action: "doSubmit();"}];
      if (!frontend)
        buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess" } );
      CreateButtons(buttons, { entersubmit: true} );
%>

      </form>
    </div> <!-- search -->

    <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>
