<% /*
     $Revision$
     $Id$
*/ %>

<%
faq = {
        alg_algfaq_info:
           function _alg_faq_info(loc_key, alg_key) {
               if (!loc_key || loc_key == -1) return; // Minimal requirement
               var sql = "SELECT NVL(o.alg_type, 'L') scope"
                       + "     , l.alg_locatie_code ||"
                       + "       DECODE(o.alg_plaatsaanduiding, NULL, NULL, '-' || o.alg_plaatsaanduiding) plaats"
                       + "  FROM alg_locatie l"
                       + "     , alg_v_onroerendgoed_gegevens o"
                       + " WHERE l.alg_locatie_key = o.alg_locatie_key(+)"
                       + "   AND l.alg_locatie_key = " + loc_key
                       + "   AND " + ((alg_key && alg_key != -1) ? alg_key : "-1") + " = o.alg_onroerendgoed_keys(+)";
                var oRs = Oracle.Execute(sql);
                var ret = { scope: oRs("scope").Value, plaats: oRs("plaats").Value };
                oRs.Close();
                return ret;
           },
        getkennisbank_sql:
            function (sqlSelect, sqlFrom, sqlWhere)
            { // Lever kennisbank items overzicht sql op.

               var fsql = "SELECT ff.fac_faq_key, "
                       + "       fac_faq_rank, "
                       + "       fac_faq_datum, "
                       + "       fac_faq_question, "
                       + "       fac_faq_answer,"
                       + "       fac_faq_answer2,"
                       + "       fac_faq_url, "
                       + "       fac_faq_level, "
                       + "       (SELECT COUNT (*)"
                       + "          FROM faq_kenmerk k"
                       + "         WHERE k.faq_kenmerk_verwijder IS NULL"
                       + "            OR k.faq_kenmerk_verwijder > SYSDATE) aantal_kenm"
                       + sqlSelect
                       + "  FROM fac_faq ff"
                       + sqlFrom
                       + " WHERE fac_faq_datum < SYSDATE"
                       + "   AND (ff.fac_faq_vervaldatum IS NULL OR ff.fac_faq_vervaldatum > SYSDATE)"
                       + "   AND (fac_faq_lang = " + safe.quoted_sql(user_lang) + " OR fac_faq_lang IS NULL)"
                           + " AND (fac_functie_key IS NULL"
                           + "     OR fac_functie_key IN "
                           + "             (SELECT fac_functie_key FROM fac_v_webgebruiker"
                           + "                WHERE prs_perslid_key = " + user_key + "))"
                       + sqlWhere;

                  fsql += " AND (    ff.faq_ins_discipline_key IN "
                        + "             (SELECT ins_discipline_key FROM fac_v_webgebruiker"
                        + "                WHERE prs_perslid_key = " + user_key
                        + "                  AND fac_functie_key = " + F("WEB_FAQBOF") + ")"
                        + "       OR BITAND (fac_faq_level, 2) = 2" // Zichtbaar frontoffice
                        + "          AND ff.faq_ins_discipline_key IN "
                        + "             (SELECT ins_discipline_key FROM fac_v_webgebruiker"
                        + "                WHERE prs_perslid_key = " + user_key
                        + "                  AND fac_functie_key = " + F("WEB_FAQFOF")
                        + "                  AND fac_gebruiker_prs_level_read < 9"
                        + "                  AND fac_gebruiker_alg_level_read < 9" + ")"
                        + "       OR BITAND (fac_faq_level, 1) = 1" // Zichtbaar frontend
                        + "          AND ff.faq_ins_discipline_key IN "
                        + "             (SELECT ins_discipline_key FROM fac_v_webgebruiker"
                        + "                WHERE prs_perslid_key = " + user_key
                        + "                  AND fac_functie_key = " + F("WEB_FAQUSE") + ")"
                        + "     )"

                   return fsql;
            }
      }

%>