<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$
    File:               mld_statusupdate.asp
    Description:        A deeplink call from the reports section of Facilitor to accept or reject lease car requests.
    Parameters:
        meldingnr       Id of the mld_melding
        mld_info        Information that will be logged in the complain (as part of Opmerking)
        mld_status      Key of mld_statusses
    Context:            Client specific file to handle a deeplink call.
    Note:
*/ %>
<%
DOCTYPE_Disable = 1;
%>
<!--#include file="../../appl/Shared/common.inc"-->
<!-- #include file="../../appl/Shared/json2.js" -->
<!-- #include file="../../appl/Shared/funcodes.inc" -->
<%
  message = "";
  var mld_opdr_key = -1;
  var mld_melding_key = -1;
  var meldingnr = getQParamInt("meldingnr", -1);
  var mld_info = getQParam("mld_info","");
  var mld_status = getQParamInt("mld_status", -1);
__Log('voor select');
  sql = " SELECT mld_melding_key FROM mld_melding WHERE mld_melding_key = " + meldingnr;

  oRs = Oracle.Execute(sql);
  if (!oRs.eof) {
    // meldingnummer is gevonden
    mld_melding_key = oRs(0).value;
  }

  if (mld_info != "") {
    sql = " UPDATE mld_melding "
        + "    SET mld_melding_opmerking = DECODE (mld_melding_opmerking, NULL, " + safe.quoted_sql(mld_info) + ", " + safe.quoted_sql(mld_info) + " || '\n' || SUBSTR (mld_melding_opmerking , 1, (4000 - " + mld_info.length + "))) "
        + "  WHERE mld_melding_key = " + mld_melding_key
        + "    AND mld_melding_status IN (2, 3, 4, 7) ";
    Oracle.Execute(sql);
  }
__Log('voor mld_status==1');
 if (mld_status == 1) {
    // melding afwijzen; ALLEEN door geautoriseerde medewerkers!
    if (func_enabled["WEB_USER02"]) {
      if (mld_info == "") {
        message = 'Bij afwijzen is het invoeren van een reden verplicht.';
      }
      else {
        message = 'Lease auto aanvraag afgewezen.';

        sql = "BEGIN mld.setmeldingstatus("+ mld_melding_key +", 1, " + user_key + "); END;";
        Oracle.Execute(sql);
        // en de volgende workflowstep aanroepen
        sql = "BEGIN mld.mld_nextworkflowstep ("+ mld_melding_key + ", 0); END;";
        Oracle.Execute(sql);
      }
    }
    else {
      message = L("lcl_no_auth");
    }

    result = { success : true, message : message }

    Response.Write(JSON.stringify(result));
  }
  else if (mld_status == 4) {
    // melding accepteren; ALLEEN door geautoriseerde medewerkers!
    __Log('voor func_enabled');
    if (func_enabled["WEB_USER02"]) {
      message = 'lease auto aanvraag geaccepteerd.';

      // melding accepteren
      sql = "BEGIN mld.setmeldingstatus("+ mld_melding_key +", 4, " + user_key + "); END;";
      Oracle.Execute(sql);
      // melding afmelden
      sql = "BEGIN mld.setmeldingstatus("+ mld_melding_key + ", 5, "+ user_key + "); END;";
      Oracle.Execute(sql);
      // en de volgende workflowstep aanroepen
      sql = "BEGIN mld.mld_nextworkflowstep ("+ mld_melding_key + ", 1); END;";
      Oracle.Execute(sql);
    }

    result = { success : true, message : message }

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