<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$
    File:               mld_statusupdate.asp
    Description:        A deeplink call from usrrap to update the status of a complain.
    Parameters:
        melding_key     Id of the mld_melding
    Context:            Client specific file to handle a actions from the report.
    Note:
*/

DOCTYPE_Disable = 1;

%>
<!--#include file="../../appl/Shared/common.inc"-->
<!-- #include file="../../appl/Shared/json2.js" -->
<%

  var melding_key = getQParamInt("melding_key", -1);
  var mld_info = getQParam("mld_info", "leeg");
  var mld_status = getQParamInt("mld_status", -1);

  if (mld_status == 5 || mld_status == -1)
  {
    if (melding_key > 0) {
      sql = "BEGIN mld.setmeldingstatus("+ melding_key +", 4 , " + user_key + "); END;";
      Oracle.Execute(sql);

      sql = " UPDATE mld_melding "
          + "    SET mld_melding_opmerking = " + safe.quoted_sql(mld_info=="leeg"?"":mld_info)
          + "  WHERE mld_melding_key = " + melding_key;
      Oracle.Execute(sql);

      sql = "BEGIN mld.setmeldingstatus("+ melding_key +", 5 , " + user_key + "); END;";
      Oracle.Execute(sql);
    }
  }
  if (mld_status == 1) {
    sql = " UPDATE mld_melding "
        + "    SET mld_melding_opmerking = DECODE (mld_melding_opmerking, NULL, "
        +                      safe.quoted_sql(mld_info)
        + "                   , SUBSTR (mld_melding_opmerking || '\n' || " + safe.quoted_sql(mld_info) + ", 1, 4000)) "
        + "  WHERE mld_melding_key = " + melding_key;
    Oracle.Execute(sql);

    sql = "BEGIN mld.setmeldingstatus("+ melding_key +", 1 , " + user_key + "); END;";
    Oracle.Execute(sql);
  }

    result = { success : true, message : "" }

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