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

    File:               alg_edit_ruimte_multi.asp
    Description:        Multi editten van de flexkenmerken van ruimtes
    Parameters:         alg_keys

    Context:
    Note:

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

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

var alg_key_arr = getQParamIntArray("alg_keys");
var alg_level = getQParam("alg_level");

var warning = "";
var result = {};
var tobeedited = 0;
var ingesloten = [];
// Bepaal de ruimtes in de selectie die
// ook echt bewerkt kunnen of mogen worden.
for (var i = 0; i < alg_key_arr.length; i++)
{
    var this_alg = alg.func_enabled(alg_key_arr[i], "R");
    if (this_alg.writeman || this_alg.writeuse)
    {
        ingesloten.push(alg_key_arr[i]);
        tobeedited++;
        var last_this_alg = this_alg; // deze gebruiken we voor rechtencontrole. Niet 100% zuiver maar goed genoeg
    }
}
user.auth_required_or_abort(tobeedited > 0); // We klagen niet over enkele wel en enkele niet

var sql = "SELECT alg_srtruimte_key"
        + "     , mld_dienstniveau_key"
        + "     , alg_ruimte_omschrijving"
        + "     , alg_ruimte_opmerking"
        + "     , alg_ruimte_beginuur"
        + "     , alg_ruimte_einduur"
        + "     , alg_ruimte_werkdagen"
        + "  FROM alg_ruimte"
        + " WHERE alg_ruimte_key in (" + ingesloten.join(",") + ")";
var oRs = Oracle.Execute(sql);
if (!oRs.eof)
{
    var diff = { srtruimte_key:    oRs("alg_srtruimte_key").Value,
                 dienstniveau_key: oRs("mld_dienstniveau_key").Value,
                 omschrijving:     oRs("alg_ruimte_omschrijving").Value,
                 opmerking:        oRs("alg_ruimte_opmerking").Value,
                 beginuur:         oRs("alg_ruimte_beginuur").Value,
                 einduur:          oRs("alg_ruimte_einduur").Value,
                 werkdagen:        oRs("alg_ruimte_werkdagen").Value
               };
    var i = 0;
    while (!oRs.eof)
    {
        i++;
        if (diff.srtruimte_key    != oRs("alg_srtruimte_key").Value)       diff.srtruimte_key = null;
        if (diff.dienstniveau_key != oRs("mld_dienstniveau_key").Value)    diff.dienstniveau_key = null;
        if (diff.omschrijving     != oRs("alg_ruimte_omschrijving").Value) diff.omschrijving = null;
        if (diff.opmerking        != oRs("alg_ruimte_opmerking").Value)    diff.opmerking = null;
        if (diff.beginuur         != oRs("alg_ruimte_beginuur").Value)     diff.beginuur = null;
        if (diff.einduur          != oRs("alg_ruimte_einduur").Value)      diff.einduur = null;
        if (diff.werkdagen        != oRs("alg_ruimte_werkdagen").Value)    diff.werkdagen = null;
        oRs.MoveNext();
    }
}
oRs.Close();

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
        $(function () { $("select option[value=-1]").val(""); }); // prevents removal of values from listboxes
        function alg_submit()
        {
            $.post($("form[name=u2]")[0].action,
                   $("[name=u2]").serialize(),
                   FcltCallbackAndThenAlways(alg_submit_callback),
                   "json");
            return true; // disable button
        }

        function alg_submit_callback(json)
        {
            iface.button.enable("btn_alg_submit");
            if (json.success)
                FcltMgr.closeDetail(window, json);
        }

        function alg_cancel()
        {
            FcltMgr.closeDetail(window, { cancel: true } );
        }

    </script>
  </head>

  <body class="fclt-modal" id="mod_algmultiedit">
  <% MODAL_START(); %>
    <form name="u2" action="alg_edit_ruimte_multi_save.asp?alg_level=<%=safe.htmlattr(alg_level)%>&alg_keys=<%=ingesloten.join(",")%>" method="post">
<%
        if (last_this_alg.writeman || last_this_alg.writeuse)
        {
            MODAL_BLOCK_START("algFlex", L("lcl_ins_meta_data"), { icon: "fa-map-marker" });
                // ruimte specifieke velden
                if (last_this_alg.writeman)
                {
                    sql = "SELECT alg_srtruimte_key"
                        + "     , " + lcl.xsqla("alg_srtruimte_omschrijving", "alg_srtruimte_key")
                        + "  FROM alg_v_aanwezigsrtruimte"
                        + " ORDER BY UPPER("+lcl.xsql("alg_srtruimte_omschrijving", "alg_srtruimte_key")+")";
                    FCLTselector( "room_srt",
                                  sql,
                                  { label: L("lcl_estate_ruimte_man_sort"),
                                    emptyOption: "",
                                    initEmpty: true
                                  });
                }

                if (last_this_alg.writeuse)
                {
                    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"),
                                    emptyOption: "",
                                    initEmpty: true
                                  });

                    RWFIELDTR("room_oms",  "fld", L("lcl_estate_ruimte_man_descr"),  diff.omschrijving, {maxlength: 30});
                }

                if (last_this_alg.writeman)
                {
                    //RWFIELDTR("room_opm",  "fld", L("lcl_estate_ruimte_man_opmerk"), diff.opmerking,    {maxlength: 50});

                    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( "room_beginuur",
                                  times.join(" UNION ALL "),
                                  { label: L("lcl_estate_gebouw_beginuur"),
                                    emptyOption: "",
                                    initEmpty: true
                                  }
                                );
                    FCLTselector( "room_einduur",
                                  times.join(" UNION ALL "),
                                  { label: L("lcl_estate_gebouw_einduur"),
                                    emptyOption: "",
                                    initEmpty: true
                                  }
                                );

                    sql = "           SELECT null, " + safe.quoted_sql(L("lcl_alg_ruimte_volgens_gebouw")) + " FROM DUAL"
                        + " UNION ALL SELECT 0, "    + safe.quoted_sql(L("lcl_No"))  + " FROM DUAL"
                        + " UNION ALL SELECT 1, "    + safe.quoted_sql(L("lcl_Yes")) + " FROM DUAL";
                    FCLTselector( "room_werkdagen",
                                  sql,
                                  { label: L("lcl_estate_gebouw_werkdagen"),
                                    emptyOption: "",
                                    initEmpty: true
                                  }
                                );
                }
            MODAL_BLOCK_END();
        }

        generateFlexKenmerkBlock({
            onrgoed_niveau: "R",
            onrgoed_key: -1,
            this_alg: last_this_alg,
            reado: false,
            multi: true
          });

%>
    <script>
      $(function()
        {
          init_multi();
        });
    </script>
<%

    var buttons =  [];
    buttons.push({title: L("lcl_submit"), action: "alg_submit()", singlepress: true, id: "btn_alg_submit", importance: 1, icon: "fa-fclt-save"});
    buttons.push({title: L("lcl_cancel"), action: "alg_cancel()", importance: 3, icon: "fa-fclt-cancel"});
    SIMPLE_BLOCK_START();
    CreateButtons(buttons);
    SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
