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

    File:         alg_edit_gebouw.asp
    Description:  edit of toevoegen van een gebouw
    Parameters:   bld_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/persoonselector.inc" -->
<!-- #include file="alg_flexkenmerk.inc" -->
<!-- #include file="alg.inc" -->

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

var bld_key  = getQParamInt("bld_key");

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

if (bld_key > 0)
{
  var sql = " SELECT *"
          + "   FROM alg_gebouw"
          + "  WHERE alg_gebouw_key = " + bld_key;

  oRs = Oracle.Execute(sql);
  if (oRs.Eof)
    shared.record_not_found("<!--"+bld_key+"-->");

  var bld_srtkey = oRs("alg_srtgebouw_key").Value;
  var bld_naam   = oRs("alg_gebouw_naam").Value;
  var bld_code   = oRs("alg_gebouw_code").Value;
  var bld_descr  = oRs("alg_gebouw_omschrijving").Value;
  var bld_maak   = oRs("alg_gebouw_aanmaak").Value;
  var bld_email  = oRs("alg_gebouw_email").Value;
  var bld_teken  = oRs("alg_gebouw_getekend").Value;
  var bld_opp    = oRs("alg_gebouw_bruto_vloeropp").Value;
  var bld_omtrek = oRs("alg_gebouw_omtrek").Value;
  var bld_inhoud = oRs("alg_gebouw_inhoud").Value;
  var bld_opmerk = oRs("alg_gebouw_opmerking").Value;
  var mld_adres  = oRs("mld_adres_key").Value;
  var prs_kstpl  = oRs("prs_kostenplaats_key").Value;
  var bld_ordrnr = oRs("alg_gebouw_ordernr").Value;
  var bld_dwgx   = oRs("alg_gebouw_dwgx").Value;
  var bld_dwgy   = oRs("alg_gebouw_dwgy").Value;
  var bld_x      = oRs("alg_gebouw_x").Value;
  var bld_y      = oRs("alg_gebouw_y").Value;
  var bld_bez    = oRs("alg_gebouw_bez").Value;
  var dienstniveau  = oRs("mld_dienstniveau_key").Value;
  var beginuur   = oRs("alg_gebouw_beginuur").Value;
  var einduur    = oRs("alg_gebouw_einduur").Value;
  var werkdagen  = oRs("alg_gebouw_werkdagen").Value;
  var verantw_key    = oRs("prs_perslid_key_verantw").Value;
  oRs.Close();
}
else
  var werkdagen = 1;
%>

