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

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

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

var autosearch = getQParamInt("autosearch", 0) == 1;
var prs_prskey = getQParamInt("prs_prskey", -1);

authparams = user.checkAutorisation("WEB_MLDBOF", true);

var MLDBOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
var MLDBOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

authparams = user.checkAutorisation("WEB_MLDFOF", true);

var MLDFOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
var MLDFOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

authparams = user.checkAutorisation("WEB_BESFOF", true);

var BESFOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
var BESFOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

if (!(MLDFOF_read || MLDFOF_write || BESFOF_read || BESFOF_write || MLDBOF_read || MLDBOF_write))
{
  Response.Write(L("lcl_no_auth"));
  Response.End();
}
%>

<html>
  <head>
    <%  FCLTHeader.Generate(); %>
          <script type="text/javascript">
          $(document).ready(function() {<% if (autosearch) { %> document.forms.u2.submit();<%}%>});
      </script>
  </head>
  <body id="searchbody">
    <div id="search">
      <form name="u2" target="workFrame" action="job_search_list.asp" method="get">
<%    BLOCK_START("searchtable", L("lcl_filterblok"));%>
          <tr>
            <td class="searchkolom1">
              <table>
                <tr>
                  <td class="label"><label for="act_key"><%=L("lcl_job_nr")%>:</label></td>
                  <td><input type="text" class="fldnum" id="act_key" name="act_key" value=""></td>
                </tr>
                <%
                FCLTpersoonselector("prs_prskey",
                                    "prs_prskey",
                                    { label: L("lcl_job_requestor"),
                                      whenEmpty: L("lcl_search_generic"),
                                      perslidKey: prs_prskey
                                    });
                var union_all   = " UNION ALL ";
                var sub_sql     = "";
                var rtype_sql   = "";

                if (BESFOF_read) {
                  sub_sql = " SELECT 1 rtable, " + safe.qL("lcl_job_1_bestelling") + " rtype_omschrijving FROM DUAL";
                  if (rtype_sql == "") {
                    rtype_sql = sub_sql;
                  } else {
                    rtype_sql = rtype_sql + union_all + sub_sql;
                  }
                }

                if (MLDFOF_read) {
                  sub_sql = " SELECT 2, " + safe.qL("lcl_job_2_melding") + " FROM DUAL";
                  if (rtype_sql == "") {
                    rtype_sql = sub_sql;
                  } else {
                    rtype_sql = rtype_sql + union_all + sub_sql;
                  }
                }

                if (MLDBOF_read) {
                  sub_sql = " SELECT 3, " + safe.qL("lcl_job_3_opdracht") + " FROM DUAL";
                  if (rtype_sql == "") {
                    rtype_sql = sub_sql;
                  } else {
                    rtype_sql = rtype_sql + union_all + sub_sql;
                  }
                }

                FCLTselector("rtype", rtype_sql,
                            {  label: L("lcl_job_type"),
                               emptyOption: "",
                               trclass: "primsearch",
                               whenEmpty: L("lcl_search_generic")
                            });
               %>
              </table>
            </td>
            <td valign=top>
              <table>
              <%
                var sql_dis_aut = ""
                    + "SELECT m1.ins_discipline_key"
                    + ", CASE "
                    + " WHEN COALESCE(sd.ins_srtdiscipline_prefix, '@') = '@'"
                     + " THEN ''"
                    + " ELSE sd.ins_srtdiscipline_prefix || '-'"
                    + " END || "+ lcl.xsql('m1.ins_discipline_omschrijving','m1.ins_discipline_key') +" ins_discipline_omschrijving"
                    + " FROM mld_v_aanwezigdiscipline m1, ins_srtdiscipline sd "
                    + " WHERE EXISTS (SELECT 'x' "
                    +                 "FROM mld_stdmelding ms "
                    +                 "WHERE M1.ins_discipline_key = ms.mld_ins_discipline_key"
                    +                 "  AND mld_stdmelding_verwijder IS NULL) "
                    + " AND m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key "
                    + " AND m1.ins_discipline_key IN ( "
                        + "SELECT ins_discipline_key FROM fac_v_my_disciplines "
                        + "WHERE fac_functie_code IN ('WEB_MLDFOF', 'WEB_ORDBOF') "
                        + "AND prs_perslid_key = " + user_key + " "
                        + ") "
                    + " ORDER BY 2";

               FCLTselector("cat", sql_dis_aut,
                            {  label: L("lcl_job_category"),
                               emptyOption: "",
                               trclass: "primsearch",
                               whenEmpty: L("lcl_search_generic")
                            });

               sql_prod_aut = "SELECT m1.ins_discipline_key, "+ lcl.xsqla('m1.ins_discipline_omschrijving','m1.ins_discipline_key')
                            + " FROM BES_v_aanwezigdiscipline m1 "
                            + " WHERE m1.ins_discipline_key IN ( "
                                  + "SELECT ins_discipline_key FROM fac_v_my_disciplines "
                                  + "WHERE fac_functie_code ='" + "WEB_BESFOF" + "' "
                                  + "AND prs_perslid_key = " + user_key + " "
                                  + ") "
                            + " ORDER BY 2";

               FCLTselector("prod", sql_prod_aut,
                            {  label: L("lcl_job_product"),
                               emptyOption: "",
                               trclass: "primsearch",
                               whenEmpty: L("lcl_search_generic")
                            });

               var stat_sql  = "SELECT 1 stat_key, "   + safe.qL("lcl_job_stat_1_inactief") + " rtype_omschrijving FROM DUAL"
                             + " UNION ALL SELECT 2, " + safe.qL("lcl_job_stat_2_actief") + " FROM DUAL"
                             + " UNION ALL SELECT 3, " + safe.qL("lcl_job_stat_3_1xoverslaan") + " FROM DUAL"
                             + " ORDER  BY 1 ";

               FCLTselector("stat", stat_sql,
                            {  label: L("lcl_job_status"),
                               emptyOption: "",
                               trclass: "primsearch",
                               whenEmpty: L("lcl_search_generic")
                            });
               %>
             </table>
          </td>
          </tr>
<%      BLOCK_END();

        var buttons =  [ {title: L("lcl_search"), action:"document.forms.u2.submit();", id:"bSearch" }];
        CreateButtons(buttons, { entersubmit: true });
%>
      </form>
    </div>
    <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>
