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

    File:               BijlagenForm_delete.asp
    Description:        SUBMIT-form

    Parameters:
    Context:
    Note:
*/
var JSON_Result = true;

var pModule = getQParamSafe("module");
var pNiveau = getQParamSafe("niveau", "");
var pKey = getQParamInt("key", -1); // de refkey
if (pModule == "MLD" && pNiveau == "M")
    var LOCKED_USER_OK = { "xmlnode": "melding", "key": pKey };
else if (pModule == "MLD" && pNiveau == "O")
    var LOCKED_USER_OK = { "xmlnode": "opdracht", "key": pKey };
else if (pModule === "ORDN") {
    var LOCKED_USER_OK = { "xmlnode": "opdracht", "key": getQParamInt("opdr_key", null) };
} else if (pModule === "MLDN") {
    var LOCKED_USER_OK = { "xmlnode": "melding", "key": getQParamInt("mld_key", null) };
}
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="./flexfiles.inc" -->
<%
protectQS.verify({ allowparams: ["newfilename"] }); // tamper check
protectRequest.validateToken();

var pKenmerk_key = getQParamInt("kenmerk_key", -1);
var pAlgLevel = getQParam("kenmerk_module", "");
var pDoDelete = getQParam("DoDelete", ""); // te verwijderen bestand

var params = flexProps(pModule, pKey, String(pKenmerk_key), pNiveau, {alglevel: pAlgLevel});

if (pDoDelete === "" && "linkImmediate" in params) {
    if (pKey > 0) {
        pDoDelete = getLinkedFilename(pKey, params);
    } else {
        pDoDelete = getQParam("newfilename", "");
    }
    if (pDoDelete && pModule.indexOf("FGII") === 0) {
        pDoDelete = pDoDelete.replace(/(\.dwf)?$/, ".dwf");
    }
}

result = { success: true, toaster: L("lcl_appendix_removed").format(safe.html(pDoDelete))};

if (pDoDelete != "")
{
  //var kmw = kenmerkwaardetabel_info(pModule, pNiveau);
  //params.module = kmw.module;    // MLD | OPD | ....
  params.module = pModule;  // module wijzigd niet als gevolg van een ander niveau.
  params.niveau = (pNiveau == "" ? null : pNiveau);
  params.refkey = pKey;
  params.kenmerkkey = pKenmerk_key
  params.file = safe.filename(pDoDelete);

  DeleteFile(params.AttachPath + "/" + safe.filename(pDoDelete), params);

  // Verwijderen bijlage/bestand tracken.
  trackBijlagen(pModule, pKey, params, null, "delete");
  result.removed = true;
}

Response.Write(JSON.stringify(result));
%><% ASPPAGE_END(); %>
