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

    File:           prs_impersonate.asp
    Description:
    Parameters:     prs_key (required)

    Context:
    Note:

*/
var JSON_Result = true;
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../aut/login.inc" -->
<!-- #include file="prs.inc" -->
<%
    protectRequest.validateToken();

    user.checkAutorisation("WEB_PRSSYS");
    if (!S("prs_allow_impersonate"))
         user.checkAutorisation("WEB_FACTAB");

    var prs_key  = getFParamInt("prs_key");
    var prs_reason = getFParam("prs_reason");
    var other = new Perslid(prs_key);
    if (other.checkAutorisation("WEB_FACFAC", true))
        abort_with_warning("Sorry, someone with WEB_FACFAC autorisation cannot be impersonated");

    Session("org_user_key") = user_key;
    var impersonatestart = new Date();
    Session("org_user_key_ts") = impersonatestart.getTime();

    // track eerst dat de beheerder (tijdelijk) uitlogt
    shared.trackaction("PRSLOG", user_key, L("lcl_impersonatelog_start").format(other.naam(), toDateTimeString(impersonatestart, true, true), prs_reason, Session("ASPFIXATION").slice(-6)));
    // en vervolgens bij de impersonated dat de beheerder inlogt
    var naam = user.naam();
    if (Session("fclt_realuser"))
        naam += " (" + Session("fclt_realuser") + ")";
    shared.trackaction("PRSLOG", prs_key, L("lcl_impersonated_start").format(naam, toDateTimeString(impersonatestart, true, true), prs_reason, Session("ASPFIXATION").slice(-6)));
    doLogin(prs_key);

    result = { success: "true" };
    Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
