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

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

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../aut/login.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/timezoneselector.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="prs_flexkenmerk.inc" -->
<!-- #include file="prs.inc" -->
<%
FCLTHeader.Requires({plugins:["jQuery"]})

var prs_key  = getQParamInt("prs_key");

// TODO: eigenlijk de ruimste van deze autorisaties nemen
var prsauthparams = prs.checkAutorisation(prs_key);
user.auth_required_or_abort(prsauthparams.readman || prsauthparams.readuse);

var sql = "SELECT p.prs_perslid_key, "
        + "       p.prs_srtperslid_key, "
        +         lcl.xsqla("sp.prs_srtperslid_omschrijving", "sp.prs_srtperslid_key") + ", "
        + "       p.prs_afdeling_key, "
        + "       p.prs_perslid_naam, "
        + "       p.prs_perslid_geslacht, "
        + "       p.prs_perslid_voorletters, "
        + "       p.prs_perslid_voornaam, "
        + "       p.prs_perslid_titel, "
        + "       p.prs_perslid_initialen, "
        + "       p.prs_perslid_nr, "
        + "       p.prs_perslid_dienstverband, "
        + "       COALESCE(p.prs_perslid_opp, sp.prs_srtperslid_opp) prs_perslid_opp, "
        + "       a.mld_adres_naam, "
        + "       p.prs_perslid_uurloon, "
        + "       p.prs_perslid_telefoonnr, "
        + "       p.prs_perslid_lang, "
        + "       p.prs_perslid_oslogin, "
        + "       p.prs_perslid_oslogin2, "
        + "       p.prs_perslid_opmerking, "
        + "       p.prs_perslid_apikey, "
        + "       p.prs_perslid_errorhandling, "
        + "       p.prs_perslid_otpsecret,"
        + "       p.prs_perslid_otpcounter,"
        + "       p.prs_perslid_ingangsdatum, "
        + "       p.prs_perslid_einddatum, "
        + "       d.prs_bedrijf_key, "
        + "       p.prs_perslid_tussenvoegsel, "
        + "       p.prs_perslid_email, "
        + "       p.prs_perslid_timezone, "
        + "       p.prs_perslid_lcid, "
        + "       p.prs_perslid_mobiel, "
        + "       (SELECT " + S("prs_kpn_string")
            + "      FROM prs_kostenplaats k"
            + "     WHERE prs_kostenplaats_key = COALESCE(p.prs_kostenplaats_key, d.prs_kostenplaats_key)"
            + "   ) kpl,"
        +         S("prs_dep_string") + " afdeling, "
        + "       p.prs_perslid_key_verantw, "
        + "       f.fac_profiel_limiet, "
        + "       f.fac_profiel_omschrijving,"
        + "       p.fac_profiel_key,"
        + "       p.prs_perslid_ingids,"
        + "       p.prs_perslid_visibility,"
        + "       p.prs_perslid_loglevel,"
        + "       (SELECT COUNT(pk.prs_perslidkostenplaats_key)"
        + "          FROM prs_perslidkostenplaats pk"
        + "         WHERE pk.prs_perslid_key = p.prs_perslid_key) aantal_pk,"
        + "       p.prs_perslid_systeemadres, "
        + "       COALESCE(p.prs_kostenplaats_key, d.prs_kostenplaats_key) kpl_key, "
        + "       p.prs_perslid_credentials_datum,"
        + "       p.prs_perslid_wachtwoord_hash,"
        + "       p.prs_perslid_inactief,"
        + "       p.prs_perslid_wachtwoord_exp, "
        + "       p.prs_perslid_externid, "
        + "       p.prs_perslid_externsyncdate"
        + "  FROM prs_perslid p, "
        + "       prs_v_afdeling d, "
        + "       prs_srtperslid sp, "
        + "       fac_profiel f, "
        + "       mld_adres a "
        + " WHERE p.prs_perslid_key = " + prs_key
        + "   AND p.prs_afdeling_key = d.prs_afdeling_key "
        + "   AND p.prs_srtperslid_key = sp.prs_srtperslid_key "
        + "   AND p.fac_profiel_key = f.fac_profiel_key(+)"
        + "   AND p.mld_adres_key = a.mld_adres_key(+)";
