<%@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="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_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 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()
      {
         var afd_key = <%=afd_key%>;
         if (confirm(L("lcl_prs_del_txt_afdeling")))
         {
            var data = { key: <%=afd_key%>
                       , level: "A"
                       };
            <% protectRequest.dataToken("data"); %>
            $.post("prs_delete.asp",
                   data,
                   FcltCallbackClose,
                   "json");
         }
      }
    </script>
  </head>
  <body id="showbody">
<%  var buttons = [];

    if (!afd_deleted && prs.canWriteAfdeling(afd_key, autfunction))
    {
      var buttons =  [ {title: L("lcl_change"), action:"afd_change()", icon: "wijzigen.png" },
                       {title: L("lcl_delete"), action:"afd_delete()", icon: "delete.png" } ];
    }
    IFRAMER_HEADER(L("lcl_prs_afdeling_frame"), buttons);
%>
    <div id="show">
<%    if (afd_deleted == 1)
      {
%>      <div class="prs_deleted"><%=L("lcl_record_is_deleted")%></div><%
      }
%>
      <form name="u2" onSubmit="return false;">
<%      BLOCK_START("prsAfd", L("lcl_dep_name_level"+afd_niveau));
        if (afd_niveau == 1)
        {
          sql =  "SELECT prs_bedrijf_key"
              + "      , prs_bedrijf_naam"
              + "   FROM prs_bedrijf"
              + "  WHERE prs_bedrijf_verwijder IS NULL AND prs_bedrijf_intern = 1"
              + " ORDER BY prs_bedrijf_naam_upper ";

          FCLTselector("bdr_key", sql,
                      {  label: L("lcl_prs_dept_company"),
                         initKey: bdr_key,
                         emptyOption: "",
                         readonly: true });
        }
        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 });

        sql = "SELECT mld_adres_key"
            + "     , mld_adres_naam"
            + "  FROM mld_v_afleveradres"
            + " ORDER BY mld_adres_naam ";
        FCLTselector("mld_adres", sql,
                    {  label: L("lcl_delivery_address"),
                       initKey: mld_adres,
                       emptyOption: "",
                       readonly: true });
        BLOCK_END();

        BLOCK_START("prsAFlex"+(S("prs_flexcolumns")!=1?"2":""), L("lcl_prs_flexblok"));
        generateFlexKenmerkCode({link_key   : afd_key,
                                 niveau     : "A",
                                 reado      : true,
                                 flexcolumns: S("prs_flexcolumns")
                                });
        BLOCK_END();
%>
      </form>
    </div>
  </body>
</html>
