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

    File:         prs_edit_photo.asp
    Description:  Vervang een photo
    Parameters:   pkey: prs_perslid_key

    Context:      fac_user_info / uwva_user_info
    Note:
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../prs/prs.inc" -->

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

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

var thisUser = new Perslid(prs_key); // geeft ook alle informatie

sql = "SELECT prs_perslid_key"
    + "     , prs_perslidwerkplek_bezetting"
    + "     , prs_perslidwerkplek_volgnr"
    + "     , prs_werkplek_key"
    + "  FROM prs_perslidwerkplek"
    + " WHERE prs_perslidwerkplek_key = " + pwp_key;

oRs = Oracle.Execute(sql);

var wp_key     = oRs("prs_werkplek_key").value;
var prs_key    = oRs("prs_perslid_key").value;
var wp_volg    = oRs("prs_perslidwerkplek_volgnr").value;
var wp_bez     = oRs("prs_perslidwerkplek_bezetting").value;

oRs.Close();
%>
<html>
  <head>
<%  FCLTHeader.Generate();
    var submitting = getQParamInt("submit", 0) == 1;
    if (submitting)
    {
      var newWPkey = getFParamInt("werkplekkey");
      var newRuimtekey = getFParamInt("ruimtekey");
      if (S("prs_werkplek_implicit") == 0)
      {
        var fields = [ { dbs: "prs_werkplek_key",              typ: "key",     frm: "werkplekkey" },
                       { dbs: "prs_perslidwerkplek_bezetting", typ: "number",  frm: "wp_bez" },
                       { dbs: "prs_perslidwerkplek_volgnr",    typ: "number",  frm: "wp_volg" }
                     ];
        sql = buildUpdate("prs_perslidwerkplek", fields)
            + "     prs_perslidwerkplek_key = " + pwp_key;
        var err = Oracle.Execute(sql);
      }
      else // impliciet
      {
        sql = "UPDATE prs_werkplek"
            + "   SET prs_alg_ruimte_key = " + newRuimtekey
            + " WHERE prs_werkplek_key = " + wp_key;
      }
      Oracle.Execute(sql);

      var wpInfo = new Werkplek(newWPkey);

%>    <script>
        FcltMgr.closeDetail(window, { refresh: true,
                                      wp_aanduiding : "<%=safe.jsstring(wpInfo.prs_werkplek_aanduiding())%>" } );
      </script>
<%    Response.End;
    }
%>
    <script type="text/javascript">
      async function prs_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!await validateForm("u2"))
              return false;
          document.forms.u2.submit();
      }
      function prs_cancel()
      {
          FcltMgr.closeDetail(window);
      }
    </script>
  </head>

  <body class="fclt-modal" id="mod_movewerkplek" style="width:400px">
    <% MODAL_START(); %>
    <form name="u2"
          action="prs_move_perslidwerkplek.asp?submit=1<%=buildTransitParam(["pwp_key"])%>"
          method="post"
          onSubmit="prs_submit();">
<%
      MODAL_BLOCK_START("bezettingInfo", L("lcl_select_werkplek"), { icon: "fa-map-marker-alt" });
      FCLTplaatsselector(-1, { werkplekkey: wp_key,
                               startlevel: 2,/*locatie*/
                               readonlylevel: S("prs_use_edit_werkplek"), /* locatie of gebouw meestal */
                               eindlevel: (S("prs_werkplek_implicit") == 0)? 6 : 5,/*ruimte/werkplek*/
                               requiredlevel: (S("prs_werkplek_implicit") == 0)? 6 : 5
                          });

      if (S("prs_werkplek_implicit")==0)
      {
        RWFIELDTR("wp_volg", "fldshort", L("lcl_estate_pwp_seq"), wp_volg, {required: false, datatype: "number", maxlength: 2});
        RWFIELDTR("wp_bez",  "fldshort", L("lcl_occupation"), wp_bez,      {required: true, datatype: "number",  maxlength: 3});
      }
      MODAL_BLOCK_END();
      SIMPLE_BLOCK_START();
      CreateButtons([{ title: L("lcl_submit"), icon: "fa-fclt-save", action: "prs_submit()"},
                     { title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "prs_cancel()"}]);
      SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
