1 %## Default elements from RT. Header and the ticket elements. Both this and the
2 %## html printed after the <%INIT>
4 Title => loc("#[_1]: [_2]", $TicketObj->Id, $TicketObj->Subject),
5 LinkRel => \%link_rel &>
8 %## The html with %-prefixed perl code.
9 <div class="history"><div id="ticket-history">
10 <div class="titlebox" id="">
11 <div class="titlebox-title">
12 <span class="left">Ticket to export</span>
14 Ny funksjonalitet utvikla av USIT - for meir info:
15 <a href="http://www.usit.uio.no/tj-grupper/rt/sys-dok/export.html">Sjå her</a>
17 Send eventuelle kommentarar og feil/manglar til rt-drift@usit.uio.no.
20 <form action="Export.html" method="post">
21 %print "<input type=\"text\" name=\"email\" size=\"40\" value=\"".$user->EmailAddress."\"/>";
22 %print "<input type=\"hidden\" name=\"id\" value=\"".$TicketObj->Id."\"/>";
24 <input type="submit" value="Send email"/>
26 <div class="ticket-transaction message odd">
27 <pre style="white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;white-space: pre-wrap;word-wrap: break-word;">
42 my (@Actions, $Tickets);
45 unless ($id || $TicketObj) {
46 Abort('No ticket specified');
49 $TicketObj ||= LoadTicket($ARGS{'id'});
51 unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
52 Abort("No permission to view ticket");
55 # used to convert html-formated email -> plain text for the body.
58 my $formater = HTML::FormatText->new(leftmargin => 0, rightmargin => 75);
60 # using buildtin methods to get the attachments - all nice and cronological.
61 my $attachments = $m->comp('Elements/FindAttachments', Ticket => $TicketObj, Tickets => $Tickets);
62 my $attachment_content = $m->comp('Elements/LoadTextAttachments', Ticket => $TicketObj);
64 #Get some information.
65 my $queue = RT::Queue->new($RT::SystemUser);
66 $queue->Load($TicketObj->Queue);
67 my $owner = RT::User->new($RT::SystemUser);
68 $owner->Load($TicketObj->Owner);
69 my $user = RT::User->new($RT::SystemUser);
70 $user->Load($TicketObj->CurrentUser);
71 my $requestor = RT::User->new($RT::SystemUser);
72 my $people = $TicketObj->Requestors->UserMembersObj;
74 while ( my $r = $people->Next ) {
75 push @requestors, $m->scomp('/Elements/ShowUserConcise', User => $r);
77 my $requestors = join ("\n ", @requestors);
80 my $Transactions = $TicketObj->Transactions;
82 my @attachments = @{$attachments->ItemsArrayRef()};
83 my @attachment_content = @{$attachment_content->ItemsArrayRef()};
92 # Find the last time the ticket was resolved.
94 #### NEED FIX HERE ###
96 while ( my $Transaction = $Transactions->Next ) {
97 if ($Transaction->Description =~ /Status changed from \'.*\' to \'resolved\'/) {
98 $resolved = $Transaction->Description." - ".
99 $Transaction->CreatorObj->RealName." on ".
100 $Transaction->CreatedAsString()."\n";
101 $resolved =~ s/Status changed from \'.*\' to \'resolved\' /Resolved: /;
104 # Ignoring comments/statuschange/etc.
105 next if $Transaction->Description !~ /(Correspondence added|Ticket created )/;
107 # Get all the transactions:
108 my $Attach = $Transaction->Attachments->ItemsArrayRef();
109 next if ! defined $Attach->[0];
110 $mail .= $Transaction->BriefDescription." by ".$Transaction->CreatorObj->Name." - ".
111 $Transaction->CreatorObj->RealName."\n";
112 $mail .= "Date: ".$Transaction->CreatedAsString()." =================================================>\n\n";
113 $created = $Transaction->CreatedAsString() unless $created;
115 if ($_->ContentType =~ /text\/plain/ && not $_->Filename) {$mail .= $_->Content."\n\n"}
116 if ($_->ContentType =~ /text\/html/ && not $_->Filename) {
117 $mail .= $formater->format(parse_html("<div>".$_->Content."</div>"))."\n\n"
120 # Finding the mail attachments that will be attached to the final email.
121 if ($_->Filename) {$mail .= "Attatchment: ".$_->Filename."\n\n";$attach=1;}
125 # Putting together the metadata. Some posibilities are commented.
126 # The ticket can have a created after the first transaction if an older ticket
127 # is merged into a newer ticket, so we use the creation-time of the first
130 $mail_head .= "============================================================================\n";
131 # $mail_head .= "Created Date:\t".$TicketObj->CreatedAsString."\n";
132 $mail_head .= "Created Date: $created\n";
133 $mail_head .= "Requestor(s): $requestors\n";
134 # $mail_head .= "Requestor(s): ".$TicketObj->Requestors->MemberEmailAddressesAsString."\n".$requestors;
135 # $mail_head .= "Cc: $TicketObj->Cc\n" if $TicketObj->Cc;
136 # $mail_head .= "X-AdminCc: $TicketObj->AdminCc\n" if $TicketObj->AdminCc;
137 $mail_head .= "X-Queue: ".$queue->Name."\n";
138 $mail_head .= "Owner: ".$owner->Name." - ".$owner->RealName."\n";
139 $mail_head .= "Subject: [rt #".$TicketObj->id."] ".$TicketObj->Subject."\n";
140 $mail_head .= $resolved;
141 $mail_head .= "============================================================================\n\n";
143 # Building an mime-email if we are to send an email.
145 my $mail = MIME::Entity->build(
146 Type => 'text/plain',
148 Data => $mail_head."\n".$mail,
151 $mail->head->set(To=>RT::Interface::Email::EncodeToMIME(String => $email));
152 $mail->head->set(From=>RT::Interface::Email::EncodeToMIME(String => $user->EmailAddress));
153 $mail->head->set(Subject=>RT::Interface::Email::EncodeToMIME(String => "Fwd: [rt #".$TicketObj->id."] ".$TicketObj->Subject));
155 # We could have been smart and done this part when getting the other
156 # transactions, but we are not smart.
159 while ( my $Transaction = $Transactions->Next ) {
160 my $Attach = $Transaction->Attachments->ItemsArrayRef();
161 next if ! defined $Attach->[0];
165 Type => $_->ContentType,
166 Disposition => 'attachment',
167 Filename => $_->Filename,
168 Description => $_->Filename,
176 RT::I18N::SetMIMEEntityToEncoding( $mail, RT->Config->Get('EmailOutputEncoding'), 'mime_words_ok', );
178 RT::Interface::Email::SendEmail( Entity => $mail );
180 # Marking the sending of an email with a transaction in the ticket.
181 # This should be something a little smarter, but that requires a change of
182 # lib/RT/Transactions_Overlay.pm
184 my $trans = RT::Transaction->new( $TicketObj->CurrentUser );
186 Ticket => $TicketObj->Id,
190 NewValue => "$email",
194 #Redirecting back to the ticket.
196 RT::Interface::Web::Redirect( RT->Config->Get('WebURL') . "Ticket/Display.html?id=" . $TicketObj->id );