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

    File:               prs_perslid_qr.asp
    Description:        Genereert & toont de persoonlijk QR-authenticatiecode van de ingelogde user
    Parameters:
    Context:
    Note:
*/ %>

<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc" -->
<%
    FCLTHeader.Requires({plugins:["jQuery"], js: []})

    if (S("qrc_enable") != 1)
        shared.simpel_page(L("lcl_no_auth"));

    // verwijder oudere bookmarks, we ondersteunen maximaal één pending
    sql = "DELETE fac_bookmark"
        + " WHERE fac_bookmark_naam = 'PRS QR code indentificatie'"
        + "   AND prs_perslid_key = " + user_key;
    Oracle.Execute(sql);

    // /default.asp?session=fhfhIPFUHEIhFE in de QR-code zou genoeg zijn
    // maar (richtlijnen) qrcodes gaan altijd via een short-url/ bookmark
    bookmarkId = shared.random(12); // Toch maar 5 minuten geldig, en sommige mensen moeten overtikken
    sql = "INSERT INTO fac_bookmark ( "
        + "   fac_bookmark_id, "
        + "   prs_perslid_key, "
        + "   fac_bookmark_naam, "
        + "   fac_bookmark_path, "
        + "   fac_bookmark_query, "
        + "   fac_bookmark_flags, "
        + "   fac_bookmark_expire ) "
        + " VALUES ( "
        +     safe.quoted_sql(bookmarkId) + ", "
        +     user_key + ", "
        + "   'PRS QR code indentificatie', "
        + "   'appl/prs/prs_perslid_qr_confirm.asp', " // via de root
        +     safe.quoted_sql("sso=0&user_key=" + user_key) + ", " // is straks beschermd met HMAC
        +     "0," // Zelfs onzichtbaar voor PRSSYS
        + "   sysdate+("+S("qr_auth_expire")+"/24/60) )"
    Oracle.Execute(sql);

    var proto = (Request.ServerVariables("SERVER_PORT") == "443")?"https":"http";
    var sitenoroot = proto + "://" + Request.ServerVariables("SERVER_NAME");
    var site = sitenoroot + rooturl;
    var bookmark = "/?sso=0&u=" + bookmarkId;
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>

    <script type='text/javascript'>
        function email_link(bmid)
        {
            var data = {bmid: "<%=safe.jsstring(bookmarkId)%>"};
            <% protectRequest.dataToken("data"); %>
            $.post("prs_perslid_qr_mail.asp",
                    data,
                    FcltCallback, "json");
        }
        function clear_sessions(bmid)
        {
            FcltMgr.confirm(L("lcl_qrc_auth_clear"), function() {
                var data = {};
                <% protectRequest.dataToken("data"); %>
                $.post("prs_perslid_clear_sessions.asp",
                    data,
                    FcltCallback, "json");
            });
        }
    </script>
  </head>

  <body class="fclt-modal" id="mod_authQR">
    <% MODAL_START();
    MODAL_BLOCK_START();%>
    <div id="myQR"><%=L("lcl_qrc_auth_header").format(safe.html(user.prs_perslid_email()), safe.html(site + bookmark), S("qr_auth_expire"))%></div>
  <center><img alt="<%=L("lcl_fac_qrcode")%>" class="QRC" src='../shared/qrcode.asp?nocache=1&size=4&text=<%=Server.URLEncode(bookmark + "&no302=1")%>'><br>
    </center>

    <div id="footer"><%=L("lcl_qrc_auth_footer")%></div>
    <% MODAL_BLOCK_END();
    MODAL_END();  %>
  </body>
</html>
<% ASPPAGE_END(); %>
