<%@ LANGUAGE = JavaScript %>
<%  Server.ScriptTimeout=6000; %>
<% /*
     $Revision$
     $Id$

     File:               ins_inspect_unexecute.asp
     Description:        Het uitvoeren van deze taak ongedaan maken.
     Parameters:
         deelsrtcont_keys    Array van inspecties die moeten worden gestart.

     Context:            Inline actie ins_list.inc of actie ins_inspect_list
                         Resultaat van een submit is een json object

*/ %>

<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/save2db.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="../API2/model_issues.inc" -->
<!-- #include file="ins.inc" -->

<%
protectRequest.validateToken();
var mld_key = getFParamInt("mld_key");
var ins_key = getFParamIntArray("ins_key");
var srtcont_key = getFParamIntArray("srtcont_key", []);
var deelsrtcont_key = getFParamIntArray("deelsrtcont_key", []);

var mjb_start_year = S("mjb_start_year");
var mjb_freeze_year = Math.max(S("mjb_freeze_year"), new Date().getFullYear());

var ingesloten = [];
var tobestart = 0;
var dlsrtcont_key = -1;
// Bepaal of de taak uitgevoerd kan en mag worden.
// ook echt gestart kunnen of mogen worden.
var ctrdisc_key = -1;

var sql = "SELECT xcp.ctr_discipline_key"
        + "  FROM ins_v_defined_inspect_xcp xcp"
        + " WHERE xcp.ins_deel_key = " + ins_key
        + "   AND xcp.ins_srtcontrole_key = " + srtcont_key
        + "   AND xcp.ins_scenario_key = 1";
var oRs = Oracle.Execute(sql);
ctrdisc_key = oRs("ctr_discipline_key").Value;
oRs.Close();

var this_ins = ins.func_enabled_deel(ins_key,
                                     {srtcont_key: srtcont_key,
                                      deelsrtcont_key: deelsrtcont_key
                                     });

user.anything_todo_or_abort(this_ins.canInspUnexecute);

lcl.set_dialect(ctrdisc_key, "CTR_DISCIPLINE_KEY");
mld.dialectIsSet = true;

var result = {key: "", success: true, unexecute: true };

sql = "DELETE FROM mld_melding_object"
    + " WHERE mld_melding_key = " + mld_key
    + "   AND ins_deel_key = " + ins_key
    + "   AND ins_deelsrtcontrole_key = " + deelsrtcont_key
oRs = Oracle.Execute(sql);

// Status terugzetten van naar "Geaccordeerd(2)".
ins.setinspectstatus(deelsrtcont_key, 2); // Geaccordeerd(2).

result.toaster = L("lcl_mjb_unexecuting_completed");
Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
