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

    File:        fac_faq_search.asp (FSN#15947)
    Description: Zoekt in FAQ
    Parameters:  -
    Context:
    Note:
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/faqselector.inc" -->
<%
FCLTHeader.Requires({ plugins:["kenmerk"],
                      js: ["../FAC/fac_faq_search.js"]
                    });
var sstring = getQParam("s","");
var urole = getQParamSafe("urole", "fe");
var fronto = (urole == "fo");
var backo = (urole == "bo");
var minfo = (urole == "mi");
var frontend = (urole == "fe" || (!fronto & !backo & !minfo));
var autosearch = getQParamInt("autosearch", -1) == 1;
var disc_key_arr = getQParamIntArray("disc_key_str", []); // Productgroep
var stdm_arr = getQParamIntArray("stdm_str", []); // Melding (Stdmelding)

if (disc_key_arr.length == 0 && stdm_arr.length != 0)
{
  var sql = "SELECT stdm.mld_ins_discipline_key FROM mld_stdmelding stdm WHERE stdm.mld_stdmelding_key = " + stdm_arr.join(",")
  oRs = Oracle.Execute(sql);
  while (!oRs.eof)
  {
    disc_key_arr[disc_key_arr.length] = oRs("mld_ins_discipline_key").Value;
    oRs.MoveNext();
  }
}


var authparamsBOF = user.checkAutorisation("WEB_FAQBOF", true); // ziet alles
var authparamsFOF = user.checkAutorisation("WEB_FAQFOF", true); // ziet ook FO-items (en eigen items)
var authparamsUSE = user.checkAutorisation("WEB_FAQUSE", true); // ziet ook FO-items (en eigen items)

user.auth_required_or_abort(authparamsBOF || authparamsFOF || authparamsUSE);

sql= "SELECT 1 FROM mld_stdmeldingfaq WHERE ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anymldfaq = !oRs.eof;
oRs.close();

%>
<html>
  <head>
   <% FCLTHeader.Generate() %>
      <script type="text/javascript">
        function doSubmit()
        {
          if (!validateForm("u2"))
            return false;
          // Submitten met kenmerken
          doSubmitWithKenmerken();
        }

<%   if (autosearch && (sstring != "" || disc_key_arr.length != 0 || stdm_arr.length != 0)) { %>
       $(document).ready(function (){doSubmit()} )
<%   } %>

        function myModal()
        {
          var url = "load_kenmerk.asp?act_key=-1"
                  + "&urole=<%=urole%>"
                  + "&advanced=1";
          var titel = "<%=L("lcl_faq_kenmerken")%>";
          showKenmerkModal(url, titel);
        }


      </script>

  </head>
  <body id="searchbody">
    <div id="search">
      <form name="u2" method="get" action="fac_faq_list.asp" target="workFrame">
<%      BLOCK_START("searchtable", L("lcl_fac_filterblok"));%>
        <tr>
          <td class="searchkolom1">
            <input type="hidden" name="urole" value="<%=urole%>">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%            RWFIELDTR ('searchtext', 'fld', L("lcl_search_diff_fields"), sstring);
             RWCHECKBOXTR("wholeword", "fldwholeword", L("lcl_faq_wholeword"), false );


              if (authparamsBOF && anymldfaq)
              {
                // <!-- Productgroep -->
                // LET OP!!
                // De options van deze selector wordt on-change dynamisch vervangen door ../shared/loadDisc.asp!
                // Wat hier staat is dus alleen de initiele situatue.
                // SQL-queries uit loadDisc:

                var discsql = " SELECT m1.ins_discipline_key"
                        + ", CASE "
                          + " WHEN sd.ins_srtdiscipline_prefix IS NULL"
                          + " THEN ''"
                          + " ELSE sd.ins_srtdiscipline_prefix || '-'"
                          + " END"
                          + " || "+ lcl.xsqla('m1.ins_discipline_omschrijving', 'm1.ins_discipline_key')
                        + " 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 ms.mld_stdmelding_verwijder IS NULL)"
                        + " AND m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key(+)"
                        + (disc_key_arr.length != 0
                          ? " AND m1.ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
                          : "")
                        + " AND EXISTS (SELECT ''"
                          + "             FROM mld_stdmeldingfaq f"
                          + "            WHERE f.ins_discipline_key = m1.ins_discipline_key)" // Alleen waar faqs van zijn
                        + " ORDER BY 2"

                FCLTselector("discmulti",
                             discsql,
                             { initKey: disc_key_arr.join(","),
                               label: L("lcl_vakgroup"),
                               onChange: 'updateStdm("' + urole + '");',
                               trclass: "primsearch",
                               multi: true,
                               emptyOption: (disc_key_arr.length==0? L("lcl_all") : null) // Als een disc_key_arr is meegegeven dan geen lege optie
                             })

                // <!-- Melding (Stdmelding) -->
                // LET OP!!
                // deze selector wordt on-change dynamisch en totaal vervangen door ../Shared/loadStdmelding.asp!
                // Wat hier staat is dus alleen de initiele situatie.
                // SQL-queries uit loadStdmelding:

                var stdmsql = "SELECT stdm.mld_stdmelding_key"
                            + "     , " + lcl.xsqla('stdm.mld_stdmelding_omschrijving', 'stdm.mld_stdmelding_key')
                            + "     , stdm.mld_ins_discipline_key"
                            + " FROM mld_stdmelding stdm"
                            + " WHERE mld_stdmelding_verwijder IS NULL"
                            // Vervallen stdmeldingen niet tonen
                            + "   AND (stdm.mld_stdmelding_vervaldatum IS NULL"
                            + "        OR stdm.mld_stdmelding_vervaldatum > SYSDATE)"
                            + (frontend
                              ? " AND stdm.mld_stdmelding_notfrontend = 0"
                              : "")
                            + (disc_key_arr.length != 0
                              ? " AND stdm.mld_ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
                              : "")
                            + " AND EXISTS (SELECT ''"
                              + "             FROM mld_stdmeldingfaq f"
                              + "            WHERE (f.mld_stdmelding_key = stdm.mld_stdmelding_key"
                              + "                   OR (f.ins_discipline_key = stdm.mld_ins_discipline_key"
                              + "                       AND f.mld_stdmelding_key IS NULL)))" // Alleen waar faqs van zijn
                            + " ORDER BY " + lcl.xsql('stdm.mld_stdmelding_omschrijving', 'stdm.mld_stdmelding_key');

                FCLTselector("stdmmulti",
                             stdmsql,
                             { initKey: stdm_arr.length == 0? -1 : stdm_arr.join(","),
                               label: L("lcl_complain"),
                               trclass: "primsearch",
                               multi: true,
                               emptyOption: L("lcl_all")
                             });
              } %>
            </table>
          </td><!-- end column 1 -->
          <!-- Second column -->
          <td class="searchkolom2">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%
            if (!frontend)
            {
              // Zichtbaar voor (faq level)
              sql = "           SELECT 1,  " + safe.quoted_sql(L("lcl_faq_level1")) + " FROM DUAL"
                  + " UNION ALL SELECT 2,  " + safe.quoted_sql(L("lcl_faq_level2")) + " FROM DUAL"
                  + " UNION ALL SELECT 3,  " + safe.quoted_sql(L("lcl_faq_level3")) + " FROM DUAL"
              FCLTselector("fac_faq_level",
                           sql,
                           { initKey: -1,
                             label: L("lcl_faq_level"),
                             emptyOption: L("lcl_all")
                           });

              if (S("language_toggles").length > 0)
              {
                sql = "";
                for (var i = 0; i < S("language_toggles").length; i++)
                {
                  sql += (sql != ""? " UNION ": "") + "SELECT " + safe.quoted_sql(S("language_toggles")[i]) + ", " + safe.quoted_sql(S("language_toggles")[i]) + ", 2 FROM DUAL";
                }
                sql += " ORDER BY 3, 2";
                FCLTselector("fac_faq_lang",
                             sql,
                             { initKey: -1,
                               label: L("lcl_faq_lang"),
                               emptyOption: L("lcl_all")
                             });
              }
            }
%>

             </table>
          </td><!-- end column 1 or 2 -->
        </tr>
<%      BLOCK_END();
        var buttons =  [];
        buttons.push ( {title: L("lcl_search"),  action:"doSubmit()" } ); // Overzicht
        buttons.push ( {title: L("lcl_obj_advanced"),  action: "myModal()" } );

        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>
