#!/usr/local/bin/php
<?php
/**
 * $Horde: kronolith/scripts/eventd,v 1.2 2003/01/28 23:47:08 jan Exp $
 *
 * Copyright 2003 Charles J. Hagenbuch <chuck@horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

// Find the base file path of Horde.
@define('HORDE_BASE', dirname(__FILE__) . '/../..');

// Find the base file path of Kronolith.
@define('KRONOLITH_BASE', dirname(__FILE__) . '/..');

// Do CLI checks and environment setup first.
require_once HORDE_BASE . '/lib/CLI.php';

// Make sure no one runs this from the web.
if (!Horde_CLI::runningFromCLI()) {
    exit("Must be run from the command line\n");
}

// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
Horde_CLI::init();

// Now load the Registry and setup conf, etc.
require_once HORDE_BASE . '/lib/Registry.php';
$registry = &Registry::singleton();
$registry->pushApp('kronolith');

// Include needed libraries
require_once HORDE_BASE . '/lib/Scheduler.php';
require_once KRONOLITH_BASE . '/lib/Kronolith.php';
require_once 'Date/Calc.php';

// Create a share instance.
require_once HORDE_BASE . '/lib/Share.php';
$shares = &Horde_Share::singleton($registry->getApp());

// Create a calendar backend object.
$calendar = &Kronolith_Driver::factory($conf['calendar']['driver'],
                                       $conf['calendar']['params']);

// Get an instance of the Kronolith scheduler.
$daemon = &Horde_Scheduler::singleton(array('kronolith', 'kronolith'), array('shares' => $shares,
                                                                             'driver' => $calendar));

// Start the daemon going.
$daemon->run();
