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

    File:               user_info.asp derived from fac/fac_user_info_phone.asp)
    Description:        Details van een user aka persoon
    Parameters:         prs_key (default user_key)
    Context:
    Note:               Schetsje obv vraag AAIT#30303
*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../prs/prs.inc" -->
<!-- #include file="../prs/prs_flexkenmerk.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="./iface.inc" -->
<%
FCLTHeader.Requires({plugins: ["suggest"]});

// AUTORISATIEPARAMETERS
var prs_key = getQParamInt("prs_key", user_key);
var itsme = (prs_key == user_key);

var sql = "SELECT prs_srtperslid_key"
        + "  FROM prs_perslid"
        + " WHERE prs_perslid_key = " + prs_key;
var oRs = Oracle.Execute(sql);
var prs_srtkey = oRs("prs_srtperslid_key").value;
oRs.Close();
var prsauthparams = prs.checkAutorisation(prs_key);
var canChange = itsme && prsauthparams.canWrite;
var thisUser = prs.prs_perslid(prs_key, { withWP: true, withWL: true, withPhoto: true }); // geeft ook alle informatie

var photoFile = thisUser.photopath;  // de huidige foto
var photoMap  = thisUser.photomap;   // map waarin de foto wordt opgeslagen
%>
<html>
<head>
<%
  FCLTMHeader.Generate();
%>
<script  type="text/javascript" >
  function edit_werkplek(img, pwp_key)
  {
      var url = rooturl + "/appl/prs/prs_move_perslidwerkplek.asp?pwp_key=" + pwp_key;
      FcltMgr.openModalDetail(url, "<%=safe.jsstring(thisUser.naam)%>",
                  { callback: function (data) { if (data.wp_aanduiding) {$(img).closest("tr").find("input").val(data.wp_aanduiding);} } });
  }

  function edit_werklocatie(img, prs_key)
  {
      var url = rooturl + "/appl/prs/prs_move_huidigewerkplek.asp?prs_key=" + prs_key;
      FcltMgr.openModalDetail(url, "<%=safe.jsstring(thisUser.naam)%>",
                  { callback: function (data) { if (data.wp_aanduiding) {$(img).closest("tr").find("input").val(data.wp_aanduiding);} } });
  }

  function edit_phone(inp)
  {
      var url = rooturl + "/appl/prs/prs_edit_perslid_modal.asp?prs_key=<%=prs_key%>"
      FcltMgr.openModalDetail(url, "<%=safe.jsstring(thisUser.naam)%>",
                  { callback: function(data) { if (data.refresh) FcltMgr.reload() } });
  }

</script>

</head>
<body class="showmode">

<script  type="text/javascript" >
  $(function ()
  {
    FcltMgr.setTitle("<%=itsme ? L("lcl_prs_person_mijndata") : safe.jsstring(thisUser.naam)%>");
  });
</script>
<%
  PAGE_START({id: "page-1-"+prs_key});

    HEADER({ title: thisUser.naam, back: true, location: S("mobile_position_required") == 1 });
    CONTENT_START();
%>
<script  type="text/javascript" >
    async function prs_submit()
    {
        if (!await validateForm("u2"))
            return false;

        $.post($("form[name=u2]")[0].action,
               $("form[name=u2]").serialize(),
               McltCallbackAndThen(prs_submit_callback),
               "json");
        return false;
    }

    function prs_submit_callback(json)
    {
        if (json.success)
        {
            jqToast(L("lcl_mobile_data_saved"));
        }
    }

    // through click on image
    function doSubmitUploadPhoto()
    {
      if (document.forms.u2Photo.input_photo.value == "")
          return false;

      if (!(/\.jpg$|\.jpeg$/i).test(document.forms.u2Photo.input_photo.value))
      {
          alert(L("lcl_shared_file_ext_not_allowed"));
          return false;
      }
      var ajaxData = new FormData();
      ajaxData.append("imgfile", document.forms.u2Photo.input_photo.files[0]);
      ajaxData.append("<%=protectRequest.theVar%>", "<%=safe.htmlattr(protectRequest.theToken())%>");

      document.forms.u2Photo.action = "<%=protectQS.create("../shared/UploadForm_save.asp?action=insert&module=SML&key="+prs_key)%>";
      $.ajax({
          url: document.forms.u2Photo.action,
          type: "POST",
          data: ajaxData,
          cache: false,
          processData: false,
          success: McltCallbackAndThen(function () { FcltMgr.reload(); })
        });
    }