var oRs = Oracle.Execute(sql);

var prs_srtkey = oRs("prs_srtperslid_key").value;
var prs_srtoms = oRs("prs_srtperslid_omschrijving").value;
var prs_afdkey = oRs("prs_afdeling_key").value;
var prs_naam   = oRs("prs_perslid_naam").value;
var prs_geslacht = oRs("prs_perslid_geslacht").value;
var prs_vltr   = oRs("prs_perslid_voorletters").value;
var prs_vrnaam = oRs("prs_perslid_voornaam").value || "";
var prs_titel  = oRs("prs_perslid_titel").value;
var prs_ini    = oRs("prs_perslid_initialen").value;
var prs_nr     = oRs("prs_perslid_nr").value;
var prs_dnst   = oRs("prs_perslid_dienstverband").value;
var prs_opp    = oRs("prs_perslid_opp").value;
var mld_adres  = oRs("mld_adres_naam").value;
var prs_uurln  = oRs("prs_perslid_uurloon").value;
var prs_telnr  = oRs("prs_perslid_telefoonnr").value;
var prs_lang   = oRs("prs_perslid_lang").value;
var prs_oslog  = oRs("prs_perslid_oslogin").value;
var prs_oslog2 = oRs("prs_perslid_oslogin2").value;
var prs_opm    = oRs("prs_perslid_opmerking").value;
var prs_apikey = oRs("prs_perslid_apikey").value;
var prs_errorhandling = oRs("prs_perslid_errorhandling").value;
var prs_ingdat = new Date(oRs("prs_perslid_ingangsdatum").value);
var prs_enddat = oRs("prs_perslid_einddatum").value!=null?new Date(oRs("prs_perslid_einddatum").value):null;
var prs_bdrkey = oRs("prs_bedrijf_key").value;
var prs_tussen = oRs("prs_perslid_tussenvoegsel").value;
var prs_email  = oRs("prs_perslid_email").value;
var prs_tz     = oRs("prs_perslid_timezone").value;
var prs_lcid   = oRs("prs_perslid_lcid").value;
var kpl        = oRs("kpl").value;
var kpl_key    = oRs("kpl_key").value;
var afdeling   = oRs("afdeling").value;
var prs_mobiel = oRs("prs_perslid_mobiel").value;
var prs_bdrkey = oRs("prs_bedrijf_key").value;
var fac_prolim = oRs("fac_profiel_limiet").value;
var fac_proms  = oRs("fac_profiel_omschrijving").value;
var fac_prokey = oRs("fac_profiel_key").value;
var ingids     = oRs("prs_perslid_ingids").value == 1;
var visibility = oRs("prs_perslid_visibility").value;
var loglevel   = oRs("prs_perslid_loglevel").value;
var aantal_pk  = oRs("aantal_pk").value;
var otpsecret  = oRs("prs_perslid_otpsecret").Value;
var otpcounter = oRs("prs_perslid_otpcounter").Value;
var systeemadres = oRs("prs_perslid_systeemadres").value;  /* show-only */
var prs_creddat = oRs("prs_perslid_credentials_datum").value!=null?new Date(oRs("prs_perslid_credentials_datum").value):null;
var haspw       = oRs("prs_perslid_wachtwoord_hash").Value != null;
var prs_credexp = oRs("prs_perslid_wachtwoord_exp").value!=null?new Date(oRs("prs_perslid_wachtwoord_exp").value):null;
var prs_inactief = oRs("prs_perslid_inactief").value!=null?new Date(oRs("prs_perslid_inactief").value):null;
var verantw_key = oRs("prs_perslid_key_verantw").value;
var externid    =  oRs("prs_perslid_externid").value;
var externsyncdate = oRs("prs_perslid_externsyncdate").value;

oRs.Close();

var thisPrs = prs.prs_perslid(prs_key, { withWL: true, withPhoto: true }); // geeft ook alle informatie
var prs_user = new Perslid(prs_key);

