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

    Vereist WEB_FACFAC
    Parameters:
    - module
    - flag

    Poweruser tool to reset the current use of a specific "flag".
    It will clear all the use of this flag and reset the description for next use
*/
var JSON_Result = true;
%>
<!--#include file="../Shared/common.inc"-->
<%
    protectRequest.validateToken();
    var authparams = user.checkAutorisation("WEB_FACFAC");

    var pmodule = getFParamSafe("module");
    var pflagnr = getFParamInt("flag");
    var result = {success: false};

    if (pflagnr >= 0 && pflagnr <= 9)
    {
        var flagcode = pmodule.toLowerCase() + "_flag" + pflagnr;

        var sql = "";
        switch (pmodule.toUpperCase())
        {
            case "BESTELOPDR":  sql = "UPDATE bes_bestelopdr SET bes_bestelopdr_flag = NULL WHERE bes_bestelopdr_flag = " + pflagnr;  break;
            case "BEZ":         sql = "UPDATE bez_bezoekers  SET bez_bezoekers_flag  = NULL WHERE bez_bezoekers_flag  = " + pflagnr;  break;
            case "FIN":         sql = "UPDATE fin_factuur    SET fin_factuur_flag    = NULL WHERE fin_factuur_flag    = " + pflagnr;  break;
            case "MLD":         sql = "UPDATE mld_melding    SET mld_melding_flag    = NULL WHERE mld_melding_flag    = " + pflagnr;  break;
            case "OPDR":        sql = "UPDATE mld_opdr       SET mld_opdr_flag       = NULL WHERE mld_opdr_flag       = " + pflagnr;  break;
            case "RES":         sql = "UPDATE res_rsv_ruimte SET res_rsv_ruimte_flag = NULL WHERE res_rsv_ruimte_flag = " + pflagnr;  break;
        }
        if (sql != "")
        {
            Oracle.Execute(sql);

            var resetlabel = "Reset by "+ user.naam() + " at " + toDateTimeString(new Date());  // max 4000
            var sql = "UPDATE fac_locale_xsl"
                    + "   SET fac_locale_xsl_cust = " + safe.quoted_sql(resetlabel)
                    + " WHERE fac_locale_xsl_label = " + safe.quoted_sql("lcl_"+flagcode);
            Oracle.Execute(sql);
            result.success = true;
        }
    }

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