<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$
    File:             mld_statusupdate.asp
    Description:      A deeplink call to approve/reject HR-calls.
    Parameters:
        mld_key       Id of the mld_melding
        mld_info      Information that will be logged in the call (as part of Opmerking)
        mld_status    Key of mld_statusses
    Context:          Client specific file to handle actions on (HR-)calls as initiated
                      from a report only accessible for UNCO/Staf and PO employees.
    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_key = getQParamInt("mld_key");
  var mld_info = getQParam("mld_info","");
  var mld_status = getQParamInt("mld_status", -1);

  if (mld_info != "") {
   // info toevoegen; ALLEEN door geautoriseerde Unco/Staf en PO medewerkers!
   if (func_enabled["WEB_USER04"] || func_enabled["WEB_USER05"]) {
    sql = " UPDATE mld_melding "
        + "    SET mld_melding_opmerking = DECODE (mld_melding_opmerking, NULL, " + safe.quoted_sql(mld_info) + ", SUBSTR (mld_melding_opmerking || CHR (13) || CHR (10) || " + safe.quoted_sql(mld_info) + ", 1, 4000)) "
        + "  WHERE mld_melding_key = " + mld_key
        + "    AND EXISTS (SELECT 1 FROM mld_melding m, mld_stdmelding sm, ins_tab_discipline td"
        + "                 WHERE m.mld_melding_key = " + mld_key
        + "                   AND m.mld_stdmelding_key = sm.mld_stdmelding_key"
        + "                   AND sm.mld_ins_discipline_key = td.ins_discipline_key"
        + "                   AND td.ins_discipline_key IN (1301, 1381))";
    Oracle.Execute(sql);
   }
   else {
     message = L("lcl_no_auth");
   }
  }

  if (mld_status == 1) {
   // melding afwijzen; ALLEEN door geautoriseerde Unco/Staf en PO medewerkers!
   if (func_enabled["WEB_USER04"] || func_enabled["WEB_USER05"]) {
    if (mld_info == "") {
      message = 'Bij afwijzen is het invoeren van een reden verplicht.';
    }
    else {
      message = 'Verzoek afgewezen.';

      sql = "BEGIN mld.setmeldingstatus("+ mld_key +", 1, " + user_key + "); END;";
      Oracle.Execute(sql);
    }
   }
   else {
     message = L("lcl_no_auth");
   }
  }
  else if (mld_status == 4) {
   // melding accepteren; ALLEEN door geautoriseerde Unco/Staf en PO medewerkers!
   if (func_enabled["WEB_USER04"] || func_enabled["WEB_USER05"]) {
    message = 'Verzoek geaccepteerd.';

    sql = "BEGIN mld.setmeldingstatus("+ mld_key +", 4, " + user_key + "); END;";
    Oracle.Execute(sql);
   }
   else {
     message = L("lcl_no_auth");
   }
  }

  result = { success : true, message : message }

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