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

    File:               prs_perslid.asp
    Status:             100%%
    Description:        Wrapper for prs_show_perslid.asp/prs_edit_perslid.asp

    Parameters:         key (or prs_key), optional

    Context:
    Note:

*/ %>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/iface.inc" -->
<%
  FCLTHeader.Requires({plugins:["suggest","jQuery"], js: ["jQuery-ui.js"]})
// jQuery-ui.js is nodig in het child formulier prs_perslidwerkplek_search_list

  var autfunction = "WEB_PRSUSE"; // stelling: als je MAN hebt moet je ook maar USE krijgen
  var authparams = user.checkAutorisation(autfunction);

  var authparamsBOF = user.checkAutorisation("WEB_PRSBOF", true);
  var canBOF = (authparamsBOF && authparamsBOF.ALGreadlevel < 9 && authparamsBOF.PRSreadlevel < 9);

  var prs_key = getQParamInt("key", -1);
  if (prs_key == -1)
    prs_key = getQParamInt("prs_key", -1);

  var dienstauthparams = user.checkAutorisation("WEB_PRSMSU", true);  // zoals bij bedrijf. goed?
  var activeTab = getQParamSafe("active_tab", "");

  // *** UNEXUS koppeling ***
  var fuz_tel_org = getQParam("fuzzytel", "");
  if (fuz_tel_org)
  {
    //__Log("*** UNEXUS koppeling ***");
    //__Log("fuzzytel=" + fuz_tel_org);

    fuz_tel = fuz_tel_org.replace(/ /g,"").slice(-9);
    var sql = "SELECT prs_perslid_key"
            + "  FROM prs_perslid"
            + " WHERE SUBSTR(regexp_replace (prs_perslid_telefoonnr, '*\\D', '')"
            + "             , -1 * LEAST(LENGTH(regexp_replace (prs_perslid_telefoonnr, '*\\D', '')), 9)"
            + "             ) = " + safe.quoted_sql(fuz_tel)
            + "    OR SUBSTR(regexp_replace (prs_perslid_mobiel,     '*\\D', '')"
            + "             , -1 * LEAST(LENGTH(regexp_replace (prs_perslid_mobiel,     '*\\D', '')), 9)"
            + "             ) = " + safe.quoted_sql(fuz_tel);
    var oRs = Oracle.Execute(sql);
    if (!oRs.eof)
    {
        prs_key = oRs("prs_perslid_key").Value;
        //__Log("persoon gevonden: " + prs_key);
    }
    else
    {
        // wel fuzzytel, maar geen prs_key gevonden, dan stoppen.
        abort_with_warning(L("lcl_prs_tel_notfound").format(fuz_tel_org));
    }
    oRs.Close();
  }
  // *** ______ _________ ***


  var naam = "";
  if (prs_key > 0)
  {
    var thisPrs = new Perslid(prs_key);  // voor de naam in de titel
    naam = thisPrs.naam();
  }
  transitParam = buildTransitParam(["prs_srtkey"]);
%>
<html>
<head>
<%
   FCLTHeader.Generate();
%>
  <script  type="text/javascript" >
      FcltMgr.setTitle("<%=safe.jsstring(naam)%>", {hot: false});
<%    if (prs_key == -1) { %>FcltMgr.startEdit(window);<% } %>
      function prsClose(params)
      {
          <% if (prs_key == -1)
             { %>
              if (params.cancel)
              {
                  FcltMgr.closeDetail(window, params );
                  return true;
              }
              if (!params.keepForm)
                  window.location.href = "prs_perslid.asp?verynew=1&key=" + params.prs_key + "<%=transitParam%>";
          <% } else { %>
              if (!params.keepForm)
                  $("#prsframe")[0].src = "prs_show_perslid.asp?prs_key=<%=prs_key%>";

          <% } %>
      }
<%
      if (activeTab)
      { %>
      $(function () {
          for (var i = 0; i < window.frames.length; i++)
              if (window.frames[i].name == "<%=activeTab%>")
                  $("#frametabs").tabs({ "active": i });
      });
<%
      } %>

    </script>
</head>

  <body>
<%
PAGE_START();
    if (prs_key == -1)
        var page="prs_edit_perslid.asp?prs_key="+prs_key+transitParam; // Maak een nieuw
    else
        var page="prs_show_perslid.asp?prs_key="+prs_key+transitParam;

    // 1. De Persoongegevens
    IFRAMER("prsframe", page, { FcltClose: "prsClose" } );

    if (prs_key > 0)
    {
      if (S("use_capacity_planning") == 1)  // hier niet ook die mldord-enz check? BONS?
      {
        // 2. De inzetbaarheid
        page = "prs_inzetbaar_list.asp?embedded=1&prs_key=" + prs_key;
        IFRAMER("prsinzetframe", page, { refreshOnClose: true, icon: "fa-list", title: L("lcl_prs_inzetbaar_title") } );
      }
      // als dit een uitvoerende is, kan ik de skills aangeven (mits voldoende autorisatie aldaar)
      if (dienstauthparams && (thisPrs.has("WEB_MLDORD") || thisPrs.has("WEB_EXTORD")))
      {
          // 3. De dienstenxpersoon
          page = "../mgt/prs_bedrijfdienstlocatie.asp?mode=list&person=" + prs_key;

          IFRAMER("prsdienstlistframe", page, { refreshOnClose: true, icon: "fa-list" } );
      }

      if (canBOF)
      { // 3. De bezetting
        page = "prs_perslidwerkplek_search_list.asp?embedded=1&prs_key=" + prs_key;
        IFRAMER("wplistframe", page, { refreshOnClose: true, icon: "fa-list" } );
      }

      // 4. De verplichtingen incl. geleende objecten
      page = "prs_obligations.asp?prs_key=" + prs_key;
      IFRAMER("prsverplichtingframe", page, { refreshOnClose: true, icon: "fa-list", title: L("lcl_prs_obligations") } );

      var xfunc = user.func_enabled("*", null, null, prs_key);
      if (user.has("WEB_PRSSYS") || xfunc.canWrite("WEB_PRSMSU") || ( xfunc._funcodes["WEB_PRSMSU"] && xfunc._funcodes["WEB_PRSMSU"].PRSreadlevel < 9))
      {
        var page = "../mgt/prs_perslid.asp?mode=list&model=authorization&person=" + prs_key;
        IFRAMER("prsauthframe", page, { icon: "fa-list", title: L("lcl_facmgt_aut")} );
      }

      // 5. tracking naar subframe, iedereen die dit mag zien, mag ook de mutaties zien
      page = protectQS.create("../shared/status_info.asp?urole=fo&prs_key=" + prs_key);
      IFRAMER("prshistoryframe", page, { icon: "fa-list", title: L("lcl_tracking")} );
    }
    PAGE_END();
%>
  </body>
</html>
<% ASPPAGE_END(); %>
