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

    File:         kpn_edit_kpngroep.asp
    Description:  file to edot or add kostenplaatsgroepen
    Parameters:   kpngroep_key


    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->

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

var kpngroep_key  = getQParamInt("kpngroep_key", "-1");
if (kpngroep_key > 0)
{
  var sql = "SELECT prs_kostenplaatsgrp_key"
          + "     , prs_kostenplaatsgrp_oms"
          + "     , prs_kostenplaatsgrp_nr"
          + "     , prs_perslid_key "
          + "     , prs_kostenplaatsgrp_limiet"
          + "     , prs_kostenplaatsgrp_limperiode"
          + "  FROM prs_kostenplaatsgrp"
          + " WHERE prs_kostenplaatsgrp_key = " + kpngroep_key
  oRsMes = Oracle.Execute(sql);
  var kpngrp_oms        = oRsMes("prs_kostenplaatsgrp_oms").Value;
  var kpngrp_nr         = oRsMes("prs_kostenplaatsgrp_nr").Value;
  var prs_key           = oRsMes("prs_perslid_key").Value? oRsMes("prs_perslid_key").Value : -1;
  var kpngrp_limiet     = oRsMes("prs_kostenplaatsgrp_limiet").Value;
  var kpngrp_limperiode = oRsMes("prs_kostenplaatsgrp_limperiode").Value;
  oRsMes.Close();
}
else
{
  var kpngrp_limperiode = 0;
  var prs_key = -1;
}

// Wijzigen van de kostenplaats(groep)? Setting prs_restrict_kpedit {0=volgens autorisatie (default) | 1=alleen eigen kp/kpg wijzigen}.
// WEB_FINMSU rechten of budgethouder.
var authparams = user.checkAutorisation("WEB_FINMSU", true);
var canChangeAlg = (authparams && authparams.ALGwritelevel < 9);
var canChange = (canChangeAlg ||
                 (S("prs_restrict_kpedit") == 1 && (prs_key == user_key))) // Alleen eigen kp/kpg wijzigen
user.auth_required_or_abort(canChange);
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      function kpn_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!validateForm("u2"))
              return false;
          document.forms.u2.submit(); //TODO???
      }

      function kpn_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }
    </script>
  </head>

  <body id="editbody">
<%
    var buttons =  [ {title: L("lcl_submit"), action:"kpn_submit()", icon: "opslaan.png" },
                     {title: L("lcl_cancel"), action:"kpn_cancel()", icon: "undo.png" } ];
    IFRAMER_HEADER(L("lcl_kpn_groep_frame"), buttons);
%>
    <div id="edit">
      <form name="u2"
            action="kpn_edit_kpngroep_save.asp?kpngroep_key=<%=kpngroep_key%>"
            method="post"
            target="hidFrameSubmit"
            onSubmit="kpn_submit();">
<%      BLOCK_START("kpnMan", "");
        RWFIELDTR("kpngrp_oms",    "fld",          L("lcl_prs_descr"),        kpngrp_oms, {maxlength: 60, readonly: !canChangeAlg});
        RWFIELDTR("kpngrp_nr",     "fld",          L("lcl_prs_number"),       kpngrp_nr,  {maxlength: 10, readonly: !canChangeAlg});
        FCLTpersoonselector("prs_key", // requestor
                            "sgPerson",
                           { perslidKey: prs_key,
                             label: L("lcl_prs_budgethouder"),
                             whenEmpty: L("lcl_search_generic"), // want filter
                             readonly: !canChangeAlg });
        RWFIELDTR("kpngrp_limiet", "fld",          L("lcl_prs_limiet"),       kpngrp_limiet,  {maxlength: 8});
        sql = "SELECT        0, " + safe.quoted_sql(L("lcl_prs_none")) + ", 0 FROM DUAL"
            + " UNION SELECT 1, " + safe.quoted_sql(L("lcl_prs_month")) + ", 1 FROM DUAL"
            + " UNION SELECT 2, " + safe.quoted_sql(L("lcl_prs_year")) + ", 2 FROM DUAL"
            + " ORDER BY 3";
        FCLTselector("kpngrp_limperiode",
                     sql,
                     { initKey: kpngrp_limperiode,
                       label: L("lcl_prs_limietperiode")
                     });

        BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
      <iframe src="../Shared/empty.html" name="hidFrameSubmit" style="display:none"></iframe>
    </div>
  </body>
</html>
