<%@language = "javascript" %>
<%
/*  $Revision$
    Modtime: 06-10-2009 $

    File:           prs_show_contactpersoon.asp
    Description:
    Parameters:     cps_key (required)

    Context:
*/ %>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/iface.inc" -->
<!--#include file="../Shared/persoonselector.inc" -->
<!--#include file="prs.inc" -->
<!--#include file="prs_flexkenmerk.inc" -->

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

  var cps_key  = getQParamInt("cps_key");
  var autparamsRELMAN = user.checkAutorisation("WEB_RELMAN", true);
  var hasRELMAN = autparamsRELMAN && autparamsRELMAN.PRSwritelevel < 9 && autparamsRELMAN.ALGwritelevel < 9; // Can delete contact person even when this person is employee

  var autfunction = ["WEB_RELUSE"];
  if (user.iamContact())
      autfunction.push("WEB_EXTREL");
  var authparamsEXTRELUSE = user.checkAutorisation(autfunction);

  sql = "SELECT c.prs_contactpersoon_key"
      + "     , c.prs_bedrijf_key"
      + "     , prs_bedrijf_naam"
      + "     , prs_bedrijf_uitvoerende"
      + "     , prs_bedrijf_intern"
      + "     , prs_contactpersoon_aanhef"
      + "     , prs_contactpersoon_voorletters"
      + "     , prs_contactpersoon_naam"
      + "     , prs_contactpersoon_voornaam"
      + "     , prs_contactpersoon_tussenv"
      + "     , prs_contactpersoon_functie"
      + "     , prs_contactpersoon_titel"
      + "     , prs_contactpersoon_telefoon_1"
      + "     , prs_contactpersoon_telefoon_2"
      + "     , prs_contactpersoon_fax"
      + "     , prs_contactpersoon_email"
      + "     , prs_contactpersoon_opmerking"
      + "     , prs_contactpersoon_uurloon"
      + "     , prs_contactpersoon_systeem"
      + "     , c.prs_perslid_key"
      + "     , c.prs_contactpersoon_verwijder"
      + "  FROM prs_contactpersoon c, "
      + "       prs_bedrijf b "
      + " WHERE b.prs_bedrijf_key = c.prs_bedrijf_key AND prs_contactpersoon_key = " + cps_key

  oRs = Oracle.Execute(sql);

  var prs_bdrkey = oRs("prs_bedrijf_key").value;
  var prs_bdrnm  = oRs("prs_bedrijf_naam").value;
  var prs_uitv   = oRs("prs_bedrijf_uitvoerende").value == 1;
  var prs_intern = oRs("prs_bedrijf_intern").value == 1;
  var prs_aanh   = oRs("prs_contactpersoon_aanhef").value;
  var prs_voorl  = oRs("prs_contactpersoon_voorletters").value;
  var prs_naam   = oRs("prs_contactpersoon_naam").value;
  var prs_vrnaam = oRs("prs_contactpersoon_voornaam").value;
  var prs_tsnvgs = oRs("prs_contactpersoon_tussenv").value;
  var prs_func   = oRs("prs_contactpersoon_functie").value;
  var prs_titel  = oRs("prs_contactpersoon_titel").value;
  var prs_tel1   = oRs("prs_contactpersoon_telefoon_1").value;
  var prs_tel2   = oRs("prs_contactpersoon_telefoon_2").value;
  var prs_fax    = oRs("prs_contactpersoon_fax").value;
  var prs_email  = oRs("prs_contactpersoon_email").value;
  var prs_opm    = oRs("prs_contactpersoon_opmerking").value;
  var prs_loon   = oRs("prs_contactpersoon_uurloon").value;
  var prs_systeem = oRs("prs_contactpersoon_systeem").value;
  var prs_prskey = oRs("prs_perslid_key").value;
  var prs_verwijder = oRs("prs_contactpersoon_verwijder").value;

  oRs.Close();

  if (user.iamContact()) // Als ik contactpersoon ben dan moet ik het ook van dit externe uitvoerende bedrijf zijn.
    user.auth_required_or_abort(!prs_intern && user.iamContact(prs_bdrkey));

  var isExtRel = (prs.checkAutorisation(user_key).writecontact && !prs.hasAutorisation(prs_prskey, "WEB_EXTREL").write && (prs_prskey != user_key));

  // De user kan de contactpersoon verwijderen als
  // 1) de persoon van het interne bedrijf niet is ingevuld OF
  // 2) de persoon van het interne bedrijf, die contactpersoon is, geen "EXTORD", "ORDBO2" en "EXTFIN" rechten heeft.

  // Verder moet de huidige user zelf geen contactpersoon zijn OF "WEB_RELMAN" rechten heeft.

  // Bepaal de "EXTORD", "ORDBO2" en "EXTFIN" rechten van de persoon van het interne bedrijf die contactpersoon is.
  // Als de persoon die rechten heeft mag de contactpersoon niet verwijderd worden.
  var protectedContact = false; // een protectedContact mag je niet verwijderen, pak eerst zijn rechten maar af
  if (prs_prskey)
  {
    var prs_ib = new Perslid(prs_prskey);
    protectedContact = prs_ib.has("WEB_EXTORD") || prs_ib.has("WEB_ORDBO2") || prs_ib.has("EXTFIN");
  }

  var canDeleteCP = !protectedContact && (!user.iamContact() || hasRELMAN);
