<% /*
    $Revision$
    $Id$

    File:               hookfunctions.inc
    Description:        This file contains the default Facilitor hookfunctions.
    Parameters:
    Context:
    Note:               Maak een XXXX/custfunctions.wsc en die wordt
                        automagisch gevonden.
*/ %>

<%
// If needed you can or may overrule some or all of these functions
// In your own custfunctions.wsc file.
// Invalid changes to this file may lead to unexpected results.

function HookResult(value, errmsg)
{
  this.value = value;
  this.errmsg = errmsg;
}

custfunc = {
        gethook: function ()
        {
            if (!S("custfunctionspath"))
                return false;
            var fso = Server.CreateObject("Scripting.FileSystemObject");
            var hookfile = Server.MapPath(rooturl + "/" + S("custfunctionspath"));
            __Log("Looking for hookfile: " + hookfile);
            if (!fso.FileExists(hookfile))
                return false;
            __Log("Found!");
            var hook = GetObject("script:"+hookfile);
            // Deze mogen de hookfiles gebruiken
            hook.Oracle = Oracle;
            hook.__Log = __Log;
            hook.__DoLog = __DoLog;
            hook.safe = safe;
            return hook;
        }
    };

// Returnvalues for all functions:
// return true = success
// return false = failed

// Optional resultvalues in presult:
// presult.value    containing a resultvalue, valid only if success
// presult.errmsg   string containing errormessage, only if fail


// ======================================================================================
// BEZ CUSTFUNCTIONS
//

// Called after bezoekers has been updated
// Used for UWV-check ARO
// parameters:   bezkeyArr just saved (Array van bezoekers)
// result: -
custfunc.bez_postsave  =
    function (bezkeyArr, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bez_postsave' in hook)
                result = hook.bez_postsave(bezkeyArr, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called when user has clicked the Done checkbox in the backoffice visitors.
// parameters:   pbezoek_key  key van de bez_bezoeker
// result: -
custfunc.bez_checkdone =
    function (pbezoek_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bez_checkdone' in hook)
                result = hook.bez_checkdone(pbezoek_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called when user has clicked the Out checkbox in the backoffice visitors.
// parameters:   pbezoek_key  key van de bez_bezoeker
// result: -
custfunc.bez_checkout =
    function (pbezoek_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bez_checkout' in hook)
                result = hook.bez_checkout(pbezoek_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// ======================================================================================
// BES CUSTFUNCTIONS
//
// Called before the RFO is inserted or changed. Used to check custommer
// specific checks on flex fields.
// parameters:   disc key of the catalog
// result: -
custfunc.bes_checkrfo =
    function (disc, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bes_checkrfo' in hook)
                result = hook.bes_checkrfo(disc, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called when receiving de hookurl information from a punchout order.
// Used to check custommer specific hook parameters.
// parameters:   srtdeel key of the article
// result: -
custfunc.bes_punch_receive =
    function (RequestForm, bes_srtdeel_key, item, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bes_punch_receive' in hook)
            {
                result = hook.bes_punch_receive(RequestForm, bes_srtdeel_key, item, presult);
                if (result && result.flex_defaults)
                    result.orderurl += "&flex_defaults=" + Server.URLencode(result.flex_defaults);
            }
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called after bestelling has been updated
// parameters:   bes_bestelling_key just saved
// Note: bestelregels zijn ook al opgeslagen
// result: -
custfunc.bes_postsave  =
    function (bes_bestelling_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bes_postsave' in hook)
                result = hook.bes_postsave(bes_bestelling_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called upon bes_bestelling save to check whether there has been
// a remote approval function defined for this discipline
// parameters:   discipline_key
// Note:   ALTERNATIEF ZOU EEN BES_DISC_PARAMS_REMOTE KUNNEN ZIJN..??
// Result: -
custfunc.bes_hasremoteapproval  =
    function (discipline_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bes_hasremoteapproval' in hook)
                result = hook.bes_hasremoteapproval(discipline_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        else
            presult.value = false;  //standaard interne approval
        return result;
    };

// Called upon bes_bestelling save to initiate
// a remote approval for this bestelling
// parameters:   bestelling_key
// Note:
// Result: -
custfunc.bes_getremoteapproval  =
    function (bestelling_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('bes_getremoteapproval' in hook)
                result = hook.bes_getremoteapproval(bestelling_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };



// ======================================================================================
// RES CUSTFUNCTIONS
//

// Called after reservering has been updated
// Used for UWV-check ARO
// parameters:   rsv_ruimte_key just saved
// result: -
custfunc.res_postsave  =
    function (rsv_ruimte_key, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('res_postsave' in hook)
                result = hook.res_postsave(rsv_ruimte_key, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// ======================================================================================
// MLD CUSTFUNCTIONS
//

// Called after weekbrief-cell (uren) has been updated
// Used for CARE: doorloop de week van deze persoon en bepaal de dagtotaalkilometers
// om op te slaan in mld_opdruren_dagkosten
//custfunc.mld_urenpost2save = function (p_prskey, p_datumfrom, presult) {return true};
custfunc.mld_urenpostsave =
    function (p_prs_key, p_datum, p_opdr_key, p_impropdr_key, p_actie, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('mld_urenpostsave' in hook)
                result = hook.mld_urenpostsave(p_prs_key, p_datum, p_opdr_key, p_impropdr_key, p_actie, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called after weekbrief-cell (kosten) has been updated
custfunc.mld_urenkostenpostsave =
    function (p_mld_opdruren_kosten_key, p_mld_opdruren_key, p_kosten_key, p_kosten, p_actie, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('mld_urenkostenpostsave' in hook)
                result = hook.mld_urenkostenpostsave(p_mld_opdruren_kosten_key, p_mld_opdruren_key, p_kosten_key, p_kosten, p_actie, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

custfunc.mld_postsave  =
    function (mld_melding, presult)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('mld_postsave' in hook)
                result = hook.mld_postsave(mld_melding, presult);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };

// Called for API_PHONEBOOK
custfunc.API_PHONEBOOK =
    function (prs_key, data)
    {
        var result = true;
        var hook = custfunc.gethook();
        if (hook)
        {
            if ('API_PHONEBOOK' in hook)
                result = hook.API_PHONEBOOK(prs_key, data);
            hook = null; // zorg dat de GC het object kan opruimen.
        }
        return result;
    };
%>