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

    File:           fac_show_faq.asp
    Description:    show detailed information of an faq

    Parameters:     faq_key

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../fac/fac.inc" -->
<!-- #include file="faq_flexkenmerk.inc" -->

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

// Autorisatie controle komt als wel level weten

var faq_key = getQParamInt("faq_key");

var sql = "SELECT fac_faq_question"
        + "     , fac_faq_answer"
        + "     , fac_faq_source"
        + "     , fac_faq_url"
        + "     , fac_faq_level"
        + "     , fac_faq_datum"
        + "     , fac_faq_lang"
        + "     , fac_faq_hint"
        + "     , fac_faq_displaymode"
        + "     , prs_perslid_key"
        + "  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 question = oRs("fac_faq_question").Value;
var answer = oRs("fac_faq_answer").Value;
var source = oRs("fac_faq_source").Value;
var url = oRs("fac_faq_url").Value;
var level = oRs("fac_faq_level").Value;
var perslidkey = oRs("prs_perslid_key").Value;
var datum = oRs("fac_faq_datum").Value;
var lang = oRs("fac_faq_lang").Value;
var hint = oRs("fac_faq_hint").Value;
var displaymode = oRs("fac_faq_displaymode").value;
var mustProf = (level & 1) == 0; // Alleen professionals

oRs.close();

var authparamsFAQUSE = user.checkAutorisation("WEB_FAQUSE", true); // Frontend mag ingevoerde items bekijken
var authparamsFAQFOF = user.checkAutorisation("WEB_FAQFOF", true); // Frontoffice mag items aanmaken en bewerken
var authparamsFAQBOF = user.checkAutorisation("WEB_FAQBOF", true); // Backoffice mag ingevoerde items publiceren (publicatie datum zetten/aanpassen)

user.auth_required_or_abort(authparamsFAQBOF || authparamsFAQFOF || (!mustProf && authparamsFAQUSE));

var canWriteFAQFOF = (authparamsFAQFOF && authparamsFAQFOF.PRSwritelevel < 9 && authparamsFAQFOF.ALGwritelevel < 9) || false;
var canWriteFAQBOF = (authparamsFAQBOF && authparamsFAQBOF.PRSwritelevel < 9 && authparamsFAQBOF.ALGwritelevel < 9) || false;
var isProf = canWriteFAQFOF || canWriteFAQBOF;
var canChange = canWriteFAQBOF || (canWriteFAQFOF && datum == null)

%>

<html>
  <head>
<%
    FCLTHeader.Generate();
%>
    <script type="text/javascript">
      function CopyToClipboard(ta)
      {
        ta.focus();
        ta.select();
        CopiedTxt = document.selection.createRange();
        CopiedTxt.execCommand("Copy");
        ta.select();
      }


      function faq_change()
      {
        if (FcltMgr.startEdit(window))
          window.location.href = "fac_edit_faq.asp?faq_key=<%=faq_key%>";
      }

      function faq_delete()
      {
        if (confirm(L("lcl_R_U_sure")))
        {
          var data = { faq_key: <%=faq_key%>
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("faq_delete.asp",
                 data,
                 FcltCallbackClose,
                 "json");
        }
      }
      jQuery(document).ready(function()
             {
               $('textarea').resize(function () { FcltMgr.resized(window) } );
               $('textarea').autogrow();
             });
    </script>
  </head>

  <body id="showbody">
<%
    var buttons = [];

    if (isProf)
    {
      if (canChange)
        buttons.push({title: L("lcl_change"), action: "faq_change()", icon: "wijzigen.png"});
      buttons.push({title: L("lcl_delete"), action: "faq_delete()", icon: "delete.png"});
    }

    IFRAMER_HEADER(L("lcl_faq_kennisitem"), buttons);
%>
    <div id="edit">
      <form name="u2"  onSubmit="return false;">
<%
        BLOCK_START("mldFaqedit", L("lcl_faq_item"));
        ROTEXTAREATR("fldtxt", L("lcl_faq_question"), question, {id: "fac_question", html: "rows='3' maxlength='4000'"});
        if (isProf)
        {   // Expliciet RW (met html: "readonly") om te forceren dat het een
            // textarea blijft ipv gerenderd als een DIV. Anders werkt CopyToClipboard niet
            RWTEXTAREATR("fac_answer", "fldtxt", L("lcl_faq_answer")+"<a onclick='CopyToClipboard($(\"#fac_answer\")[0])'>"+L("lcl_faq_kopieer")+"</a>", answer, { html: "rows='3' readonly maxlength='4000'"});
        }
        else
            ROTEXTAREATR("fldtxt", L("lcl_faq_answer"), answer);
        ROTEXTAREATR("fldtxt", L("lcl_faq_hint"), hint, { suppressEmpty: true } );
        BLOCK_END();

        if (isProf)
        {
            BLOCK_START("mldInfo", L("lcl_faq_itemadm"));
            ROFIELDTR("fld",          L("lcl_faq_level"),   fac.getfaqleveltext(level));
            ROCHECKBOXTR("fldcheck",  L("lcl_faq_displaymode"), displaymode);
            ROFIELDTR("fld",          L("lcl_faq_bron"),   source);
            ROFIELDTR("fld",          L("lcl_faq_link"),   url, { infoPointer: {Url: url, Title: L("lcl_faq_item"), NewWindow: true}, suppressEmpty: true});
            FCLTpersoonselector("sgPers",
                                "sgPers",
                                { perslidKey: perslidkey,
                                  label: L("lcl_faq_ingevoerd"),
                                  moreinfo: true,
                                  readonly: true
                                });
            ROFIELDTR("fld",          L("lcl_faq_datum"),  toDateString(datum));
            ROFIELDTR("fld",          L("lcl_faq_lang"),   lang, {suppressEmpty: true});
            BLOCK_END();
        }

        BLOCK_START("faqFlex2", L("lcl_faq_flexblok"));
        generateFlexKenmerkCode ({ faq_key: faq_key,
                                       reado  : true,
                                       flexcolumns: S("faq_flexcolumns")
                                     });
        BLOCK_END();
%>
      </form>
    </div>
  </body>
</html>