</script>
        <div>
        <form name="u2Photo" id="u2photo" method="post" enctype="multipart/form-data">
          <input type="hidden" name="noresize" id="noresize" value="0">
          <img id="photo" alt="<%=safe.htmlattr(L("fac_profiel")) + " " + safe.htmlattr(L("lcl_photos"))%>"
               class="selfie" src="<%=safe.htmlattr(photoFile) %>"
               onclick="$('#input_photo').click();">
<%
        if (S("prs_use_edit_photo") && canChange)
        {
            %>
          <div class="flex-center">
            <label for="photo" class="text-center"><%=L("lcl_pda_change_photo")%></label><%
%>          <div class="attachments_form" style="display: none;">
                <span class="attachments_form">
                  <span class="attachments_fields"></span>
                  <span class="add_attachment" style="">
                    <input type="file"
                          name="input_photo"
                          id="input_photo"
                          class="file_selector filedrop"
                          multiple="false"
                          onchange="doSubmitUploadPhoto();"
                          data-max-concurrent-uploads="1"
                          data-upload-path="<%=photoMap%>"
                          data-role="none"
                          data-param="sml"
                          data-description="true">
                  </span>
                </span>
            </div>
          </div>
<%
            IFACE.FORM_END();
        }
%>
        </form>

      <form name="u2" id="u2" method="post" action="<%=rooturl%>/appl/prs/prs_edit_perslid_save.asp?prs_key=<%=prs_key%>">

          <input type="hidden" name="changed" id="changed" value="0">

<%
     // ============================= PERSOONSGEGEVENS ======================================
        ROFIELD("fld",        L("lcl_prs_person_email"),     thisUser.prs_perslid_email,      {suppressEmpty: true});
        ROFIELD("fld",        L("lcl_prs_person_dept_name"), thisUser.prs_afdeling_naam);
        ROFIELD("fld",        L("lcl_prs_person_function"),  thisUser.prs_srtperslid,         {suppressEmpty: true});
        RWFIELD("prs_telnr",  L("lcl_prs_person_phone"),     thisUser.prs_perslid_telefoonnr, {maxlength: 20});
        RWFIELD("prs_mobiel", L("lcl_prs_person_mobile"),    thisUser.prs_perslid_mobiel,     {maxlength: 20});

        for (wp in thisUser.werkplekken) // is reeds gesorteerd op volgnr
        {
            var wpi = thisUser.werkplekken[wp];
            ROFIELD('fldroom', (wp == 0? L("lcl_prs_workplace") : null), wpi.prs_werkplek_aanduiding, {suppressEmpty: true});
        }
        var wl = thisUser.werklocatie.alg_locatie_key? thisUser.werklocatie.aanduiding : "";
        ROFIELD('fld', L("lcl_prs_work_location"), wl, {suppressEmpty: true});

     // ============================= FLEXKENMERKEN =========================================
        prsauthparams.writeuse = false;
        prsauthparams.writeman = false;
        //BLOCK_START({collapsed: true, title: L("lcl_bes_flexblok")});
        %><div id='besFlex' class='besFlex'></div><%
          generateFlexKenmerkCode({link_key     : prs_key,
                                   srt_key      : prs_srtkey,
                                   niveau       : "P",
                                   reado        : false,
                                   includepublic: true,
                                   prsauthparams: prsauthparams,
                                   mobile       : true
                                  });
%>
<script type="text/javascript">
  // In dit scherm de suggest velden voor kenmerken readonly maken
  // omdat de lijst met waarden op de verkeerde plaats worden getoond.
  // NB: Dit script NA het generateFlexKenmerkCode omdat deze ook een script bevat dat eerst uitgevoerd moet worden.
  $(function ()
  {
    $(".fldSflexS").each(function(index) {  $(this).attr("readonly", "");  });
  });
</script>
<%
        //BLOCK_END();
      CONTROLGROUP_START();
        if (canChange)
          BUTTON(L("lcl_change"), {click: "prs_submit()", icon: "fa-fclt-edit"});
      CONTROLGROUP_END();
      IFACE.FORM_END();
%>
      </form>
<%
    CONTENT_END();
    FOOTER();
  PAGE_END();
PDA_PAGE_END(); %>
	</body>
</html>
<% ASPPAGE_END(); %>