// Persoon toevoegen aan 'reserveerbare delen'.
var res_authparams = user.checkAutorisation("WEB_RESMSU", true);
var res_deel_key = -1;
if (res_authparams)
{
    // Is dit deel al reserveerbaar?
    var sql = "SELECT res_deel_key"
            + "  FROM res_deel"
            + " WHERE res_deel_verwijder IS NULL"
            + "   AND res_prs_perslid_key = " + prs_key;
    var oRs = Oracle.Execute(sql);
    if (!oRs.eof)
      res_deel_key = oRs("res_deel_key").Value;
    oRs.Close();
}

%>
<html>
  <head>
<%  FCLTHeader.Generate();
    var xfunc = user.func_enabled("*", null, null, prs_key);
%>
    <script  type="text/javascript" >
      function prs_change()
      {
          if (FcltMgr.startEdit(window))
              window.location.href = "prs_edit_perslid.asp?prs_key=<%=prs_key%>"
      }
      function prs_delete()
      {
          FcltMgr.confirm(L("lcl_prs_del_txt_perslid"), function() {
              var data = {
                  key: <%=prs_key%>,
                  level: "P"
              };
              <% protectRequest.dataToken("data"); %>
              $.post("prs_delete.asp",
                  data,
                  FcltCallbackClose,
                  "json");
          });
      }
      function prs_reactivate()
      {
        var data = { prs_key: <%=prs_key%>
                   , reactivate: 1
                   };
                   console.log(data);
        <% protectRequest.dataToken("data"); %>
        $.post( "prs_perslid_clear.asp"
              , data
              , FcltCallbackRefresh
              , "json"
              );

      }
      function prs_substitute()
      {
          var url = "../prs/prs_perslid_substitutes.asp?pkey=<%=prs_key%>";
          FcltMgr.openModalDetail(url, L("lcl_prs_frame_substitutes"), { callback: FcltCallbackRefresh });
      }
      function prs_changepwd()
      {
          var url = "../prs/pchange.asp?prs_key=<%=prs_key%>";
          FcltMgr.openModalDetail(url, L("lcl_password_link"), { callback: FcltMgr.reload });
      }

      function prs_showotp()
      {
            var url = "../prs/prs_perslid_otp.asp?prs_key=<%=prs_key%>";
            FcltMgr.openModalDetail(url, L("lcl_otp_authenticatie"));
      }

      function prs_approve()
      {
          FcltMgr.confirm(L("lcl_prs_approve"), function() {
              var data = {
                  prs_key: <%=prs_key%>
              };
              protectRequest.dataToken(data);
              $.post("prs_approve.asp",
                  data,
                  FcltCallbackRefresh,
                  "json");
          });
      }

      function impersCallback(json, textStatus)
      {
          window.top.location.href = "<%=rooturl%>/";
      };

      function prs_impersonate()
      {
        var fnImpers = (reden = "") => {
          var data = { prs_key: <%=prs_key%>
                      , prs_reason: reden
                      };
          <% protectRequest.dataToken("data"); %>
          $.post( "../prs/prs_impersonate.asp"
                , data
                , FcltCallbackAndThen(impersCallback)
                , "json"
                );
        }
<%    if (
        Application("otap_environment") == "O" ||
        Application("otap_environment") == "A"
      ) { %>
        fnImpers();
<%    } else { %>
        params = { oktekst: L("lcl_ok")
                 , title: L("lcl_impersonate")
                 , ishtmlsafe: true
                 , fncallback: function($dialog)
                                {
                                    var reden = $dialog.find("#prs_reden").val();
                                    if (reden.length < 10)
                                    {
                                        FcltMgr.alert(L("lcl_impersonate_abort"));
                                        return false;
                                    }
                                    else
                                    {
                                        fnImpers(reden);
                                    }
                                }
                 , buttons: [{ text: L("lcl_cancel"), icon: "fal fa-fw fa-undo", class: "alertCancel" }]
                 };
        var page_content = L("lcl_impersonate_start").format("<b><%=safe.jsstring(safe.html(prs_vrnaam))%>" + " " + "<%=safe.jsstring(safe.html(prs_naam))%></b>")
                         + '<br>'
                         + '<div>'
                         + '<label for="prs_reden">' + L("lcl_impersonate_reason") + ': </label>'
                         + '<textarea class="fldtxt" id="prs_reden" name="prs_reden" rows="3" minlength="10"></textarea>'
                         + '</div>';
        FcltMgr.mydialog(page_content, params);
<%    } %>
      } // \ prs_impersonate

      function prs_reserveerbaar()
      {
          FcltMgr.openDetail("appl/mgt/res_deel.asp?mode=wrap&ins_min_level=4&id=<%=res_deel_key%>&res_prs_perslid_key=<%=prs_key%>", L("res_deel"));
      }
    </script>
  </head>

  <body class="showmode">
