<?php
/* $Horde: forwards/lib/api.php,v 1.8 2003/09/01 21:37:14 jan Exp $
 *
 * Forwards external API interface.
 *
 * This file defines Forwards's external API interface. Other
 * applications can interact with Forward through this API.
 *
 * @author  Eric Rostetter <eric.rostetter@physics.utexas.edu>
 * @author  Diego Rivera <lrivera@racsa.co.cr>
 * @version $Revision: 1.8 $
 * @package Forward
 */

// Find the base file paths for Forwards
@define('FORWARDS_BASE', dirname(__FILE__) . '/..');

$_services['summary'] = array(
  'args' => array(),
  'type' => 'string'
);

function _forwards_summary()
{
    global $registry, $conf;

    // Include the necessary libraries.
    require_once FORWARDS_BASE . '/lib/base.php';
    require_once FORWARDS_BASE . '/lib/Driver.php';

    // Get the current login credentials
    $splitted = explode('@', Auth::getAuth());
    $user = @$splitted[0];
    $realm = @$splitted[1];
    $pass = Auth::getCredential('password');

    // Create the driver
    $driver = &Forwards_Driver::factory();

    // find out if it is activated or not...
    if (!isset($driver))
    {
        $content = _("Failed to create a forwards driver");
    }
    else
    {
        if (!$driver->isEnabledForwarding($user, $realm, $pass)) {
            $content = _("Forward is not active.");
        } else {
            $content = _("Forward is active.");
            $to = $driver->currentTarget($user, $realm, $pass);
            // FIXME: should we parse the contents returned?
            $content .= ($to
                ? '<blockquote>' . nl2br(htmlentities($to)) . '</blockquote>'
                : _("Unable to retrieve forwarding information")
            );
        }
    }

    // Build and return the html for the summary page
    $html  = '<table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td class="header">';
    $html .= Horde::link(Horde::url($registry->getInitialPage()), $registry->getParam('name'), 'header') . $registry->getParam('name') . '</a>';
    $html .= '</td></tr>';
    $html .= '<tr><td class="text"><table border="0" cellpadding="0" cellspacing="0">';
    $html .= '<tr><td class="text" nowrap="nowrap" valign="top"><b>';
    $html .= $content;
    $html .= '</b></td></tr>';
    $html .= '</table></td></tr></table>';
    return $html;
}

?>
