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

    File:         alg_show_terreinsector.asp
    Description:  details van een terrein
    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/persoonselector.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="alg_flexkenmerk.inc" -->
<!-- #include file="alg.inc" -->

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

var ter_key  = getQParamInt("ter_key");
var onrgoedlvl = "T";
var this_alg = alg.func_enabled(ter_key, onrgoedlvl);
user.auth_required_or_abort(this_alg.readman || this_alg.readuse);

var sql = "SELECT ts.alg_locatie_key"
        + "     , ts.alg_terreinsector_omschrijving"
        + "     , ts.alg_terreinsector_code"
        + "     , ts.alg_terreinsector_naam"
        + "     , ts.alg_srtterreinsector_key"
        + "     , (SELECT " + lcl.xsqla('alg_srtterreinsec_omschrijving', 'alg_srtterreinsector_key')
          + "        FROM alg_srtterreinsector sts"
          + "       WHERE sts.alg_srtterreinsector_key = ts.alg_srtterreinsector_key) srtterreinsector_oms"
        + "     , ts.alg_terreinsector_oppervlak"
        + "     , ts.alg_terreinsector_omtrek"
        + "     , ts.alg_terreinsector_aanmaak"
        + "     , ts.alg_terreinsector_omschrijving"
        + "     , ts.alg_terreinsector_ordernr"
        + "     , ts.alg_terreinsector_image"
        + "     , ts.alg_terreinsector_toon_telef"
        + "     , ts.alg_terreinsector_toon_email"
        + "     , ts.alg_terreinsector_toon_kentk"
        + "     , ts.prs_kostenplaats_key"
        + "     ,(SELECT " + S("prs_kpn_string") + " kpstring"
          + "       FROM prs_kostenplaats k"
          + "      WHERE k.prs_kostenplaats_key = ts.prs_kostenplaats_key) kostenplaats_oms"
        + "     , ts.prs_afdeling_key"
        + "     , (SELECT prs_afdeling_omschrijving"
          + "        FROM prs_afdeling a"
          + "       WHERE a.prs_afdeling_key = ts.prs_afdeling_key) afdeling_oms"
        + "     , prs_perslid_key_verantw"
        + "     , prs_perslid_key_verantw2"
        + "     , ts.alg_terreinsector_vervaldatum"
        + "     , ts.alg_terreinsector_verwijder"
        + "  FROM alg_terreinsector ts"
        + " WHERE ts.alg_terreinsector_key = " + ter_key;
var 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_sroms = oRs("srtterreinsector_oms").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_oms   = oRs("alg_terreinsector_omschrijving").Value;
var ter_ordnr = oRs("alg_terreinsector_ordernr").Value;
var ter_image = oRs("alg_terreinsector_image").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 kp_key  = oRs("prs_kostenplaats_key").Value;
var prs_kstpl = oRs("kostenplaats_oms").Value;
var afd_key   = oRs("prs_afdeling_key").Value;
var prs_afd   = oRs("afdeling_oms").Value;
var verantw_key  = oRs("prs_perslid_key_verantw").Value;
var verantw2_key = oRs("prs_perslid_key_verantw2").Value;
var ter_deleted = oRs("alg_terreinsector_verwijder").Value != null;
var vervaldatum = oRs("alg_terreinsector_vervaldatum").Value;
oRs.Close();
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">

      $(function()
      {
        $('textarea').resize(function () { FcltMgr.resized(window) } );
        $('textarea').autogrow();
      });

      function ter_change()
      {
        if (FcltMgr.startEdit(window))
            window.location.href = "alg_edit_terreinsector.asp?ter_key=<%=ter_key%>"
      }

      function ter_delete()
      {
        FcltMgr.confirm(L("lcl_alg_del_txt_terreinsector"), function() {
            var data = {
                key: <%=ter_key%>,
                level: "T"
            };
            <% protectRequest.dataToken("data"); %>
            var ter_key = <%=ter_key%>
            $.post("alg_delete.asp",
                data,
                FcltCallbackClose,
                "json");
        });
      }

    </script>
  </head>

  <body class="showmode">
  <% SUBFRAME_START(); %>
