<?php
if (!function_exists('_horde_hook_postauthenticate')) {
    function _horde_hook_postauthenticate($userID, $credential, $realm)
    {
        $client = new SoapClient('http://www.example.com/webservice.wsdl');
        try {
            $status = $client->getTOSAccepted($userID);
        } catch (SoapFault $e) {
            Horde::fatal($e, __FILE__, __LINE__, PEAR_LOG_ERR);
        }
        $_SESSION['client']['tos'] = $_SESSION['client']['passwd'] = !$status;
    }
}

if (!function_exists('_horde_hook_post_pushapp')) {
    function _horde_hook_post_pushapp($app)
    {
        if (!Auth::getAuth() || $app == 'passwd') {
            return;
        }
        foreach (debug_backtrace() as $step) {
            if ($step['function'] == 'callByPackage' ||
                $step['function'] == 'listAlarms') {
                return;
            }
        }
        if (!empty($_SESSION['client']['tos'])) {
            $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/firstlogin.php', true);
            header('Location: ' . $url);
            exit;
        }
        if (!empty($_SESSION['client']['passwd'])) {
            $url = Horde::url(Util::addParameter($GLOBALS['registry']->get('webroot', 'passwd') . '/', 'return_to', Horde::url($GLOBALS['registry']->get('webroot', 'horde'), true)), true);
            header('Location: ' . $url);
            exit;
        }
    }
}