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

    File:         prs_edit_perslid_modal.asp
    Description:  Sta wat simpele wijzigingen van de gebruiker in zijn eigen gegevens
                  Dit is te beschouwen als de edit-variant van fac_user_info
    Parameters:

    Context:      fac_user_info
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="prs_flexkenmerk.inc" -->
<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="prs.inc" -->

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

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

var prsauthparams = prs.checkAutorisation(prs_key);
user.auth_required_or_abort(prsauthparams.writeman || prsauthparams.writeuse || prsauthparams.writeself);

sql = "SELECT prs_perslid_telefoonnr"
    + "     , prs_perslid_mobiel"
    + "     , prs_srtperslid_key"
    + "  FROM prs_v_aanwezigperslid p"
    + " WHERE p.prs_perslid_key = " + prs_key;

var oRs = Oracle.Execute(sql);

var prs_telnr  = oRs("prs_perslid_telefoonnr").value;
var prs_mobiel = oRs("prs_perslid_mobiel").value;
var prs_srtkey = oRs("prs_srtperslid_key").value;

oRs.Close();
%>

<html>
  <head>
<%  FCLTHeader.Generate();
    var submitting = getQParamInt("submit", 0) == 1;
    if (submitting)
    {
      var fields =  [ { dbs: "prs_perslid_telefoonnr", typ: "varchar",  frm: "prs_telnr" },
                      { dbs: "prs_perslid_mobiel", typ: "varchar",  frm: "prs_mobiel" }];
      sql = buildUpdate("prs_perslid", fields)
          + "     prs_perslid_key = " + prs_key;

      var err = Oracle.Execute(sql, true);
      warning = "";
      if (err.friendlyMsg)
          warning = err.friendlyMsg;
      else
          shared.trackaction("PRSUPD", prs_key);

      if (!warning)
      {
        currentKenmerkenSQL = "SELECT kl.prs_kenmerk_key"
                            + "  , kl.prs_kenmerklink_waarde"
                            + "  FROM prs_kenmerklink kl"
                            + "     , prs_kenmerk k"
                            + " WHERE k.prs_kenmerk_key = kl.prs_kenmerk_key"
                            + "   AND prs_kenmerklink_verwijder IS NULL"
                            + "   AND prs_link_key = " + prs_key;

        saveFlexKenmerken(prs_key, { kenmerkTable       : "prs_kenmerklink",
                                     kenmerkParentKey   : "prs_link_key",
                                     kenmerkWaarde      : "prs_kenmerklink_waarde",
                                     kenmerkKey         : "prs_kenmerk_key",
                                     currentKenmerkenSQL: currentKenmerkenSQL,
                                     requestQF          : Request.Form,
                                     moduleName         : "prs_kenmerklink_niveau",
                                     moduleVal          : "P",
                                     isNew              : false,
                                     flexPath           : "PRS/P"
                                  }
                          )
      }
%>    <script>
        FcltMgr.closeDetail(window, { refresh: true,
                                      warning: "<%=safe.jsstring(warning)%>" } );
      </script><%
      Response.End;
    }
%>
    <script type="text/javascript">
      function prs_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!validateForm("u2"))
              return false;
          document.forms.u2.submit();
      }
      function prs_cancel()
      {
          FcltMgr.closeDetail(window);
      }
    </script>
  </head>

  <body class="modal" id="mod_edit_prs_modal" style="width:400px">
    <form name="u2"
          action="prs_edit_perslid_modal.asp?submit=1<%=buildTransitParam(["prs_key"])%>"
          method="post"
          onSubmit="prs_submit();">
<%
      BLOCK_START("bezettingInfo", L("lcl_prs_basisblok"));
      RWFIELDTR("prs_telnr",  "fld",     L("lcl_prs_person_phone"),       prs_telnr, {maxlength: 15});
      RWFIELDTR("prs_mobiel", "fld",     L("lcl_prs_person_mobile"),      prs_mobiel, {maxlength: 15});
      BLOCK_END();

      BLOCK_START("prsFlex0", L("lcl_prs_flexblok"));
        generateFlexKenmerkCode ({ link_key: prs_key,
                                   srt_key: prs_srtkey,
                                   niveau: "P",
                                   reado: false,
                                   flexcolumns: 1,
                                   minVolgnr: 800,
                                   prsauthparams: prsauthparams
                                 });
      BLOCK_END();

      CreateButtons([{ title: L("lcl_submit"), action: "prs_submit()"},
                     { title: L("lcl_cancel"), action: "prs_cancel()"}]);
IFACE.FORM_END();
%>
    </form>
  </body>
</html>
