<%@ 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/FlexFiles.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="./mld.inc" -->

<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: ["../fac/faq.js"] })

var ins_disc_key = getQParamInt("ins_disc_key", -1);
var stdm_key = getQParamInt("stdm_key", -1);
var typeopdr_key = getQParamInt("typeopdr_key", -1);
var afdeling_key = getQParamInt("afdeling_key", -1);
var loc_key = getQParamInt("loc_key", -1);
var alg_key_arr = getQParamIntArray("alg_key_arr", []);
var changed = getQParamInt("changed", 1);
var showall = getQParamInt("showall", 0);

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'>

         $(function ()
         {
           if (faqcount == 0)
              FcltMgr.closeDetail(window, { cancel: true });

           $(".faqvraag").click(function() {
              $(this).siblings().last().toggle();
              FcltMgr.resized();
           });
         });

         function showAnswer2(faq_key)
         {
           var x = $("#"+faq_key)[0];
           $(x.children[1]).css("display", "block");
           $(x.children[0]).remove();
           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: "../fac/faq_increment_rank.asp",
                    data: data,
                    success: faqSolvedCallback,
                    datatype: "json",
                    async: false
                  });
         }

      </script>
   </head>
   <body class="fclt-modal" id="mod_faq">
      <% MODAL_START();
      MODAL_BLOCK_START("mldFaq", L("lcl_faq_kennisbank"), {icon: "fa-book-open"});%>
      <h3 id="faqhead"><%=I("fa-exclamation-circle fa-2x")+"&nbsp;"+L("lcl_faq_mld_1")%></h3>
      <div id="faqsubhead"><%=L("lcl_faq_mld_2")%></div>

      <ul id="faqanswerlist">
<%
      var data = mld.faq_info(loc_key, alg_key_arr, ins_disc_key, stdm_key, typeopdr_key, afdeling_key, changed, true, null, showall);
      var oRs = data.fixed_faq;
%>
    <script>
        var faqcount = <%=(oRs.length == 0 ? 0 : 1)%>;
    </script>
<%
      for (i=0; i<oRs.length; i++)
      {
%>
         <li>
            <div class="faqvraag"><a name="<%=oRs[i].faq_key%>"><%=safe.html(oRs[i].question)%></a></div>
            <div class="faqantwoord fclthtml">
               <%=safe.fclthtml(oRs[i].answer, { "faqlink": true, "file_params": { "module": "FAQA", "key": oRs[i].faq_key }})%><br/>
<%
        if (oRs[i].answer2)
        {
%>
               <div class="faqanswer2" id="<%=oRs[i].faq_key%>"><a name="<%=oRs[i].faq_key%>" href="javascript:showAnswer2(<%=oRs[i].faq_key%>);"><%=L("lcl_faq_answer2")%></a>
                  <div class="faqantwoord fclthtml">
                     <%=safe.fclthtml(oRs[i].answer2, { "faqlink": true, "file_params": { "module": "FAQB", "key": oRs[i].faq_key }})%><br/>
                  </div>
               </div>
<%
        }

        if (oRs[i].hurl)
        {
%>             <a href="<%=safe.htmlattr(oRs[i].hurl)%>" target="_new"><%=safe.html(oRs[i].hlnk)%></a><br/>
<%      }
        else if (oRs[i].has_kenm)
        {
%>             <div class="faqlink"><a href="javascript:showFaq(<%=oRs[i].faq_key%>)"><%=L("lcl_more")%></a></div><br/>
<%      }
%>             <div id="faqsolved" onClick="faqSolved(<%=oRs[i].faq_key%>);" class="ref">
                 <span class="button">
                   <span title="<%=L("lcl_faq_mld_3")%>"><%=I("fa-check")%></span>
                   <%=L("lcl_faq_mld_3")%>
                 </span>
               </div>
            </div>
         </li>
<%
      }
%>
      </ul>
      <div id="faqfoot"><%=L("lcl_faq_mld_4")%></div>
<%
      MODAL_BLOCK_END();
      var buttons = [{title: (typeopdr_key > 0 ? L("lcl_faq_ord_5") : L("lcl_faq_mld_5")), icon: "fa-arrow-circle-right", action: "FcltMgr.closeDetail(window, { cancel: true })"}];
      SIMPLE_BLOCK_START();
      CreateButtons(buttons, {showIcons: true});
      SIMPLE_BLOCK_END();
      MODAL_END();
%>
   </body>
</html>
<% ASPPAGE_END(); %>
