This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / rt / html / Search / Elements / BuildFormatString
1 %# {{{ BEGIN BPS TAGGED BLOCK
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# }}} END BPS TAGGED BLOCK
46 <%args>
47 $Format => undef
48 %cfqueues => undef
49 </%args>
50 <%init>
51
52 unless ($Format) {         
53     $Format = $RT::DefaultSearchResultFormat;
54 }   
55     
56 my @fields = (
57     "QueueName",           "OwnerName",
58     "id",                  "Status",
59     "Subject",             "ExtendedStatus",
60     "Priority",            "InitialPriority",
61     "FinalPriority",       "EffectiveId",
62     "Type",                "TimeWorked",
63     "TimeLeft",            "TimeEstimated",
64     "Requestors",          "Cc",
65     "AdminCc",             "StartsRelative",
66     "StartedRelative",     "CreatedRelative",
67     "LastUpdatedRelative", "ToldRelative",
68     "DueRelative",         "ResolvedRelative",
69     "Starts",              "Started",
70     "Created",             "CreatedBy",
71     "LastUpdated",         "LastUpdatedBy",
72     "Told",                "Due",
73     "Resolved",            "NEWLINE",
74     "RefersTo",            "ReferredToBy",
75     "DependsOn",           "DependedOnBy",
76     "MemberOf",            "Members",
77     "Parents",             "Children",
78     "-",
79 );
80
81 my $CustomFields = RT::CustomFields->new( $session{'CurrentUser'});
82 foreach (keys %cfqueues) {
83     my $id = $_;
84     $id =~ s/^.'*(.*).'*$/$1/;
85     # Gotta load up the $queue object, since queues get stored by name now.
86     my $queue = RT::Queue->new($session{'CurrentUser'});
87     $queue->Load($id);
88     $CustomFields->LimitToQueue($queue->Id);
89 }
90 $CustomFields->LimitToGlobal;
91
92 while ( my $CustomField = $CustomFields->Next ) {
93     my $queuestr;
94     if ($CustomField->QueueObj && $CustomField->QueueObj->Id != 0) {
95         $queuestr = $CustomField->QueueObj->Name . ".";
96     }
97     push @fields, "CustomField." . $queuestr . "{" . $CustomField->Name . "}";
98 }
99
100 my ( @seen);
101
102 my @format = split( /,\s*/, $Format );
103 foreach my $field (@format) {
104     my %column = ();
105     $field =~ s/'(.*)'/$1/;
106     my ( $prefix, $suffix );
107     if ( $field =~ m/(.*)__(.*)__(.*)/ ) {
108         $prefix = $1;
109         $suffix = $3;
110         $field  = $2;
111     }
112     $field = "<blank>" if !$field;
113     $column{Prefix} = $prefix;
114     $column{Suffix} = $suffix;
115     $field =~ s/\s*(.*)\s*/$1/;
116     $column{Column} = $field;
117     push @seen, \%column;
118 }
119
120 if ( $ARGS{"RemoveCol"} ) {
121     my $index  = $ARGS{'CurrentDisplayColumns'};
122     my $column = $seen[$index];
123     if ($index) {
124         delete $seen[$index];
125         my @temp = @seen;
126         @seen = ();
127         foreach my $element (@temp) {
128             next unless $element;
129             push @seen, $element;
130         }
131     }
132 }
133 elsif ( $ARGS{"AddCol"} ) {
134     if ( defined $ARGS{'SelectDisplayColumns'} ) {
135         my $selected = $ARGS{'SelectDisplayColumns'};
136         my @columns;
137         if (ref($selected) eq 'ARRAY') {
138             @columns = @$selected;
139         } else {
140             push @columns, $selected;
141         }
142         foreach my $col (@columns) {
143             my %column = ();
144             $column{Column} = $fields[ $col ];
145             
146             if ( $ARGS{Face} eq "Bold" ) {
147                 $column{Prefix} .= "<B>";
148             }
149             if ( $ARGS{Face} eq "Italic" ) {
150                 $column{Prefix} .= "<I>";
151             }
152             if ( $ARGS{Size} ) {
153                 $column{Prefix} .= "<" . $ARGS{Size} . ">";
154             }
155             if ( $ARGS{Link} eq "Display" ) {
156                 $column{Prefix} .= "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?id=__id__\">";
157             }
158             elsif ( $ARGS{Link} eq "Take" ) {
159                 $column{Prefix} .=
160                     "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?Action=Take&id=__id__\">";
161             }
162     
163             my $suffix;
164             if ( $ARGS{'Link'} eq "Display" || $ARGS{'Link'} eq "Take" ) {
165                 $column{Suffix} .= "</a>";
166             }
167             if ( $ARGS{Size} ) {
168                 $column{Suffix} .= "</" . $ARGS{Size} . ">";
169             }
170             if ( $ARGS{Face} eq "Italic" ) {
171                 $column{Suffix} .= "</I>";
172             }
173             if ( $ARGS{Face} eq "Bold" ) {
174                 $column{Suffix} .= "</B>";
175             }
176             if ( $ARGS{Title} ) {
177                 $column{Suffix} .= "/TITLE:" . $ARGS{Title};
178             }
179             push @seen, \%column;
180         }
181     }
182 }
183 elsif ( $ARGS{"ColUp"} ) {
184     my $index = $ARGS{'CurrentDisplayColumns'};
185     if ( defined $index && ( $index - 1 ) >= 0 ) {
186         my $column = $seen[$index];
187         $seen[$index]       = $seen[ $index - 1 ];
188         $seen[ $index - 1 ] = $column;
189         $ARGS{CurrentDisplayColumns}     = $index - 1;
190     }
191 }
192 elsif ( $ARGS{"ColDown"} ) {
193     my $index = $ARGS{'CurrentDisplayColumns'};
194     if ( defined $index && ( $index + 1 ) < scalar @seen ) {
195         my $column = $seen[$index];
196         $seen[$index]       = $seen[ $index + 1 ];
197         $seen[ $index + 1 ] = $column;
198         $ARGS{CurrentDisplayColumns}     = $index + 1;
199     }
200 }
201
202 $Format = "";
203 foreach my $field (@seen) {
204     next unless $field;
205     $Format .= ", \n" if $Format;
206     $Format .= "'";
207     $Format .= $field->{Prefix};
208     $Format .= "__" . $field->{Column} . "__" if ( $field->{Column} ne "<blank>" ) ;
209     $Format .= $field->{Suffix};
210     $Format .= "'";
211 }
212 return($Format, \@fields, \@seen);
213
214 </%init>
215