<%  var buttons = [];
    if (!ter_deleted)
    {
      if (this_alg.writeman || this_alg.writeuse)
        buttons.push({title: L("lcl_change"), action:"ter_change()", icon: "fa-fclt-edit" });
      if (this_alg.writeman) // ALGMAN nodig
        buttons.push({title: L("lcl_delete"), action:"ter_delete()", icon: "fa-trash-alt" });
    }

    IFRAMER_HEADER(L("lcl_alg_terreinsector_frame"), buttons);
%>
<%    if (ter_deleted == 1)
      {
        SIMPLE_BLOCK_START();
%>      <div class="alg_deleted"><%=L("lcl_record_is_deleted")%></div><%
        SIMPLE_BLOCK_END();
      }
%>
      <form name=u2 onSubmit="return false;">
<%
    BLOCK_START("algter1", L("lcl_alg_terreinsector_frame"), {icon : "fa-draw-polygon"});
        FCLTplaatsselector(-1,
                           { locatiekey: loc_key,
                             startlevel: 2, // Locatie
                             eindlevel: 2, // Locatie
                             readonly: true,
                             moreinfo: true
                           });

        ROFIELDTR("fld", L("lcl_estate_terreinsector_man_name"), ter_naam);
        ROFIELDTR("fld", L("lcl_estate_terreinsector_man_code"), ter_code);
        ROFIELDTR("fld", L("lcl_estate_terreinsector_man_sort"), ter_sroms, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_estate_terreinsector_man_descr"), ter_oms);
    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,
                       readonly: true,
                       extraclass: "notmulti"
                     });
        sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonmailLOV"));
        FCLTselector("toon_email",
                    sql,
                    { label: L("lcl_estate_gebouw_toon_email"),
                      initKey: toon_email,
                      readonly: true,
                      extraclass: "notmulti"
                    });
        sql = api2.splitLOV2sql(L("lcl_estate_gebouw_toonkentLOV"));
        FCLTselector("toon_kenteken",
                    sql,
                    { label: L("lcl_estate_gebouw_toon_kenteken"),
                      initKey: toon_kenteken,
                      readonly: true,
                      extraclass: "notmulti"
                    });
    BLOCK_END();

    BLOCK_START("algter3", L("lcl_alg_gebouw_administr"), {icon: "fa-clipboard"});
        if (vervaldatum <= new Date())
                fldcls += " expired2";
        ROFIELDTR(fldcls, L("lcl_alg_vervaldatum"), toDateString(vervaldatum), {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_prs_dept_kosten"), prs_kstpl, { suppressEmpty: true, infoPointer: { Url: "appl/mgt/prs_kostenplaats.asp?mode=show&id=" + kp_key}});

        ROFIELDTR("fld", L("lcl_dep_name_level2"), prs_afd, { infoPointer: { Url: "appl/prs/prs_afdeling.asp?key=" + afd_key }});
        FCLTpersoonselector("verantw",
                            "sgVerantw",
                            { perslidKey: verantw_key,
                              label: L("lcl_alg_verantw"),
                              readonly: true,
                              moreinfo: true,
                              suppressEmpty: true
                            });
        FCLTpersoonselector("verantw2",
                            "sgVerantw2",
                            { perslidKey: verantw2_key,
                              label: L("lcl_alg_verantw2"),
                              readonly: true,
                              moreinfo: true,
                              suppressEmpty: true
                            });
        ROFIELDTR("fld", L("lcl_estate_terreinsector_ordernr"), ter_ordnr, {suppressEmpty: true});
        FILEPICKERTR("ter_image", L("lcl_alg_terreinsector_image"), ter_image, { "key": ter_key, "module": "ALGPHT", "readonly": true });
    BLOCK_END();

    if (!(ter_opp == null && ter_omt == null && vervaldatum == null))
    {
        BLOCK_START("algter4", L("lcl_alg_gebouw_fysiek"), {icon: "fa-ruler-combined"});
            ROFIELDTR("fld", L("lcl_estate_terreinsector_man_oppervlak"), ter_opp, {suppressEmpty: true, datatype: "float"});
            ROFIELDTR("fld", L("lcl_estate_terreinsector_man_omtrek"), ter_omt, {suppressEmpty: true, datatype: "float"});
            var fldcls = "fld";
        BLOCK_END();
    }

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

%>
      </form>
    <% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
