<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$
    File:               mld_statusupdate.asp
    Description:        A deeplink call from the reports section of Facilitor to finish cleaning activitis.
    Parameters:
        meldingnr       Id of the mld_melding
        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 = "Kamer afronden is niet gelukt";
  v_res = false;
  var mld_melding_key = -1;
  var meldingnr = getQParamInt("meldingnr", -1);
  var mld_status = 0;
  var mld_omschr = "";
__Log('voor select');
  sql = " SELECT mld_melding_key, "
      + "        mld_melding_status, "
      + "        ins_srtdiscipline_prefix || mld_melding_key || ' (' || ins_discipline_omschrijving || '/' || mld_stdmelding_omschrijving || ')'"
      + "   FROM mld_melding m, mld_stdmelding std, ins_tab_discipline d, ins_srtdiscipline sd "
      + "  WHERE m.mld_stdmelding_key = std.mld_stdmelding_key "
      + "    AND std.mld_ins_discipline_key = d.ins_discipline_key "
      + "    AND d.ins_srtdiscipline_key = sd.ins_srtdiscipline_key "
      + "    AND m.mld_melding_key = " + meldingnr;

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

 
  // melding accepteren; ALLEEN door geautoriseerde medewerkers!
  __Log('voor func_enabled');
  if (func_enabled["WEB_USER02"]) {

    if (mld_status == 4 || mld_status == 7) {
      // melding afmelden
      sql = "BEGIN mld.setmeldingstatus("+ mld_melding_key + ", 5, "+ user_key + "); END;";
      Oracle.Execute(sql);
    }
    if (mld_status == 4 || mld_status == 5 || mld_status == 7) {
      // melding op afgerond zetten
      sql = "UPDATE mld_melding SET mld_melding_afgerond = 1 WHERE mld_melding_key = " + mld_melding_key;
      Oracle.Execute(sql);
      // tracking toevoegen
      sql = "BEGIN fac.trackaction('MLDAFR', " + mld_melding_key + ", "+ user_key + ", NULL, 'Melding " + mld_omschr + " is afgerond'); END;";
      Oracle.Execute(sql);
      // en de volgende workflowstep aanroepen
      sql = "BEGIN mld.mld_nextworkflowstep ("+ mld_melding_key + ", 1); END;";
      Oracle.Execute(sql);
      
      message = "Kamer afgerond";
      v_res = true;
    }
  }
  else {
    message = "Onvoldoende rechten";
    v_res = false;
  }
  result = { success : v_res, message : message }

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