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

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

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

var job_info = job.func_enabled_job();
var urole       = getQParamSafe("urole", (job_info.has_PRSSYS ? "" : "fe"));
var autosearch  = getQParamInt("autosearch", (urole == "fe" ? 1 : 0)) == 1;
var prs_prskey  = getQParamInt("prs_prskey", (urole == "fe" ? user_key : -1));
var template    = getQParamInt("template", 0);
var urole       = getQParam("urole", "");

user.auth_required_or_abort(job_info.canReadAny);

%>
<html>
  <head>
    <%  FCLTHeader.Generate(); %>
      <script type="text/javascript">
          $(function() {<% if (autosearch) { %> document.forms.u2.submit();<%}%>});
      </script>
  </head>
  <body id="searchbody">
    <form name="u2" target="workFrame" action="job_search_list.asp" method="get">
      <% SEARCH_PAGE_START({ header: L("lcl_filterblok") });
      SEARCH_BLOCK_START();%>
                <input type="hidden" id="template" name="template" value="<%=template%>">
                <input type="hidden" id="urole" name= "urole" value="<%=urole%>"> 
                <tr>
                  <td class="label"><label for="act_key"><%=(template == 1 ? L("lcl_job_template_nr") : L("lcl_job_nr"))%></label></td>
                  <td><input type="text" class="fldshort" 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,
                                      readonly: urole === "fe"
                                    });
                if (template != 1) {
                  var union_all   = " UNION ALL ";
                  var sub_sql     = "";
                  var rtype_sql   = "";

                  if (job_info.canBESRead) {
                    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 (job_info.canMLDRead) {
                    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 (job_info.canORDRead) {
                    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")
                              });
                }
SEARCH_BLOCK_END();
SEARCH_BLOCK_START();
                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_MLDUSE', '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 in ('WEB_BESUSE', '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")
                            });
                if (template != 1) {
                  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")
                              });
                }
               %>
<%      SEARCH_BLOCK_END();

        var buttons = [{title: L("lcl_overview_list"), action: "document.forms.u2.submit();", id:"bSearch", icon: "fa-clipboard-list" }];
        SIMPLE_BLOCK_START();
          CreateButtons(buttons, { entersubmit: 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(); %>
