%args>
$id => undef
%args>
<%init>
my $Ticket;
my @Actions;
unless ($id) {
Abort('No ticket specified');
}
if ($ARGS{'id'} eq 'new') {
# {{{ Create a new ticket
my $Queue = new RT::Queue( $session{'CurrentUser'} );
$Queue->Load($ARGS{'Queue'});
unless ( $Queue->id ) {
Abort('Queue not found');
}
unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
Abort('You have no permission to create tickets in that queue.');
}
($Ticket, @Actions) = CreateTicket(
Attachments => delete $session{'Attachments'},
%ARGS,
);
unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
Abort("No permission to view newly created ticket #".$Ticket->id.".");
}
# }}}
} else {
$Ticket ||= LoadTicket($ARGS{'id'});
$m->callback( CallbackName => 'BeforeProcessArguments',
TicketObj => $Ticket,
ActionsRef => \@Actions, ARGSRef => \%ARGS );
if ( defined $ARGS{'Action'} ) {
if ($ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/) {
my $action = $1;
my ($res, $msg) = $Ticket->$action();
push(@Actions, $msg);
}
}
$m->callback(CallbackName => 'ProcessArguments',
Ticket => $Ticket,
ARGSRef => \%ARGS,
Actions => \@Actions);
$ARGS{UpdateAttachments} = $session{'Attachments'};
push @Actions,
ProcessUpdateMessage(
ARGSRef => \%ARGS,
Actions => \@Actions,
TicketObj => $Ticket,
);
delete $session{'Attachments'};
#Process status updates
push @Actions, ProcessTicketWatchers(ARGSRef => \%ARGS, TicketObj => $Ticket );
push @Actions, ProcessTicketBasics( ARGSRef => \%ARGS, TicketObj => $Ticket );
push @Actions, ProcessTicketLinks( ARGSRef => \%ARGS, TicketObj => $Ticket );
push @Actions, ProcessTicketDates( ARGSRef => \%ARGS, TicketObj => $Ticket );
push @Actions, ProcessObjectCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $Ticket );
# XXX: we shouldn't block actions here if user has no right to see the ticket,
# but we should allow him to see actions he has done
unless ($Ticket->CurrentUserHasRight('ShowTicket')) {
Abort("No permission to view ticket");
}
if ( $ARGS{'MarkAsSeen'} ) {
$Ticket->SetAttribute(
Name => 'User-'. $Ticket->CurrentUser->id .'-SeenUpTo',
Content => $Ticket->LastUpdated,
);
push @Actions, loc('Marked all messages as seen');
}
}
$m->callback(
CallbackName => 'BeforeDisplay',
TicketObj => \$Ticket,
Actions => \@Actions,
ARGSRef => \%ARGS,
);
# This code does automatic redirection if any updates happen.
if (@Actions) {
# We've done something, so we need to clear the decks to avoid
# resubmission on refresh.
# But we need to store Actions somewhere too, so we don't lose them.
my $key = Digest::MD5::md5_hex( rand(1024) );
push @{ $session{"Actions"}->{$key} ||= [] }, @Actions;
$session{'i'}++;
my $url = RT->Config->Get('WebURL') . "m/ticket/show?id=" . $Ticket->id . "&results=" . $key;
$url .= '#' . $ARGS{Anchor} if $ARGS{Anchor};
RT::Interface::Web::Redirect($url);
}
# If we haven't been passed in an Attachments object (through the precaching mechanism)
# then we need to find one
my $Attachments = $m->comp('/Ticket/Elements/FindAttachments', Ticket => $Ticket);
my %documents;
while ( my $attach = $Attachments->Next() ) {
next unless ($attach->Filename());
unshift( @{ $documents{ $attach->Filename } }, $attach );
}
my $Customers = $Ticket->Customers;
my @customers;
while ( my $customer = $Customers->Next() ) {
push @customers, $customer;
}
my $CustomFields = $Ticket->CustomFields;
$m->callback(
CallbackName => 'MassageCustomFields',
Object => $Ticket,
CustomFields => $CustomFields,
);
my $print_value = sub {
my ($cf, $value) = @_;
my $linked = $value->LinkValueTo;
if ( defined $linked && length $linked ) {
my $linked = $m->interp->apply_escapes( $linked, 'h' );
$m->out('');
}
my $comp = "ShowCustomField". $cf->Type;
$m->callback(
CallbackName => 'ShowComponentName',
Name => \$comp,
CustomField => $cf,
Object => $Ticket,
);
if ( $m->comp_exists( $comp ) ) {
$m->comp( $comp, Object => $value );
} else {
$m->out( $m->interp->apply_escapes( $value->Content, 'h' ) );
}
$m->out('') if defined $linked && length $linked;
# This section automatically populates a div with the "IncludeContentForValue" for this custom
# field if it's been defined
if ( $cf->IncludeContentForValue ) {
my $vid = $value->id;
$m->out( '
<& /m/_elements/ticket_menu, ticket => $Ticket &>
<&| /Widgets/TitleBox, title => loc('The Basics'),
class => 'ticket-info-basics',
&>
<&|/l&>Id&>:
<%$Ticket->Id %>
<&|/l&>Status&>:
<% loc($Ticket->Status) %>
% if ($Ticket->TimeEstimated) {
<&|/l&>Estimated&>:
<& /Ticket/Elements/ShowTime, minutes => $Ticket->TimeEstimated &>
% }
% if ($Ticket->TimeWorked) {
<&|/l&>Worked&>:
<& /Ticket/Elements/ShowTime, minutes => $Ticket->TimeWorked &>
% }
% if ($Ticket->TimeLeft) {
<&|/l&>Left&>:
<& /Ticket/Elements/ShowTime, minutes => $Ticket->TimeLeft &>
% }
<&|/l&>Priority&>:
<& /Ticket/Elements/ShowPriority, Ticket => $Ticket &>
<&|/l&>Queue&>:
<& /Ticket/Elements/ShowQueue, QueueObj => $Ticket->QueueObj &>
&>
% if ($Ticket->CustomFields->First) {
<&| /Widgets/TitleBox, title => loc('Custom Fields'),
class => 'ticket-info-cfs',
&>
% while ( my $CustomField = $CustomFields->Next ) {
% my $Values = $Ticket->CustomFieldValues( $CustomField->Id );
% my $count = $Values->Count;
<% $CustomField->Name %>:
% unless ( $count ) {
<&|/l&>(no value)&>
% } elsif ( $count == 1 ) {
% $print_value->( $CustomField, $Values->First );
% } else {
% while ( my $Value = $Values->Next ) {
-
% $print_value->( $CustomField, $Value );
% }
% }
% }
&>
% }
<&| /Widgets/TitleBox, title => loc('People'), class => 'ticket-info-people' &>
<&|/l&>Owner&>:
<& /Elements/ShowUser, User => $Ticket->OwnerObj, Ticket => $Ticket &>
<&|/l&>Requestors&>:
<& /Ticket/Elements/ShowGroupMembers, Group => $Ticket->Requestors, Ticket => $Ticket &>
<&|/l&>Cc&>:
<& /Ticket/Elements/ShowGroupMembers, Group => $Ticket->Cc, Ticket => $Ticket &>
<&|/l&>AdminCc&>:
<& /Ticket/Elements/ShowGroupMembers, Group => $Ticket->AdminCc, Ticket => $Ticket &>
&>
% if (keys %documents) {
<&| /Widgets/TitleBox, title => loc('Attachments'),
title_class=> 'inverse',
class => 'ticket-info-attachments',
color => "#336699" &>
% foreach my $key (keys %documents) {
<%$key%>
% foreach my $rev (@{$documents{$key}}) {
<%PERL>
my $size = $rev->ContentLength;
if ($size) {
my $kb = int($size/102.4) / 10;
my $units = RT->Config->Get('AttachmentUnits');
if (!defined($units)) {
if ($size > 1024) {
$size = $kb . "k";
}
else {
$size = $size . "b";
}
}
elsif ($units eq 'k') {
$size = $kb . "k";
}
else {
$size = $size . "b";
}
%PERL>
-
<&|/l, $rev->CreatedAsString, $size, $rev->CreatorObj->Name &>[_1] ([_2]) by [_3]&>
% }
% }
% }
&>
% }
% # too painful to deal with reminders
% if ( 0 && RT->Config->Get('EnableReminders') ) {
<&|/Widgets/TitleBox, title => loc("Reminders"),
class => 'ticket-info-reminders',
&>
&>
% }
% if ( @customers ) {
<&| /Widgets/TitleBox, title => loc("Customers"),
class => 'ticket-info-customers',
&>
% foreach my $customer ( @customers ) {
% my $resolver = $customer->TargetURI->Resolver or next;
% } #foreach
&>
% } # if @customers
<&| /Widgets/TitleBox, title => loc("Dates"),
class => 'ticket-info-dates',
&>
<&|/l&>Created&>:
<% $Ticket->CreatedObj->AsString %>
<&|/l&>Starts&>:
<% $Ticket->StartsObj->AsString %>
<&|/l&>Started&>:
<% $Ticket->StartedObj->AsString %>
<&|/l&>Last Contact&>:
<% $Ticket->ToldObj->AsString %>
<&|/l&>Due&>:
% my $due = $Ticket->DueObj;
% if ( $due && $due->Unix > 0 && $due->Diff < 0 ) {
<% $due->AsString %>
% } else {
<% $due->AsString %>
% }
<&|/l&>Closed&>:
<% $Ticket->ResolvedObj->AsString %>
<&|/l&>Updated&>:
% my $UpdatedString = $Ticket->LastUpdated ? loc("[_1] by [_2]", $Ticket->LastUpdatedAsString, $Ticket->LastUpdatedByObj->Name) : loc("Never");
<% $UpdatedString | h %>
&>
<&| /Widgets/TitleBox, title => loc('Links'), class => 'ticket-info-links' &>
<% loc('Depends on')%>:
<%PERL>
my ( @active, @inactive, @not_tickets );
for my $link ( @{ $Ticket->DependsOn->ItemsArrayRef } ) {
my $target = $link->TargetObj;
if ( $target && $target->isa('RT::Ticket') ) {
if ( $target->QueueObj->IsInactiveStatus( $target->Status ) ) {
push( @inactive, $link->TargetURI );
}
else {
push( @active, $link->TargetURI );
}
}
else {
push( @not_tickets, $link->TargetURI );
}
}
%PERL>
% for my $Link (@not_tickets, @active, @inactive) {
- <& /Elements/ShowLink, URI => $Link &>
% }
<% loc('Depended on by')%>:
% while (my $Link = $Ticket->DependedOnBy->Next) {
- <& /Elements/ShowLink, URI => $Link->BaseURI &>
% }
<% loc('Parents') %>:
<& /Ticket/Elements/ShowParents, Ticket => $Ticket &>
<% loc('Children')%>:
<& /Ticket/Elements/ShowMembers, Ticket => $Ticket &>
<% loc('Refers to')%>:
% while (my $Link = $Ticket->RefersTo->Next) {
- <& /Elements/ShowLink, URI => $Link->TargetURI &>
% }
<% loc('Referred to by')%>:
% while (my $Link = $Ticket->ReferredToBy->Next) {
% next if (UNIVERSAL::isa($Link->BaseObj, 'RT::Ticket') && $Link->BaseObj->Type eq 'reminder');
- <& /Elements/ShowLink, URI => $Link->BaseURI &>
% }
&>
&>