]> git.uio.no Git - usit-rt.git/blob - local/html/Ticket/Export.html
Initial commit 4.0.5-3
[usit-rt.git] / local / html / Ticket / Export.html
1 %## Default elements from RT. Header and the ticket elements. Both this and the 
2 %## html printed after the <%INIT>
3 <& /Elements/Header, 
4     Title => loc("#[_1]: [_2]", $TicketObj->Id, $TicketObj->Subject),
5     LinkRel => \%link_rel &>
6 <& /Elements/Tabs &> 
7
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>
13 <br><br>
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&aring; her</a>
16 <br>
17 Send eventuelle kommentarar og feil/manglar til rt-drift@usit.uio.no.
18 <br>
19 <span>
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."\"/>";
23 <br>
24 <input type="submit" value="Send email"/>
25 </span>
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;">
28 %print "$mail_head";
29 %print "$mail";
30 </pre>
31 </div>
32 </div>
33 </div>
34
35 <%ARGS>
36 $id => undef
37 $TicketObj => undef
38 $email => undef
39 </%ARGS>
40
41 <%INIT>
42 my (@Actions, $Tickets);  
43
44
45 unless ($id || $TicketObj) {
46     Abort('No ticket specified');
47 }
48
49 $TicketObj ||= LoadTicket($ARGS{'id'});
50
51 unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
52     Abort("No permission to view ticket");
53 }
54
55 # used to convert html-formated email -> plain text for the body.
56 use HTML::Parse;
57 use HTML::FormatText;
58 my $formater = HTML::FormatText->new(leftmargin => 0, rightmargin => 75);
59
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);
63
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;
73 my @requestors;
74 while ( my $r = $people->Next ) {
75 push @requestors, $m->scomp('/Elements/ShowUserConcise', User => $r);
76 }
77 my $requestors = join ("\n              ", @requestors);
78
79
80 my $Transactions = $TicketObj->Transactions;
81
82 my @attachments = @{$attachments->ItemsArrayRef()};
83 my @attachment_content = @{$attachment_content->ItemsArrayRef()};
84 my $mail;
85 my $mailsendt=0;
86 my $attach=0;
87
88 my $resolved = "";
89 my $created;
90 my $mail_head;
91
92 # Find the last time the ticket was resolved.
93
94 #### NEED FIX HERE ###
95
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:     /;
102 }
103
104 # Ignoring comments/statuschange/etc.
105 next if $Transaction->Description !~ /(Correspondence added|Ticket created )/;
106
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;
114 for (@$Attach) {
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"
118         }
119
120 # Finding the mail attachments that will be attached to the final email.
121         if ($_->Filename) {$mail .= "Attatchment: ".$_->Filename."\n\n";$attach=1;}
122 }
123
124 }
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
128 # transaction.
129
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";
142
143 # Building an mime-email if we are to send an email.
144 if ($email){
145     my $mail = MIME::Entity->build(
146         Type => 'text/plain',
147         Charset => 'utf-8',
148         Data => $mail_head."\n".$mail,
149     );
150
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));
154    
155 # We could have been smart and done this part when getting the other 
156 # transactions, but we are not smart. 
157
158     if ($attach){
159         while ( my $Transaction = $Transactions->Next ) {
160             my $Attach = $Transaction->Attachments->ItemsArrayRef();
161             next if ! defined $Attach->[0];
162             for (@$Attach) {
163                 if ($_->Filename){
164                     $mail->attach(
165                         Type => $_->ContentType,
166                         Disposition => 'attachment',
167                         Filename => $_->Filename,
168                         Description => $_->Filename,
169                         Data => $_->Content,
170                     );
171                 }
172             }
173         }
174     }
175
176         RT::I18N::SetMIMEEntityToEncoding( $mail, RT->Config->Get('EmailOutputEncoding'), 'mime_words_ok', );
177
178     RT::Interface::Email::SendEmail( Entity => $mail );
179
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
183
184     my $trans = RT::Transaction->new( $TicketObj->CurrentUser );
185     $trans->Create(
186             Ticket      => $TicketObj->Id,
187             Type        => 'Export',
188             Field       => "Email",
189             OldValue    => "Email",
190             NewValue    => "$email",
191             ActivateScrips => 0
192         );
193
194 #Redirecting back to the ticket.
195
196         RT::Interface::Web::Redirect( RT->Config->Get('WebURL') . "Ticket/Display.html?id=" . $TicketObj->id );
197     
198     $mailsendt=1;
199 }
200
201 my %link_rel;
202 </%INIT>