<?php
/**
 * $Horde: whups/ticket/index.php,v 1.34.2.1 2009-01-06 15:28:39 jan Exp $
 *
 * Copyright 2001-2002 Robert E. Coyle <robertecoyle@hotmail.com>
 * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (BSD). If you
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @author Chuck Hagenbuch <chuck@horde.org>
 */

require_once dirname(__FILE__) . '/../lib/base.php';
require_once WHUPS_BASE . '/lib/Ticket.php';
require_once WHUPS_BASE . '/lib/Renderer/Comment.php';
require_once 'Horde/Variables.php';
require_once 'Horde/Text/Filter.php';

$ticket = Whups::getCurrentTicket();
$vars = Variables::getDefaultVariables();
$ticket->setDetails($vars);

$title = '[#' . $ticket->getId() . '] ' . $ticket->get('summary');
require WHUPS_TEMPLATES . '/common-header.inc';
require WHUPS_TEMPLATES . '/menu.inc';
require WHUPS_TEMPLATES . '/prevnext.inc';

$tabs = Whups::getTicketTabs($vars, $ticket->getId());
echo $tabs->render('history');

$form = new TicketDetailsForm($vars, $ticket);

$renderer = $form->getRenderer();
$renderer->_name = $form->getName();
$renderer->beginInactive($title);
$renderer->renderFormInactive($form, $vars);
$renderer->end();

echo '<br class="spacer" />';

$comment = new Horde_Form_Renderer_Comment();
$comment->begin(_("History"));
$history = Whups::permissionsFilter($whups_driver->getHistory($ticket->getId()),
                                    'comment', PERMS_READ);
$chtml = array();
foreach ($history as $transaction => $comment_values) {
    $chtml[] = $comment->render($transaction, new Variables($comment_values));
}
if ($prefs->getValue('comment_sort_dir')) {
    $chtml = array_reverse($chtml);
}
echo implode('', $chtml);
$comment->end();

require $registry->get('templates', 'horde') . '/common-footer.inc';