<%
    SUBFRAME_START();
    var buttons = [];
    if (prsauthparams.writeman && prs_inactief) {
      buttons.push( {title: "heractiveren", action: "prs_reactivate()", icon: "fa-user-check" });
    }
    if (prsauthparams.writeman || prsauthparams.writeuse) {
      buttons.push( {title: L("lcl_change"), action:"prs_change()", icon: "fa-fclt-edit" });
    }

    if (prsauthparams.writeman) {
      buttons.push( {title: L("lcl_delete"), action:"prs_delete()", icon: "fa-trash-alt" });
    }
    // Bepaalde functies zijn alleen zinvol voor personen die users zijn
    if (prs_email || prs_oslog || prs_oslog2)
    {
      if (prsauthparams.writesys || xfunc.canWrite("WEB_FACMGT"))
      {
        if (prs_user.isUnapprovedUser())
        buttons.push( { title: L("lcl_prs_approve"), icon: "fa-check", action: "prs_approve()" });
        buttons.push( { title: L("lcl_password_title"), icon: "fa-key", action: "prs_changepwd()" });
      }
      if (user.has("WEB_FACFAC")) // die mag het *altijd*
      {
        buttons.push({ title: L("lcl_otp_authenticatie"), icon: "fa-unlock-alt", action: "prs_showotp()", id: "otp_perslid" });
      }

      var canImpers = prsauthparams.writetab || (S("prs_allow_impersonate") && prsauthparams.writesys)
      if (canImpers && !prs_inactief && prs_key != user_key && typeof Session("org_user_key") == "undefined") {
        buttons.push({ title: L("lcl_impersonate"), icon: "fa-handshake", action: "prs_impersonate()", id: "bimpers" });
      }
    }
    if (res_authparams)
    {
        var sql = "SELECT *"
                + "  FROM res_v_aanwezigdiscipline"
                + " WHERE ins_discipline_min_level = 4"; // zijn er persoon resource catalogi?
        var oRs = Oracle.Execute(sql)
        if (!oRs.EOF)
            buttons.push({title: L("res_prs_planbaar"), action: "prs_reserveerbaar()", icon: "fa-calendar-star"});
        oRs.Close()
    }

    if (prs_user.has("WEB_FACFAC") && !user.has("WEB_FACFAC"))
    {
        buttons = []; // zelf geen WEB_FACFAC dan mag je echt niets meer
    }
    IFRAMER_HEADER(L("lcl_prs_persoon_frame"), buttons);

    if (prs_inactief)
    {
        SIMPLE_BLOCK_START();
        Response.Write("<div class='prs_deleted'>" + L("lcl_prs_inactive_perslid"));
        Response.Write("</div>");
        SIMPLE_BLOCK_END();
    }

%>
      <form name=u2>
