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

    File:           mld_faq.asp
    Description:    (Modal)dialoog om kennisbankitems aan melding te kunnen koppelen
    Parameters:     stdm_key
    Context:        Als net een melding is gekozen komt een popup met faq's
    Note:           Als je zowel FO als FE rechten hebt zie je alle faq's
                    voor deze melding
*/
%>

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

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

var mld_stdmelding_key = getQParamInt("stdm_key");

var authparamsFOF = user.checkAutorisation("WEB_FAQFOF", true); // ziet (ook) FO-items
var authparamsUSE = user.checkAutorisation("WEB_FAQUSE", true); // ziet (ook) FE-items
user.auth_required_or_abort(authparamsUSE || authparamsFOF);
%>

<html>
   <head>
<%    FCLTHeader.Generate() %>
      <script type='text/javascript'>
         $(document).ready(function ()
                           {
                             $(".faqvraag").click(function() {
                                $(this).siblings().last().toggle();
                                FcltMgr.resized();
                             });
                           }
         );

         function faqSolvedCallback(data, textStatus)
         {
           FcltMgr.closeDetail(window, { accept: true });
         }

         function faqSolved(faq_key)
         { // Increment the rank of a FAQ (kennisbankitem)
           var data = {faq_key: faq_key};
           <% protectRequest.dataToken("data"); %>
           $.ajax({ type: "POST",
                    url: "../mld/mld_increment_rank.asp",
                    data: data,
                    success: faqSolvedCallback,
                    datatype: "json",
                    async: false
                  });
         }
      </script>
   </head>
   <body class="modal" id="mod_faq">
      <div id="faqhead"><%=L("lcl_faq_mld_1")%></div>
      <div id="faqsubhead"><%=L("lcl_faq_mld_2")%></div>
      <ul id="faqanswerlist">
<%
    var faq_bits = 0;
    if (authparamsFOF)
        faq_bits += 2;
    if (authparamsUSE)
        faq_bits += 1;

      var sql = "SELECT ff.fac_faq_key, fac_faq_question, fac_faq_answer, fac_faq_url, fac_faq_level"
             + "  FROM fac_faq ff"
             + "     , mld_stdmeldingfaq sf"
             + " WHERE ff.fac_faq_key = sf.fac_faq_key"
             + "   AND (sf.mld_stdmelding_key = " + mld_stdmelding_key
             + "        OR (sf.mld_stdmelding_key IS NULL"
             + "            AND sf.ins_discipline_key = (SELECT mld_ins_discipline_key"
                                                      + "  FROM mld_stdmelding "
                                                      + " WHERE mld_stdmelding_key = " + mld_stdmelding_key + ")))"
             + "   AND BITAND(fac_faq_level," + faq_bits + ") <> 0"
             + "   AND fac_faq_datum < SYSDATE"
             + "   AND (fac_faq_lang = " + safe.quoted_sql(user_lang) + " OR fac_faq_lang IS NULL)"
             + " ORDER BY fac_faq_rank DESC NULLS LAST"
             + "        , fac_faq_datum DESC"
             + "        , fac_faq_question";
      var oRs = Oracle.Execute(sql);
      var faq_url = '';
      while (!oRs.eof) {
%>
         <li>
            <div class="faqvraag"><a name="<%=oRs("fac_faq_key").value%>"><%=safe.html(oRs("fac_faq_question").value)+L("lcl_faq_mld_klik")%></a></div>
            <div class="faqantwoord">
               <%=safe.html(oRs("fac_faq_answer").value)%><br/>
<%      if (oRs("fac_faq_url").value)
        {
          fac_url = oRs("fac_faq_url").value;
          var arr = fac_url.split("|");
          hurl = arr[0];
          hlnk = arr.length>1?arr[1]:hurl;

          if (hurl.slice(0,4) == "http") // extern
            hurl = hurl;
          else // in cust subdir
            hurl = custpath + "/" + hurl;
%>             <a href="<%=safe.htmlattr(hurl)%>" target="_new"><%=safe.html(hlnk)%></a><br/>
<%      } %>
               <div id="faqsolved" onClick="faqSolved(<%=oRs("fac_faq_key").value%>);" class="ref"><div class="button">
                  <img class="opgelost"
                       title="<%=L("lcl_faq_mld_3")%>"
                       alt="<%=L("lcl_faq_mld_3")%>"
                       src="../pictures/accept.png">
                  </img><%=L("lcl_faq_mld_3")%></div>
            </div>
            </div>
         </li>
<%
         oRs.MoveNext();
      }

      oRs.close();
%>
      </ul>
      <div id="faqfoot"><%=L("lcl_faq_mld_4")%></div>
<%
      var buttons = [{title: L("lcl_faq_mld_5"), icon: "delete.png", action: "FcltMgr.closeDetail(window, { cancel: true })"}];
      CreateButtons(buttons, {showIcons: true});
%>
   </body>
</html>
