import rt 3.6.4
[freeside.git] / rt / html / Search / Results.tsv
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/copyleft/gpl.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <%ARGS>
49 $OrderBy => 'id'
50 $Order => 'ASC'
51 </%ARGS>
52 <%INIT>
53
54 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
55 $Tickets->FromSQL( $ARGS{'Query'} );
56 if ( $OrderBy =~ /\|/ ) {
57
58   # Multiple Sorts
59   my @OrderBy = split /\|/, $OrderBy;
60   my @Order   = split /\|/, $Order;
61   $Tickets->OrderByCols(
62     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
63       ( 0 .. $#OrderBy ) );
64 }
65 else {
66   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
67 }
68
69 my @rows;
70 my %known_cfs;
71
72 my @attrs = qw( id QueueObj->Name Subject Status TimeEstimated TimeWorked TimeLeft Priority FinalPriority OwnerObj->Name 
73                 Requestors->MemberEmailAddressesAsString Cc->MemberEmailAddressesAsString AdminCc->MemberEmailAddressesAsString
74                 DueObj->ISO ToldObj->ISO CreatedObj->ISO ResolvedObj->ISO LastUpdatedObj->ISO);
75
76 $r->content_type('application/vnd.ms-excel');
77 while ( my $Ticket = $Tickets->Next()) {
78     my $row;
79     foreach my $attr (@attrs) {
80         if ($attr =~ /(.*)->ISO$/ and $Ticket->$1->Unix <= 0) {
81             $row->{$attr} = "";
82         } else {
83             my $method = '$Ticket->'.$attr.'()';
84             $row->{$attr} = eval $method;
85             if ($@) {die "Failed to find $attr - ". $@}; 
86         }
87     }
88
89     my $cfs = $Ticket->QueueObj->TicketCustomFields();
90     while (my $cf = $cfs->Next) {
91         my @content;
92         my $values = $Ticket->CustomFieldValues($cf->Id);
93         while (my $value = $values->Next) {
94             push @content, $value->Content;
95         }
96         $row->{'CustomField-'.$cf->Id} = join(', ',@content);
97         if ($row->{'CustomField-'.$cf->Id}) {
98             $known_cfs{$cf->Id} = $cf->Name;
99         }
100     }
101     push @rows, $row;
102 }
103
104
105     my @header;
106     foreach my $attr (@attrs) {
107         my $label = $attr;
108         $label =~ s'Obj-.(?:AsString|Name|ISO)''g;
109         $label =~ s'-\>MemberEmailAddressesAsString''g;
110         push @header, $label;
111     }
112     foreach my $id (sort keys %known_cfs) {
113         push @header, "CF-".$known_cfs{$id}; 
114     }
115     $m->out(join("\t", @header));
116     $m->out("\n");
117 }
118
119 foreach my $row (@rows) {
120     my @row;
121     foreach my $attr(@attrs) {
122         push @row, $row->{"$attr"};
123     }
124     foreach my $id (sort keys %known_cfs) {
125         my $val = $row->{'CustomField-'.$id};
126         $val =~ s/(\n|\r)//g;
127         push @row, $val;
128     }
129     $m->out(join("\t",@row));
130     $m->out("\n");
131 }
132
133 $m->abort();
134 </%INIT>