<%      BLOCK_START("prsPerslid", L("lcl_prs_basisblok"), {icon: "fa-id-card-alt"});
        Response.write("<tr><td></td><td class='profile'><img id='photo' alt='" + safe.htmlattr(L("fac_profiel")) + " " + safe.htmlattr(L("lcl_photos")) + "' class='profile' src='" + safe.htmlattr(thisPrs.photopaththumb) + "'></td></tr>");

        ROFIELDTR("fld", L("lcl_prs_person_achternaam"), prs_naam);
        ROFIELDTR("fld", L("lcl_prs_person_geslacht"), { 0: L("lcl_prs_person_geslachtV"), 1: L("lcl_prs_person_geslachtM"), 9: L("lcl_prs_person_geslachtX") }[prs_geslacht] , {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_tussen"), prs_tussen, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_voorletters"), prs_vltr, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_voornaam"), prs_vrnaam, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_title"), prs_titel, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_initials"), prs_ini, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_phone"), prs_telnr, { suppressEmpty: true, type: "telefoon" });
        ROFIELDTR("fld", L("lcl_prs_person_mobile"), prs_mobiel, { suppressEmpty: true, type: "telefoon" });
        ROFIELDTR("fld", L("lcl_prs_person_email"), prs_email, { suppressEmpty: true, type: "email" });
        ROFIELDTR("fld", L("lcl_prs_person_visibility"), (visibility == 0 ? L("lcl_prs_perslid_visibility0") : L("lcl_prs_perslid_visibility1")), { suppressEmpty: true });
        if (prsauthparams.writesys || xfunc.canWrite("WEB_FACMGT"))
        {
          ROFIELDTR("fld", L("lcl_prs_systeemadres"), systeemadres, {suppressEmpty: true});
          ROFIELDTR("fld", L("lcl_prs_person_login"), prs_oslog, {suppressEmpty: true});
          ROFIELDTR("fld", L("lcl_prs_person_login2"), prs_oslog2, {suppressEmpty: true});
          if (otpsecret)
          {
            var txt = L("lcl_unknown");
            if (otpcounter > 0)
            {
                var otpresult = otpcodes(otpsecret);
                txt = toDateTimeString(new Date(otpcounter * 1000 * otpresult.otpstep), true);
            }
            ROFIELDTR("fld", L("lcl_otp_lastuse"), txt, {suppressEmpty: true});
          }

          var recent = new Date();
          recent.setDate(recent.getDate() - 7); // 1 week highlighten, handig voor troubleshooting
          ROFIELDTR("fld" + (prs_creddat&&prs_creddat>recent?" recentlychangedcredentials":""), L("lcl_pass_lastchanged"), toDateTimeString(prs_creddat) , {suppressEmpty: true});

          if (haspw)
          {
              var dt_exp = null;
              if (S("prs_password_expiration") > 0)
              {
                dt_exp = new Date(prs_creddat);
                dt_exp.setDate(dt_exp.getDate() + S("prs_password_expiration"));
                if (prs_credexp !=null && prs_credexp < dt_exp)
                {
                    dt_exp = prs_credexp;
                }
              }

              ROFIELDTR("fld" + (dt_exp<new Date()?" expiredcredentials":""), L("lcl_pass_willexpire"), toDateTimeString(dt_exp), {suppressEmpty: true});
          }
          ROFIELDTR("fld", L("prs_perslid_inactief"), toDateTimeString(prs_inactief), {suppressEmpty: true});
        }

        var wl = thisPrs.werklocatie.alg_locatie_key? thisPrs.werklocatie.aanduiding : "";
        ROFIELDTR('fld', L("lcl_prs_work_location"), wl, {suppressEmpty: true});
        if (prsauthparams.writesys)
        {
          ROTEXTAREATR("fldtxt", L("lcl_prs_person_opmerking"), prs_opm, {suppressEmpty: true});
        }
        BLOCK_END();

        if (prsauthparams.writesys || xfunc.canWrite("WEB_FACMGT")) // Die kunnen ook approve'n
        {
          BLOCK_START("prsTech", L("lcl_prs_techblok"), {icon: "fa-cogs"});
            if (prs_apikey)
            {
                var showkey = prs_apikey;
                if (!prsauthparams.writetab)
                    var showkey = showkey.substr(0,3) + "..." + showkey.substr(showkey.length-3);
                ROFIELDTR("fld", L("lcl_prs_apiuser"), showkey, {suppressEmpty: true, secret: true });
                ROCHECKBOXTR("flderrorhandling", L("prs_perslid_errorhandling"), prs_errorhandling);
            }
            var flagtxt = [];
            if (prs_user.isSystemUser())        flagtxt.push(L("lcl_prs_flags_system"));
            if (prs_user.isUnapprovedUser())    flagtxt.push(L("lcl_prs_flags_unapproved"));
            if (prs_user.isGroupedUser())       flagtxt.push(L("lcl_prs_flags_grouped"));
            if (prs_user.isBlockedUser())       flagtxt.push(L("lcl_prs_flags_blocked"));
            if (prs_user.isWriteonlyApi2User()) flagtxt.push(L("lcl_prs_flags_api2writeonly"));
            if (prs_user.isUndeletableUser())   flagtxt.push(L("lcl_prs_flags_undeletable"));
            if (flagtxt.length)
                ROFIELDTR("fld", L("lcl_prs_flags"), flagtxt.join("\n"));
            if (loglevel || user.has("WEB_FACFAC") )
            {
                ROCHECKBOXTR("fldloglevel", L("prs_perslid_loglevel"), loglevel);
                ROFIELDTR("fld", L("extern_nr"), externid, {suppressEmpty: true});
                ROFIELDTR("fld", L("extern_syncdate"), toDateTimeString(externsyncdate) , {suppressEmpty: true});
            }
          BLOCK_END();
        }

        BLOCK_START("prsPerslid2", L("lcl_prs_organisatieblok"), { icon: "fa-address-card"} );
        if (prsauthparams.writesys)
          ROCHECKBOXTR("fldnotingids", L("lcl_prs_in_guide"), ingids);
        ROFIELDTR("fld", L("lcl_prs_person_nr"), prs_nr, {suppressEmpty: true});
        var params_afd = { infoPointer: { Url: "appl/prs/prs_afdeling.asp?key=" + prs_afdkey
                                        }
                         };
        ROFIELDTR("fld", L("lcl_prs_organisatie"), afdeling, params_afd);
        ROFIELDTR("fld", L("lcl_prs_person_function"), prs_srtoms);
        FCLTpersoonselector("prs_verantwkey",
                            "prs_verantwkey",
                            { label: L("lcl_prs_person_verantw"),
                              perslidKey: verantw_key,
                              moreinfo: true,
                              info: 'PRS',
                              readonly: true,
                              suppressEmpty: true
                            });

        ROFIELDTR("fld", L("lcl_prs_person_opp"), prs_opp, {suppressEmpty: true, datatype: "float"});
        ROFIELDTR("fld", L("lcl_prs_person_dienstverband_perc"), prs_dnst, {suppressEmpty: prs_dnst!==0, datatype: "percentage"});
        if (S("prs_perslid_datums") == 1)
        {
          ROFIELDTR("fld", L("lcl_prs_person_ingangsdatum"), toDateString(prs_ingdat), {suppressEmpty: true});
          ROFIELDTR("fld", L("lcl_prs_person_einddatum"), toDateString(prs_enddat), {suppressEmpty: true});
        }

        if (kpl_key > 0)
        {
            var params_kpl = { suppressEmpty: true
                             , infoPointer: { Url: "appl/mgt/prs_kostenplaats.asp?mode=show&id=" + kpl_key
                                            }
                             };
            ROFIELDTR("fld", L("lcl_account"), kpl, params_kpl);
        }

        if (fac_prokey)
        { // Er is een profiel
          if (fac_prolim)
            ROFIELDTR("fld", L("lcl_prs_profile"), fac_proms + " (" + S("currency_pref") + ' ' + safe.curr(fac_prolim) + ")", {suppressEmpty: true});
          else
          { // Zijn er profielwaarden?
            sql = "SELECT COUNT(fac_profiel_key) aantalpw"
                + " FROM fac_profielwaarde"
                + " WHERE fac_profiel_key = " + fac_prokey;
            oRs = Oracle.Execute(sql);
            var aantalpw = oRs("aantalpw").value;

            if (aantalpw > 0)
              ROFIELDTR("fld",
                        L("lcl_prs_profile"),
                        fac_proms,
                        {infoPointer: {Url: "appl/prs/profielwaarden_info.asp?fac_prokey=" + fac_prokey + "&autosearch=1", Title: L("lcl_menu_fin_mandatering")},
                         suppressEmpty: true });
          }
        }
        if (aantal_pk > 0)
        {
          sql = "SELECT pk.prs_perslidkostenplaats_key"
              + ", k.prs_kostenplaats_key"
              + ", k.prs_kostenplaats_nr || ' ' || k.prs_kostenplaats_omschrijving kostenplaats"
              + " FROM prs_perslidkostenplaats pk"
              + ", prs_kostenplaats k"
              + " WHERE k.prs_kostenplaats_key(+) = pk.prs_kostenplaats_key"
              + " AND pk.prs_perslid_key = " + prs_key
              + " ORDER BY kostenplaats"
          oRs = Oracle.Execute(sql);

          if (aantal_pk == 1)
            ROFIELDTR("fld", L("lcl_prs_mandate_for"), (oRs("prs_kostenplaats_key").value? oRs("kostenplaats").value : L("lcl_prs_all_accounts")), {suppressEmpty: true});
          else
            ROFIELDTR("fld", L("lcl_prs_mandate_for"), oRs("kostenplaats").value + "...",
                             {infoPointer: {Url: "appl/prs/kpn_mandate_search.asp?prs_key=" + prs_key + "&autosearch=1", Title: L("lcl_menu_fin_mandatering")},
                              suppressEmpty: true });
          oRs.Close();
        }
        ROFIELDTR("fld", L("lcl_delivery_address"), mld_adres, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_person_uurloon"), prs_uurln, {suppressEmpty: true, datatype: "currency"});

        // Is persoon een contactpersoon, en zo ja van welk bedrijf.
        sql = "SELECT b.prs_bedrijf_key"
            + "     , b.prs_bedrijf_naam"
            + "  FROM prs_contactpersoon p"
            + "     , prs_bedrijf b"
            + " WHERE p.prs_bedrijf_key = b.prs_bedrijf_key"
            + "   AND prs_contactpersoon_verwijder IS NULL"
            + "   AND prs_perslid_key = " + prs_key;
        oRs = Oracle.Execute(sql);
        while (!oRs.eof)
        {
          var cnt_key = oRs("prs_bedrijf_key").value;
          var cnt_str = oRs("prs_bedrijf_naam").value;
          var params_cnt = { suppressEmpty: true
                           , infoPointer: { Url: "appl/prs/prs_bedrijf.asp?bedrijf_key=" + cnt_key
                                          }
                           };
          ROFIELDTR("fld", L("lcl_prs_perslid_contactpersoon"), cnt_str, params_cnt);
          oRs.MoveNext();
        }
        oRs.Close();

        BLOCK_END();

        if (prs_lang || prs_tz || prs_lcid)
        {
            BLOCK_START("prsRegion", L("lcl_prs_regionalblok"), {icon: "fa-globe-stand"});

            ROFIELDTR("fld", L("lcl_lcl_taal"), prs_lang, {suppressEmpty: true});
            FCLTtimezoneselector("", {initVal: prs_tz, readonly: true, suppressEmpty: true});
            sql = api2.splitLOV2sql(L("lcl_prs_person_lcidLOV"));
            FCLTselector("prs_lcid", sql,
                      { label: L("lcl_prs_person_lcid"),
                        initKey: prs_lcid,
                        readonly: true,
                        suppressEmpty: true,
                        extraclass: "notmulti"
                      });

            BLOCK_END();
        }

        if (S("prs_collegas_used") < 9 && (prsauthparams.writeman || prsauthparams.writeuse))
        {
          var sql = "SELECT pc.prs_perslid_key_alt"
                  + "     , " + S("prs_pers_string") + " prs_perslid_naam"
                  + "     , prs_collega_vervaldatum"
                  + "  FROM prs_collega pc"
                  + ",      prs_perslid p"
                  + " WHERE pc.prs_perslid_key_alt = p.prs_perslid_key"
                  + "   AND pc.prs_perslid_key = " + prs_key
                  + " ORDER BY 2";
          var oRs = Oracle.Execute (sql);
          var btns = [];
          btns.push({ title: L("lcl_prs_frame_substitutes"), icon: "fa-fclt-edit", action: "prs_substitute()", id: "bcollegas", importance: 2});

          BLOCK_START("prsSubst", L("lcl_prs_substitutesblock"), { icon: "fa-people-arrows", buttons: btns });
          while (!oRs.eof) { %>
            <tr>
              <td onclick="FcltMgr.openDetail('appl/fac/fac_user_info.asp?prs_key=<%=oRs("prs_perslid_key_alt").Value%>')">
                <span class="details">
                  <%=safe.html(oRs("prs_perslid_naam").value)%>
                </span>
              </td>
              <td>
                <%=(oRs("prs_collega_vervaldatum").value !== null ? safe.html(L("lcl_tot") + " " + toDateString(oRs("prs_collega_vervaldatum").value, true)) : "")%>
              </td>
            </tr>
<%          oRs.moveNext();
          }
          BLOCK_END();
          oRs.Close()
        }

        if ((prsauthparams.writeman || prsauthparams.writeuse))
        {
          BLOCK_START("prsSubstTo", L("lcl_prs_replaceblock"), { icon: "fa-people-arrows" });
            var sql_o = "SELECT pc.prs_perslid_key"
                      + "     , " + S("prs_pers_string") + " prs_perslid_naam"
                      + "     , prs_collega_vervaldatum"
                      + "  FROM prs_collega pc"
                      + "     , prs_perslid p"
                      + " WHERE pc.prs_perslid_key = p.prs_perslid_key"
                      + "   AND pc.prs_perslid_key_alt = " + prs_key
                      + " ORDER BY 2";
            var oRs_o = Oracle.Execute("SELECT COUNT(*) aantal FROM (" + sql_o + ")");
            var vervangt_aantal = oRs_o("aantal").Value;
            oRs_o.Close();
            if (vervangt_aantal <= S("prs_collegas_groep"))
            {
              var oRs_o = Oracle.Execute(sql_o);
              while (!oRs_o.eof) { %>
                <tr>
                  <td onclick="FcltMgr.openDetail('appl/fac/fac_user_info.asp?prs_key=<%=oRs_o("prs_perslid_key").Value%>')">
                    <span class="details">
                      <%=safe.html(oRs_o("prs_perslid_naam").value)%>
                    </span>
                  </td>
                  <td>
                    <%=(oRs_o("prs_collega_vervaldatum").value !== null ? safe.html(L("lcl_tot") + " " + toDateString(oRs_o("prs_collega_vervaldatum").value, true)) : "")%>
                  </td>
                </tr>
<%              oRs_o.moveNext();
              }
              oRs_o.Close();
            }
            else
            {
                ROFIELDTR("fldpers", "", L("lcl_prs_substitutes_toomany").format(vervangt_aantal));
            }
          BLOCK_END();
        }

        var notis = prs.check4notis();

        if ((prs_key == user_key || prsauthparams.writesys || prsauthparams.writeman) && notis.canany)
        {
          BLOCK_START("prsNoti", L("lcl_noti_prsvoorkeur"), { icon: "fa-bell-on"} );
          if (prs_user.noti_niks() == 1 || prs_user.noti_portal() == 1 || prs_user.noti_email() == 1 || prs_user.noti_sms() == 1 || prs_user.noti_popup() == 1)
          {
            CHECKBOXTR(L("lcl_noti_niks"), "fldfacnoti", "noti0", prs_user.noti_niks(), { html: " disabled" });
            if (notis.can1) CHECKBOXTR(L("lcl_noti_portal"), "fldfacnoti", "noti1", prs_user.noti_portal(), { html: " disabled" });
            if (notis.can2) CHECKBOXTR(L("lcl_noti_email"), "fldfacnoti", "noti2", prs_user.noti_email(), { html: " disabled" });
            if (notis.can4) CHECKBOXTR(L("lcl_noti_sms"), "fldfacnoti", "noti4", prs_user.noti_sms(), { html: " disabled" });
            if (notis.can8) CHECKBOXTR(L("lcl_noti_popup"), "fldfacnoti", "noti8", prs_user.noti_popup(), { html: " disabled" });
          }
          else
          {%>
            <tr id="noNotipref">
              <td class="label" colspan="2">
                <label><span><%=L("lcl_no_noti_prsvoorkeur")%></span></label>
              </td>
            </tr>
          <%}
          BLOCK_END();
        }

          generateFlexKenmerkCode ({
             link_key     : prs_key,
             srt_key      : prs_srtkey,
             niveau       : "P",
             reado        : true,
             prsauthparams: prsauthparams
        });

%>
      </form>
    <% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