%>
<html>
<head>
<%
   FCLTHeader.Generate();
   // var xfunc = user.func_enabled("*", null, null, cps_key); TODO: kritisch naar kijken, moet dit voor contactpersonen?
%>
<script  type="text/javascript">
    function cps_change()
    {
        if (FcltMgr.startEdit(window))
            window.location.href = "prs_edit_contactpersoon.asp?cps_key=<%=cps_key%>"
    }
<%
if (canDeleteCP)
  {
%>
    function cps_delete()
    {
        FcltMgr.confirm(L("lcl_prs_del_txt_contactpers"), function() {
            var data = {
                key: <%=cps_key%>,
                level: "C"
            };
            <% protectRequest.dataToken("data"); %>
            $.post("prs_delete.asp",
                data,
                FcltCallbackClose,
                "json");
        });
    }
<%
  }
%>

    function cps_reset()
    {
      FcltMgr.confirm(L("lcl_otp_clear_confirm"), function() {
        var data = { cp_key: <%=cps_key%>
                   };
        <% protectRequest.dataToken("data"); %>
        $.post("../prs/prs_perslid_otp_clear.asp"
          , data
          , FcltCallbackClose
          , "json"
        );
      });
    }

    function cps_locations()
    {
        var url = "../prs/prscontactlocs.asp?ckey=<%=cps_key%>";
        FcltMgr.openModalDetail(url, L("lcl_prs_companies_dienst_locs"));
    }
</script>
</head>

<body class="showmode">
<%
  SUBFRAME_START();
  var buttons = [];

  if (authparamsEXTRELUSE.ALGwritelevel < 9 && prs_verwijder == null)
  {
    buttons =  [ {title: L("lcl_change"), action:"cps_change()", icon: "fa-fclt-edit" } ];
    if (canDeleteCP)
      buttons.push({title: L("lcl_delete"), action:"cps_delete()", icon: "fa-trash-alt" });
    buttons.push({title: L("lcl_prs_companies_dienst_locs"), action: "cps_locations()", icon: "fa-location-arrow"});
  }
  if (isExtRel)
  {
    buttons.push({title: L("lcl_clear_otp"), action:"cps_reset()", icon: "fa-arrows-rotate-reverse"});
  }

IFRAMER_HEADER(L("lcl_prs_contactpersoon_frame"), buttons);
if (prs_verwijder != null)
{
  SIMPLE_BLOCK_START();
%>      <div class="prs_deleted"><%=L("lcl_record_is_deleted")%></div><%
  SIMPLE_BLOCK_END();
}
%>
<div id="show">
<form name="u2">
<%
BLOCK_START("prsPerslid", L("lcl_prs_basisblok"), { icon: "fa-user-md-chat" });
 var params = { infoPointer: { Url: "appl/prs/prs_bedrijf.asp?bedrijf_key=" + prs_bdrkey,
                          Title: prs_bdrnm }};

    ROFIELDTR("fld", L("lcl_prs_companies_name"), prs_bdrnm, params);
    FCLTpersoonselector("prs_prskey",
                        "prs_prskey",
                        { label: L("lcl_person"),
                          perslidKey: prs_prskey,
                          filtercode: "",
                          whenEmpty: L("lcl_search_generic"),
                          moreinfo: true,
                          info: 'PRS',
                          readonly: true,
                          suppressEmpty: true
                        });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_naam"), prs_naam, { suppressEmpty:true });
    ROFIELDTR("fldshort", L("lcl_prs_companies_contact_tussenv"), prs_tsnvgs, { suppressEmpty:true });
    ROFIELDTR("fldshort", L("lcl_prs_companies_contact_voorl"), prs_voorl, { suppressEmpty:true });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_voorn"), prs_vrnaam, { suppressEmpty:true });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_aanhef"), prs_aanh, { suppressEmpty:true });
    ROFIELDTR("fldshort", L("lcl_prs_companies_contact_titel"), prs_titel, { suppressEmpty:true });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_functie"), prs_func, { suppressEmpty:true });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_tel1"), prs_tel1, { suppressEmpty:true, type: "telefoon" });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_tel2"), prs_tel2, { suppressEmpty:true, type: "telefoon" });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_fax1"), prs_fax, { suppressEmpty:true, type: "fax" });
    ROFIELDTR("fld", L("lcl_prs_companies_contact_email"), prs_email, { suppressEmpty: true, type: "email" });
    ROTEXTAREATR("fldtxt", L("lcl_prs_companies_contact_opm"), prs_opm, {id: "prs_opm", suppressEmpty: true});
    ROFIELDTR("fldshort", L("lcl_prs_companies_uurloon"), prs_loon, {suppressEmpty: true, datatype: "currency"});
    ROCHECKBOXTR("fld", L("lcl_prs_companies_contact_systeem"), prs_systeem, {suppressEmpty: true});
BLOCK_END();
%><div id='prsFlex' class='prsFlex'></div><%
  generateFlexKenmerkCode ({
     link_key   : cps_key,
     niveau     : "C",
     reado      : true
});
%>
</form>
<% SUBFRAME_END(); %>
</body>
</html>
<% ASPPAGE_END(); %>
