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

    File:               fac_alg_list.asp
    Description:        Show an overview of alg_locatie & alg_v_onroerendgoed items in list-form,
                        which meets with the given requirements
    Parameters:
    Context:            Include frame for fac_show_faq.
    Note:
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../MLD/mld.inc" -->
<!-- #include file="../fac/fac.inc" -->

<%
var outputmode = getQParamInt("outputmode", 0); //  0 = screen, 1 = print, 2 = excel etc
var showall    = getQParamInt("showall", 0) == 1;
var faq_key    = getQParamInt("faq_key");

var sql = "SELECT fac_faq_level"
        + "     , fac_faq_datum"
        + "  FROM fac_faq f"
        + " WHERE fac_faq_key = " + faq_key;
var oRs = Oracle.Execute(sql);
if (oRs.Eof)
    shared.record_not_found("<!--" + faq_key + "-->");

var level = oRs("fac_faq_level").Value;
var datum = oRs("fac_faq_datum").Value;
var mustProf = (level & 1) == 0; // Alleen professionals
oRs.close();

var this_faq = fac.func_enabled_faq(faq_key); // Wat heb ik zoal aan rechten op deze specifieke kennisbankitem.

user.auth_required_or_abort(this_faq.canReadAny);

var addButton = [];

%>
<html>
  <head>
<%  FCLTHeader.Generate({outputmode:outputmode}) %>
    <script type="text/javascript">
      var autosearch = 1; //automatisch laden van resultaat op search pagina

      function alg_algfaq()
      {
        FcltMgr.openModalDetail("../fac/fac_algfaq.asp?faq_key=<%=faq_key%>",
                                L("lcl_faq_algfaq"),
                                { callback: FcltMgr.reload });
      }

      function faq_newmld(row)
      {
        var faqData = JSON.parse(row.getAttribute("ROWDATA"));
        var locParam = "&loc_key="+faqData.loc_key;
        var bldParam = "&bld_key="+faqData.bld_key;
        var flrParam = "&flr_key="+faqData.flr_key;
        var roomParam = "&room_key="+faqData.room_key;
        FcltMgr.openDetail("appl/mld/mld_melding.asp?fromkb=1"+locParam+bldParam+flrParam+roomParam, L("lcl_add"));
      }

    </script>
  </head>
  <body id="listbody">
<%
  function fnrowData(oRs)
  {
    var locatie_key = oRs("loc_key").Value;
    var gebouw_key = oRs("bld_key").Value;
    var verdieping_key = oRs("flr_key").Value;
    var ruimte_key = oRs("room_key").Value;

    var data = {loc_key:locatie_key, bld_key:gebouw_key, flr_key:verdieping_key, room_key:ruimte_key };
    return JSON.stringify(data);
  }

  function fnScope(oRs)
  {
    switch (oRs("scope").Value)
    {
        case "L": return L("lcl_location");
        case "G": return L("lcl_building");
        case "T": return L("lcl_terra");
        case "V": return L("lcl_floor");
        case "R": return L("lcl_room");
    }
    return "";
  }

  if (this_faq.canChange)
  {
    addButton = [{icon: "fa-fclt-edit", title: L("lcl_change"), action: "alg_algfaq()"}];
  }

  var sql = "SELECT f.alg_algfaq_key"
          + "     , NVL(o.alg_type, 'L') scope"
          + "     , l.alg_locatie_code ||"
          + "       DECODE(o.alg_plaatsaanduiding, NULL, NULL, '-' || o.alg_plaatsaanduiding) plaats"
          + "     , l.alg_locatie_key loc_key"
          + "     , COALESCE(o.alg_gebouw_key, o.alg_terreinsector_key, -1) bld_key"
          + "     , COALESCE(o.alg_verdieping_key, -1) flr_key"
          + "     , COALESCE(o.alg_ruimte_key, -1) room_key"
          + "  FROM alg_algfaq f"
          + "     , alg_locatie l"
          + "     , alg_v_onroerendgoed_gegevens o"
          + " WHERE f.alg_locatie_key = l.alg_locatie_key"
          + "   AND f.alg_onroerendgoed_keys = o.alg_onroerendgoed_keys(+)"
          + "   AND f.fac_faq_key = " + faq_key;

  var rst = new ResultsetTable({ sql: sql
                               , keyColumn: "alg_algfaq_key"
                               , ID: "algfaqtable"
                               , noPrint: true
                               , showAll: showall
                               , rowData: fnrowData
                               , outputmode: outputmode
                               , title: L("lcl_faq_voor_alg")
                               , buttons: addButton
                               });

  rst.addColumn(new Column({caption: L("lcl_faq_alg_scope"), content: fnScope }));
  rst.addColumn(new Column({caption: L("lcl_plaatsgegevens"), content: "plaats" }));

  var cnt = rst.processResultset();
%>
    </body>
  </html>

<% ASPPAGE_END(); %>
