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

    File:         prs_show_afdeling.asp
    Description:  Details van een afdeling
    Parameters:

    Context:
    Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="prs_flexkenmerk.inc" -->
<!-- #include file="prs.inc" -->

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

var afd_key  = getQParamInt("afd_key", "-1");
var afd_niveau = getQParamInt("afd_niveau", -1);

var autfunction = "WEB_PRSUSE";

var authparams = user.checkAutorisation(autfunction);

sql = "SELECT prs_afdeling_key"
    + "     , prs_afdeling_naam"
    + "     , prs_afdeling_omschrijving"
    + "     , prs_bedrijf_key"
    + "     , prs_afdeling_parentkey"
    + "     , mld_adres_key"
    + "     , prs_kostenplaats_key"
    + "     , prs_perslid_key_verantw"
    + "     , prs_afdeling_verwijder"
    + "  FROM prs_afdeling"
    + " WHERE prs_afdeling_key = " + afd_key

oRs = Oracle.Execute(sql);

var afd_key     = oRs("prs_afdeling_key").value;
var afd_naam    = oRs("prs_afdeling_naam").value;
var afd_oms     = oRs("prs_afdeling_omschrijving").value;
var bdr_key     = oRs("prs_bedrijf_key").value;
var afd_parkey  = oRs("prs_afdeling_parentkey").value;
var mld_adres   = oRs("mld_adres_key").value;
var kstpl_key   = oRs("prs_kostenplaats_key").value;
var verantw_key = oRs("prs_perslid_key_verantw").value;
var afd_deleted = oRs("prs_afdeling_verwijder").value != null;
oRs.Close();
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script  type="text/javascript" >
      function afd_change()
      {
          if (FcltMgr.startEdit(window))
              window.location.href = "prs_edit_afdeling.asp?afd_key=<%=afd_key%>&afd_niveau=<%=afd_niveau%>"
      }
      function afd_delete()
      {
          FcltMgr.confirm(L("lcl_prs_del_txt_afdeling"), function() {
              var afd_key = <%=afd_key%>;
              var data = {
                  key: <%=afd_key%>,
                  level: "A"
              };
              <% protectRequest.dataToken("data"); %>
              $.post("prs_delete.asp",
                  data,
                  FcltCallbackClose,
                  "json");
          });
      }
    </script>
  </head>
  <body class="showmode">
<%  SUBFRAME_START();
    var buttons = [];

    if (!afd_deleted && prs.canWriteAfdeling(afd_key, autfunction))
    {
      var buttons =  [ {title: L("lcl_change"), action:"afd_change()", icon: "fa-fclt-edit" },
                       {title: L("lcl_delete"), action:"afd_delete()", icon: "fa-trash-alt" } ];
    }
    IFRAMER_HEADER(L("lcl_prs_afdeling_frame"), buttons);
    if (afd_deleted == 1)
      {
        SIMPLE_BLOCK_START();
%>      <div class="prs_deleted"><%=L("lcl_record_is_deleted")%></div><%
        SIMPLE_BLOCK_END();
      }
%>
      <form name="u2" onSubmit="return false;">
<%      BLOCK_START("prsAfd", L("lcl_dep_name_level"+afd_niveau), {icon: "fa-users"});
        if (afd_niveau == 1)
        {
          sql =  "SELECT prs_bedrijf_key"
              + "      , prs_bedrijf_naam"
              + "   FROM prs_bedrijf"
              + "  WHERE prs_bedrijf_key = " + bdr_key;
          oRs = Oracle.Execute(sql);
          ROFIELDTR("fld", L("lcl_prs_dept_company"), oRs("prs_bedrijf_naam").Value, {infoPointer: { Url: "appl/prs/prs_bedrijf.asp?bedrijf_key="+bdr_key, Title:L("lcl_details") }});
        }
        else if (afd_niveau > 1)
        {
          FCLTafdelingselector("afd_parkey",
                               "afd_parkey",
                              { departmentKey: afd_parkey,
                                label: L("lcl_dep_name_level" + (afd_niveau - 1)), // Nu Afdeling, was L("lcl_BES_organisation") => Organisatie
                                autlevel: authparams.PRSreadlevel, // Was voorheen niet aanwezig
                                filtercode: String(afd_niveau - 1),
                                readonly: true });
        }
        ROFIELDTR("fld", L("lcl_prs_dept_name"), afd_naam);
        ROFIELDTR("fld", L("lcl_prs_dept_desc"), afd_oms, {suppressEmpty:true});
        FCLTkostenplaatsselector( "kstpl_key",
                                  "kstpl_key",
                                  user_key,
                                  {label: L("lcl_prs_dept_kosten"),
                                   kostenplaatsKey: kstpl_key,
                                   readonly: true, 
                                   suppressEmpty: true });

        FCLTpersoonselector("prs_verantwkey",
                            "prs_verantwkey",
                            { label: L("lcl_prs_dept_verantw"),
                              perslidKey: verantw_key,
                              moreinfo: true,
                              info: 'PRS',
                              readonly: true,
                              suppressEmpty: true
                            });

        sql = "SELECT mld_adres_naam"
            + "  FROM mld_adres"
            + " WHERE mld_adres_key = " + mld_adres;
        oRs = Oracle.Execute(sql);
        if (!oRs.eof)
        {
            ROFIELDTR("fld", L("lcl_delivery_address"), oRs("mld_adres_naam").value, {suppressEmpty: true});
        }
        oRs.Close();
        BLOCK_END();

        %><div id='prsAFlex' class='prsAFlex'></div><%
        generateFlexKenmerkCode({link_key   : afd_key,
                                 niveau     : "A",
                                 reado      : true
                                });
%>
      </form>
      <% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
