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

    File:               ins_edit_multi.asp
    Description:        Multi editten van de flexkenmerken van objecten
    Parameters:         ins_keys

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc" -->
<!-- #include file="./ins_flexkenmerk.inc" -->
<!-- #include file="ins.inc" -->

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

var urole = getQParamSafe("urole");
var ins_key_arr = getQParamIntArray("ins_keys");
var submitting = getQParamInt("submit", 0) == 1;

var warning = "";
var result = {};
var tobeedited = 0;
var ingesloten = [];
// Bepaal de objecten in de selectie die
// ook echt geinspecteerd kunnen of mogen worden.
for (var i = 0; i < ins_key_arr.length; i++)
{
  var this_ins = ins.func_enabled_deel(ins_key_arr[i]);
  if (this_ins.canChange)
  {
    ingesloten.push(ins_key_arr[i]);
    tobeedited++;
    var last_this_ins = this_ins; // 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

if (ins.isSleCil(ingesloten[0]))
{
    var autfunction = "WEB_SLEBOF";
    module = "SLE";
}
else
    var autfunction = getQParam("pautfunction", (urole == "fo"? "WEB_INSFOF" : "WEB_INSMAN"));
authparams = last_this_ins.authparams(autfunction);
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
<%
    if (submitting)
    {
      var fields = [];
      if (last_this_ins.canChangeAlg && getFParam("vervaldatum"))
        fields.push({ dbs: "ins_deel_vervaldatum", typ: "date",    frm: "vervaldatum",  track: L("lcl_ins_vervaldatum") });
//      if (last_this_ins.canChangeAlg && getFParam("aanmaakdatum"))
//        fields.push({ dbs: "ins_deel_aanmaak",     typ: "date",    frm: "aanmaakdatum", track: L("lcl_last_action") });
      if (last_this_ins.canChangeAlg && getFParam("ins_manager"))
        fields.push({ dbs: "prs_perslid_key_beh",  typ: "key",     frm: "ins_manager", track: L("lcl_ins_manager"), foreign: "prs_perslid" });

      for (var i = 0; i < ingesloten.length; i++)
      { // Ik mag het object wijzigen dus voer wijziging uit
        var insUpd = buildTrackingUpdate("ins_deel", " ins_deel_key = " + ingesloten[i], fields);
        // Submit the changed data
        var err = Oracle.Execute(insUpd.sql, true);
        if (err.friendlyMsg)
            warning = err.friendlyMsg;

        /* flextrackarray = */ ins.updateKenmerkdeel(ingesloten[i], {multimode: true});

        var update_string = L("lcl_ins_is_insupd") + "\n" + insUpd.trackarray.join("\n");
        shared.trackaction("INSUPD", ingesloten[i], update_string);
      }

%>    <script type="text/javascript">
        $(document).ready(function()
                          {
                            FcltMgr.closeDetail(window, { success: true } )
                          });
      </script>
<%    Response.End();
    }
%>

    <script type="text/javascript">
      function ins_submit()
      {
        document.forms.u2.submit();
        return true; // disable button
      }

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


  <body class="modal" id="mod_insmultiedit">
<%
    sql = "SELECT DISTINCT s.ins_srtdeel_key"   // PF: verondersteld de omschrijving overbodig hier
        + ", d.ins_alg_ruimte_type"
        + ", d.ins_alg_locatie_key"
        + " FROM ins_deel d"
        + ", ins_srtdeel s"
        + " WHERE s.ins_srtdeel_key = d.ins_srtdeel_key"
        + " AND d.ins_deel_key in (" + ingesloten.join(",") + ")";
    oRs = Oracle.Execute(sql);
    var ins_srtdeel_key = oRs("ins_srtdeel_key").value;
    var diff_objsrt = false;
    var i = 0;
    while (!oRs.eof)
    {
      i++;
      if (oRs("ins_srtdeel_key").value != ins_srtdeel_key) diff_objsrt = true;
      oRs.MoveNext();
    }
    oRs.close();
%>
    <form name="u2" action="ins_edit_deel_multi.asp?submit=1&ins_keys=<%=ingesloten.join(",")%>&urole=<%=urole%>" method="post">
<%
      if (diff_objsrt)
      {
        Response.write(L("lcl_ins_diff_objsrt"));
      }
      else
      {
          if (last_this_ins.canChangeAlg)
          {
              BLOCK_START("insGeo", L("lcl_ins_meta_data"));
//              FCLTcalendar("aanmaakdatum",
//                           { initEmpty: true,
//                             label: L("lcl_last_action"),
//                             volgnr: 1
//                           });
              FCLTcalendar("vervaldatum",
                           { initEmpty: true,
                             label: L("lcl_ins_vervaldatum"),
                             volgnr: 2
                           });
              FCLTpersoonselector("ins_manager", // beheerder
                                "sgins_manager",
                               { perslidKey: -1,
                                 autlevel: authparams && authparams.PRSwritelevel,
                                 label: L("lcl_ins_manager"),
                                 filtercode: "INSB",
                                 moreinfo: false
                              });
           BLOCK_END();
        }


        generateFlexKenmerkBlock({
            fnpre: function () {BLOCK_START("insMultiEdit", L("lcl_flexible_properties"));},
            fnpost: BLOCK_END,
            urole: urole,
            ins_key: -1,
            srtdeelkey_array: ins_srtdeel_key > 0? [ins_srtdeel_key] : [],
            nodefaults: true,
            reado: false,
            multi: true,
            flexcolumns: 1 // altijd want popup
          });
      }
      var buttons =  [];
      if (ins_srtdeel_key > 0 && !diff_objsrt)
        buttons.push({title: L("lcl_submit"), action:"ins_submit()", singlepress: true, id: "btn_edit_submit"})
      buttons.push({title: L("lcl_cancel"),  action:"ins_cancel()"})
      CreateButtons(buttons)
IFACE.FORM_END();
%>
    </form>
  </body>
</html>