<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_gebouw_frame"), buttons);
%>
    <div id="edit">
      <form name="u2"
            action="alg_edit_gebouw_save.asp?bld_key=<%=bld_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("algLoc1", "&nbsp;");
        FCLTplaatsselector(this_alg.authparams("WEB_ALGMAN").ALGwritelevel,
                           { gebouwkey: bld_key,
                             startlevel: 2, //Locatie
                             eindlevel: 2, // Locatie
                             readonly: bld_key > 0,
                             required: true
                           });
        manRWFIELD("bld_naam",  "fld",          L("lcl_estate_gebouw_man_name"),        bld_naam, {required: true, maxlength: 30});
        sql = "SELECT   alg_srtgebouw_key, "
            + "         "+lcl.xsqla('alg_srtgebouw_omschrijving', 'alg_srtgebouw_key')
            + "    FROM alg_srtgebouw "
            + "   WHERE alg_srtgebouw_verwijder IS NULL "
            + "ORDER BY UPPER("+lcl.xsql('alg_srtgebouw_omschrijving', 'alg_srtgebouw_key')+")";
        FCLTselector("bld_srtkey",
                     sql,
                     { label: L("lcl_estate_gebouw_srtgebouw"),
                       initKey: bld_srtkey,
                       emptyOption: "",
                       readonly: !this_alg.writeman
                     });
        manRWFIELD("bld_code",  "fld",          L("lcl_estate_gebouw_man_code"),        bld_code, {required: true, maxlength: 12});
        manRWFIELD("bld_opmerk",  "fld",          L("lcl_estate_gebouw_man_opmerk"),        bld_opmerk, {maxlength: 50});
        FCLTkostenplaatsselector(  "prs_kstpl",
                                   "prs_kstpl",
                                   user_key,
                                  { kostenplaatsKey: prs_kstpl,
                                   label: L("lcl_prs_dept_kosten"),
                                   filtercode: "G",
                                   readonly: !this_alg.writeman
                                  });
        manRWFIELD("bld_ordrnr",  "fld",          L("lcl_estate_gebouw_ordernr"),        bld_ordrnr, {maxlength: 30});
        sql = "SELECT mld_dienstniveau_key"
            + "     , " + lcl.xsqla("mld_dienstniveau_omschr", "mld_dienstniveau_key")
            + "  FROM mld_dienstniveau"
            + " ORDER BY UPPER(" + lcl.xsql("mld_dienstniveau_omschr", "mld_dienstniveau_key") + ")";
        FCLTselector("dienstniveau",
                     sql,
                     { label: L("lcl_mld_dienst_niveau"),
                       initKey: dienstniveau,
                       emptyOption: "",
                       readonly: !this_alg.writeuse
                     });
        FCLTpersoonselector("verantw",
                            "sgVerantw",
                            { perslidKey: verantw_key,
                              label: L("lcl_alg_verantw"),
                              readonly: !this_alg.writeuse,
                              autlevel: this_alg.authparams("WEB_ALGMAN") && this_alg.authparams("WEB_ALGMAN").PRSwritelevel
                            });
        manRWFIELD("bld_email",  "fld",     L("lcl_alg_gebouw_email"),       bld_email, {maxlength: 200});
        BLOCK_END();

        BLOCK_START("algLoc2", "&nbsp;");
        if (bld_key > 0)
        {
          var calcopp = alg.calc_algm2(bld_key, onrgoedlvl); 
          ROFIELDTR("fld", L("lcl_estate_ruimte_bruto_vloeropp") + L("lcl_estate_calc_vloeropp"), calcopp.oppbruto, {suppressEmpty: true});
          ROFIELDTR("fld", L("lcl_estate_ruimte_opp_alt1") + L("lcl_estate_calc_vloeropp"), calcopp.oppalt1, {suppressEmpty: true});
          ROFIELDTR("fld", L("lcl_estate_ruimte_opp_alt2") + L("lcl_estate_calc_vloeropp"), calcopp.oppalt2, {suppressEmpty: true});
        }
        manRWFIELD("bld_opp",  "fld float",          L("lcl_estate_gebouw_man_bruto_vloeropp"),        bld_opp, {datatype:"float", maxlength: 15});
        manRWFIELD("bld_omtrek",  "fld",          L("lcl_estate_gebouw_man_omtrek"),        bld_omtrek, {maxlength: 15});
        manRWFIELD("bld_inhoud",  "fld",          L("lcl_estate_gebouw_man_inhoud"),        bld_inhoud, {maxlength: 15});
        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: !this_alg.writeman
                     });
        manRWFIELD("bld_x",  "fld",          L("lcl_geoxcoord"),        bld_x, {maxlength: 25});
        manRWFIELD("bld_y",  "fld",          L("lcl_geoycoord"),        bld_y, {maxlength: 25});
        if (this_alg.writeman)
          CHECKBOXTR(L("lcl_estate_gebouw_bez"), "fldalgbez", "bld_bez", bld_bez==1)
        var times = [];
        for (i=0; i<24; i++)
        {
          sql = "           SELECT " + String(i+0/4) + ", '" + String(i) + ":00' FROM DUAL"
              + " UNION ALL SELECT " + String(i+1/4) + ", '" + String(i) + ":15' FROM DUAL"
              + " UNION ALL SELECT " + String(i+2/4) + ", '" + String(i) + ":30' FROM DUAL"
              + " UNION ALL SELECT " + String(i+3/4) + ", '" + String(i) + ":45' FROM DUAL"
          times.push(sql);
        }
        FCLTselector("bld_beginuur", times.join(" UNION ALL "),
                        {  label: L("lcl_estate_gebouw_beginuur"),
                           initKey: beginuur,
                           emptyOption: "",
                           readonly: !this_alg.writeman
                        }
                      );
        FCLTselector("bld_einduur", times.join(" UNION ALL "),
                        {  label: L("lcl_estate_gebouw_einduur"),
                           initKey: einduur,
                           emptyOption: "",
                           readonly: !this_alg.writeman
                        }
                      );
        if (this_alg.writeman)
          CHECKBOXTR(L("lcl_estate_gebouw_werkdagen"), "fldalgwerk", "bld_werkdagen", werkdagen==1)
        BLOCK_END();

        generateFlexKenmerkBlock ({ onrgoed_key    : bld_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>
