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

    File:         alg_edit_terreinsector.asp
    Description:  Wijzigen of toevoegen van geselecteerde terreinsector
    Parameters:   ter_key

    Context:
    Note:

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

<!--#include file="../Shared/plaatsselector.inc" -->
<!--#include file="../Shared/kostenplaatsselector.inc" -->
<!--#include file="../Shared/afdelingselector.inc" -->
<!-- #include file="alg_flexkenmerk.inc" -->
<!-- #include file="alg.inc" -->

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

var ter_key  = getQParamInt("ter_key", -1);

var onrgoedlvl = "T";
var this_alg = alg.func_enabled(ter_key, onrgoedlvl);
user.auth_required_or_abort(this_alg.writeman || (ter_key>0&&this_alg.writeuse));

if (ter_key > 0)
{
    sql = "SELECT "
        + "  alg_locatie_key"
        + ", alg_terreinsector_omschrijving"
        + ", alg_terreinsector_code"
        + ", alg_terreinsector_naam"
        + ", alg_srtterreinsector_key"
        + ", alg_terreinsector_oppervlak"
        + ", alg_terreinsector_omtrek"
        + ", alg_terreinsector_aanmaak"
        + ", alg_terreinsector_ordernr"
        + ", prs_kostenplaats_key"
        + ", prs_afdeling_key"
        + "  FROM alg_terreinsector "
        + " WHERE alg_terreinsector_key = " + ter_key;

    oRs = Oracle.Execute(sql);

      var loc_key   = oRs("ALG_LOCATIE_KEY").value;
      var ter_oms   = oRs("ALG_TERREINSECTOR_OMSCHRIJVING").value;
      var ter_code  = oRs("ALG_TERREINSECTOR_CODE").value;
      var ter_naam  = oRs("ALG_TERREINSECTOR_NAAM").value;
      var ter_srkey = oRs("ALG_SRTTERREINSECTOR_KEY").value;
      var ter_opp   = oRs("ALG_TERREINSECTOR_OPPERVLAK").value;
      var ter_omt   = oRs("ALG_TERREINSECTOR_OMTREK").value;
      var ter_aanmk = oRs("ALG_TERREINSECTOR_AANMAAK").value;
      var ter_ordnr = oRs("ALG_TERREINSECTOR_ORDERNR").value;
      var prs_kstn  = oRs("PRS_KOSTENPLAATS_KEY").value;
      var prs_afd   = oRs("PRS_AFDELING_KEY").value;

    oRs.Close();
}
%>

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

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

<body id="editbody">
<%
  var buttons =  [ {title: L("lcl_submit"), action:"alg_submit()", icon: "opslaan.png" },
                   {title: L("lcl_cancel"), action:"alg_cancel()", icon: "undo.png" } ];
  IFRAMER_HEADER(L("lcl_alg_terreinsector_frame"), buttons);
%>
<div id="edit">
<form name="u2"
      action="alg_edit_terreinsector_save.asp?ter_key=<%=ter_key%>"
      method="post"
      target="hidFrameSubmit"
      onSubmit="alg_submit();">

<%
if (this_alg.writeman)
    manRWFIELD = RWFIELDTR;
else
    manRWFIELD = function (a,b,c,d,e) { ROFIELDTR(b,c,d,e) }; // als geen USE of <self> dan zijn er veel readonly

BLOCK_START("algInfo", "");

  FCLTplaatsselector(this_alg.authparams("WEB_TERMAN").ALGwritelevel, {
                    locatiekey: loc_key,
                    startlevel: 2, // Locatie
                    eindlevel: 2, // Locatie
                    readonly: false, //ter_key > 0,
                    required: true });

  sql = "SELECT   alg_srtterreinsector_key, "
      + lcl.xsqla('alg_srtterreinsec_omschrijving', 'alg_srtterreinsector_key')
      + "    FROM alg_v_aanwezigsrtterreinsector "
      + "ORDER BY UPPER("+lcl.xsql('alg_srtterreinsec_omschrijving', 'alg_srtterreinsector_key')+")";

  FCLTselector("ter_srkey", sql,
              {  label: L("lcl_estate_terreinsector_man_sort"),
                 initKey: ter_srkey,
                 emptyOption: "",
                 readonly: false
              });

  RWFIELDTR("ter_code", "fld", L("lcl_estate_terreinsector_man_code"), ter_code, {maxlength: 12, required: true});
  RWFIELDTR("ter_naam", "fld", L("lcl_estate_terreinsector_man_name"), ter_naam, {maxlength: 30, required: true});

  FCLTkostenplaatsselector( "prs_kstn",
                          "prs_kstn",
                          user_key,
                          { kostenplaatsKey: prs_kstn,
                            label: L("lcl_prs_dept_kosten") });

  FCLTafdelingselector("prs_afd",
                       "sgDept",
                        { label: L("lcl_dep_name_level2"),
                          departmentKey: prs_afd,
                          //autlevel: authparams.PRSreadlevel,
                          whenEmpty: L("lcl_search_generic")
                        });

  RWFIELDTR("ter_ordnr", "fld", L("lcl_estate_terreinsector_ordernr"), ter_ordnr, {maxlength: 30});
  RWFIELDTR("ter_opp", "fld", L("lcl_estate_terreinsector_man_oppervlak"), ter_opp, {maxlength: 15});
  RWFIELDTR("ter_omt", "fld", L("lcl_estate_terreinsector_man_omtrek"), ter_omt, {maxlength: 15});

BLOCK_END();

generateFlexKenmerkBlock ({
     onrgoed_key    : ter_key,
     onrgoed_niveau : onrgoedlvl,
     reado          : false,
     flexcolumns    : S("alg_flexcolumns"),
     this_alg       : this_alg
});

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