<%@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/calendar.inc" -->

<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../API2/api2.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"
        + ", alg_terreinsector_image"
        + ", alg_terreinsector_toon_telef"
        + ", alg_terreinsector_toon_email"
        + ", alg_terreinsector_toon_kentk"
        + ", alg_terreinsector_vervaldatum"
        + ", prs_kostenplaats_key"
        + ", prs_afdeling_key"
        + ", prs_perslid_key_verantw"
        + ", prs_perslid_key_verantw2"
        + "  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 ter_image = oRs("alg_terreinsector_image").Value;
    var prs_kstn  = oRs("prs_kostenplaats_key").Value;
    var prs_afd   = oRs("prs_afdeling_key").Value;
    var verantw_key    = oRs("prs_perslid_key_verantw").Value
    var verantw_key2   = oRs("prs_perslid_key_verantw2").Value;
    var toon_telefoon  = oRs("alg_terreinsector_toon_telef").Value;
    var toon_email     = oRs("alg_terreinsector_toon_email").Value;
    var toon_kenteken  = oRs("alg_terreinsector_toon_kentk").Value;
    var vervaldatum = oRs("alg_terreinsector_vervaldatum").Value != null ? new Date(oRs("ALG_TERREINSECTOR_VERVALDATUM").Value) : null;

    oRs.Close();
}
else
{
    var toon_telefoon  = 0;
    var toon_email     = 0;
    var toon_kenteken  = 0;
}
%>

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

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

<body class="editmode">
<% SUBFRAME_START(); %>
<%
  var buttons =  [ {title: L("lcl_submit"), action:"alg_submit()", icon: "fa-fclt-save" },
                   {title: L("lcl_cancel"), action:"alg_cancel()", icon: "fa-fclt-cancel" } ];
  IFRAMER_HEADER(L("lcl_alg_terreinsector_frame"), buttons);
%>
<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("algter1", L("lcl_alg_terreinsector_frame"), {icon : "fa-draw-polygon"});

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

  RWFIELDTR("ter_naam", "fld", L("lcl_estate_terreinsector_man_name"), ter_naam, {maxlength: 30, required: true});
  RWFIELDTR("ter_code", "fld", L("lcl_estate_terreinsector_man_code"), ter_code, {maxlength: 12, 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_oms", "fld", L("lcl_estate_terreinsector_man_descr"), ter_oms, {maxlength: 60});
BLOCK_END();

  BLOCK_START("algLoc5", L("lcl_alg_gebouw_bezoek"), {icon: "fa-user-tag"});
  var sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toontelfLOV"));
  FCLTselector("toon_telefoon",
              sql,
              { label: L("lcl_estate_gebouw_toon_telefoon"),
                initKey: toon_telefoon,
                extraclass: "notmulti"
              });
  sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonmailLOV"));
  FCLTselector("toon_email",
             sql,
             { label: L("lcl_estate_gebouw_toon_email"),
               initKey: toon_email,
               extraclass: "notmulti"
             });
  sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonkentLOV"));
  FCLTselector("toon_kenteken",
             sql,
             { label: L("lcl_estate_gebouw_toon_kenteken"),
               initKey: toon_kenteken,
               extraclass: "notmulti"
             });
BLOCK_END();

BLOCK_START("algter3", L("lcl_alg_gebouw_administr"), {icon: "fa-clipboard"});
  FCLTcalendar("vervaldatum",
               { datum: vervaldatum,
                 initEmpty: vervaldatum==null,
                 label: L("lcl_alg_vervaldatum"),
                 readonly: !this_alg.writeman
               });

  FCLTkostenplaatsselector( "prs_kstn",
                          "prs_kstn",
                          user_key,
                          { kostenplaatsKey: prs_kstn,
                            label: L("lcl_prs_dept_kosten") });
  RWFIELDTR("ter_ordnr", "fld", L("lcl_estate_gebouw_ordernr"), ter_ordnr, {maxlength: 30});

  FCLTpersoonselector("verantw",
                      "sgVerantw",
                      { perslidKey: verantw_key,
                        label: L("lcl_alg_verantw"),
                        autlevel: this_alg.authparams("WEB_TERMAN") && this_alg.authparams("WEB_TERMAN").PRSwritelevel
                      });
  FCLTpersoonselector("verantw2",
                      "sgVerantw2",
                      { perslidKey: verantw_key2,
                        label: L("lcl_alg_verantw2"),
                        autlevel: this_alg.authparams("WEB_TERMAN") && this_alg.authparams("WEB_TERMAN").PRSwritelevel
                      });
  FCLTafdelingselector("prs_afd",  // geen idee eigenlijk wat die hier doet? Als huurder? Parkeerders.
                       "sgDept",
                        { label: L("lcl_dep_name_level2"),
                          departmentKey: prs_afd
                          //autlevel: authparams.PRSreadlevel
                        });
  FILEPICKERTR("ter_image", L("lcl_alg_terreinsector_image"), ter_image, { "key": ter_key, "module": "ALGPHT", "readonly": !this_alg.writeman });
BLOCK_END();

BLOCK_START("algter4", L("lcl_alg_gebouw_fysiek"), {icon: "fa-ruler-combined"});

  RWFIELDTR("ter_opp", "fldshort", L("lcl_estate_terreinsector_man_oppervlak"), ter_opp, {maxlength: 15});
  RWFIELDTR("ter_omt", "fldshort", L("lcl_estate_terreinsector_man_omtrek"), ter_omt, {maxlength: 15});

BLOCK_END();


generateFlexKenmerkBlock ({
     onrgoed_key    : ter_key,
     onrgoed_niveau : onrgoedlvl,
     reado          : false,
     this_alg       : this_alg
});

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