import rt 3.8.11
[freeside.git] / rt / html / Search / Elements / BuildFormatString
index e5e131b..0526333 100644 (file)
@@ -1,8 +1,8 @@
-%# {{{ BEGIN BPS TAGGED BLOCK
+%# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
 %#  
-%# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
+%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
 %#                                          <jesse@bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
 %# 
 %# You should have received a copy of the GNU General Public License
 %# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 %# 
 %# 
 %# CONTRIBUTION SUBMISSION POLICY:
 %# works based on those contributions, and sublicense and distribute
 %# those contributions and any derivatives thereof.
 %# 
-%# }}} END BPS TAGGED BLOCK
+%# END BPS TAGGED BLOCK }}}
 <%args>
 $Format => undef
 %cfqueues => undef
+$Face => undef
+$Size => undef
+$Link => undef
+$Title => undef
+$AddCol => undef
+$RemoveCol => undef
+$ColUp => undef
+$ColDown => undef
+$SelectDisplayColumns => undef
+$CurrentDisplayColumns => undef
 </%args>
 <%init>
 
 unless ($Format) {         
     $Format = $RT::DefaultSearchResultFormat;
 }   
-    
-my @fields = (
-    "QueueName",           "OwnerName",
-    "id",                  "Status",
-    "Subject",             "ExtendedStatus",
-    "Priority",            "InitialPriority",
-    "FinalPriority",       "EffectiveId",
-    "Type",                "TimeWorked",
-    "TimeLeft",            "TimeEstimated",
-    "Requestors",          "Cc",
-    "AdminCc",             "StartsRelative",
-    "StartedRelative",     "CreatedRelative",
-    "LastUpdatedRelative", "ToldRelative",
-    "DueRelative",         "ResolvedRelative",
-    "Starts",              "Started",
-    "Created",             "CreatedBy",
-    "LastUpdated",         "LastUpdatedBy",
-    "Told",                "Due",
-    "Resolved",            "NEWLINE",
-    "RefersTo",                   "ReferredToBy",
-    "DependsOn",           "DependedOnBy",
-    "MemberOf",            "Members",
-    "Parents",             "Children",
-    "-",
+   
+
+# All the things we can display in the format string by default
+my @fields = qw(
+  id
+  Status
+  ExtendedStatus
+  Subject
+  QueueName
+  OwnerName
+  Priority
+  InitialPriority
+  FinalPriority
+  Type
+  TimeWorked
+  TimeLeft
+  TimeEstimated
+  CreatedBy
+  LastUpdatedBy
+  Requestors
+  Cc
+  AdminCc
+  Starts
+  StartsRelative
+  Started
+  StartedRelative
+  Created
+  CreatedRelative
+  LastUpdated
+  LastUpdatedRelative
+  Told
+  ToldRelative
+  Due
+  DueRelative
+  Resolved
+  ResolvedRelative
+  RefersTo
+  ReferredToBy
+  DependsOn
+  DependedOnBy
+  MemberOf
+  Members
+  Parents
+  Children
+  NEWLINE
 );
 
 my $CustomFields = RT::CustomFields->new( $session{'CurrentUser'});
-foreach (keys %cfqueues) {
-    my $id = $_;
+foreach my $id (keys %cfqueues) {
+    # What does this _do_? What are the keys to cfqueues
     $id =~ s/^.'*(.*).'*$/$1/;
     # Gotta load up the $queue object, since queues get stored by name now.
     my $queue = RT::Queue->new($session{'CurrentUser'});
@@ -90,11 +123,7 @@ foreach (keys %cfqueues) {
 $CustomFields->LimitToGlobal;
 
 while ( my $CustomField = $CustomFields->Next ) {
-    my $queuestr;
-    if ($CustomField->QueueObj && $CustomField->QueueObj->Id != 0) {
-       $queuestr = $CustomField->QueueObj->Name . ".";
-    }
-    push @fields, "CustomField." . $queuestr . "{" . $CustomField->Name . "}";
+    push @fields, "CustomField.{" . $CustomField->Name . "}";
 }
 
 my ( @seen);
@@ -117,8 +146,8 @@ foreach my $field (@format) {
     push @seen, \%column;
 }
 
-if ( $ARGS{"RemoveCol"} ) {
-    my $index  = $ARGS{'CurrentDisplayColumns'};
+if ( $RemoveCol ) {
+    my $index  = $CurrentDisplayColumns;
     my $column = $seen[$index];
     if ($index) {
         delete $seen[$index];
@@ -130,9 +159,9 @@ if ( $ARGS{"RemoveCol"} ) {
         }
     }
 }
-elsif ( $ARGS{"AddCol"} ) {
-    if ( defined $ARGS{'SelectDisplayColumns'} ) {
-       my $selected = $ARGS{'SelectDisplayColumns'};
+elsif ( $AddCol ) {
+    if ( defined $SelectDisplayColumns ) {
+       my $selected = $SelectDisplayColumns;
        my @columns;
        if (ref($selected) eq 'ARRAY') {
            @columns = @$selected;
@@ -141,74 +170,74 @@ elsif ( $ARGS{"AddCol"} ) {
        }
        foreach my $col (@columns) {
            my %column = ();
-           $column{Column} = $fields[ $col ];
-           
-           if ( $ARGS{Face} eq "Bold" ) {
-               $column{Prefix} .= "<B>";
-           }
-           if ( $ARGS{Face} eq "Italic" ) {
-               $column{Prefix} .= "<I>";
-           }
-           if ( $ARGS{Size} ) {
-               $column{Prefix} .= "<" . $ARGS{Size} . ">";
-           }
-           if ( $ARGS{Link} eq "Display" ) {
-               $column{Prefix} .= "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?id=__id__\">";
-           }
-           elsif ( $ARGS{Link} eq "Take" ) {
-               $column{Prefix} .=
-                   "<A HREF=\"".$RT::WebPath."/Ticket/Display.html?Action=Take&id=__id__\">";
-           }
-    
-           my $suffix;
-           if ( $ARGS{'Link'} eq "Display" || $ARGS{'Link'} eq "Take" ) {
-               $column{Suffix} .= "</a>";
-           }
-           if ( $ARGS{Size} ) {
-               $column{Suffix} .= "</" . $ARGS{Size} . ">";
-           }
-           if ( $ARGS{Face} eq "Italic" ) {
-               $column{Suffix} .= "</I>";
-           }
-           if ( $ARGS{Face} eq "Bold" ) {
-               $column{Suffix} .= "</B>";
-           }
-           if ( $ARGS{Title} ) {
-               $column{Suffix} .= "/TITLE:" . $ARGS{Title};
-           }
-           push @seen, \%column;
-       }
+           $column{Column} = $col;
+
+    if ( $Face eq "Bold" ) {
+        $column{Prefix} .= "<b>";
+        $column{Suffix} .= "</b>";
+    }
+    if ( $Face eq "Italic" ) {
+        $column{Prefix} .= "<i>";
+        $column{Suffix} .= "</i>";
     }
+    if ($Size) {
+        $column{Prefix} .= "<" . $m->interp->apply_escapes( $Size,  'h' ) . ">";
+        $column{Suffix} .= "</" . $m->interp->apply_escapes( $Size, 'h' ) . ">";
+    }
+    if ( $Link eq "Display" ) {
+        $column{Prefix} .=
+          "<a HREF=\"" . $RT::WebPath . "/Ticket/Display.html?id=__id__\">";
+        $column{Suffix} .= "</a>";
+    }
+    elsif ( $Link eq "Take" ) {
+        $column{Prefix} .= "<a HREF=\"" . $RT::WebPath
+          . "/Ticket/Display.html?Action=Take&id=__id__\">";
+        $column{Suffix} .= "</a>";
+    }
+
+    if ($Title) {
+        $column{Suffix} .= "/TITLE:" . $m->interp->apply_escapes( $Title, 'h' );
+    }
+    push @seen, \%column;
+}
+}
 }
-elsif ( $ARGS{"ColUp"} ) {
-    my $index = $ARGS{'CurrentDisplayColumns'};
+elsif ( $ColUp ) {
+    my $index = $CurrentDisplayColumns;
     if ( defined $index && ( $index - 1 ) >= 0 ) {
         my $column = $seen[$index];
         $seen[$index]       = $seen[ $index - 1 ];
         $seen[ $index - 1 ] = $column;
-        $ARGS{CurrentDisplayColumns}     = $index - 1;
+        $CurrentDisplayColumns     = $index - 1;
     }
 }
-elsif ( $ARGS{"ColDown"} ) {
-    my $index = $ARGS{'CurrentDisplayColumns'};
+elsif ( $ColDown ) {
+    my $index = $CurrentDisplayColumns;
     if ( defined $index && ( $index + 1 ) < scalar @seen ) {
         my $column = $seen[$index];
         $seen[$index]       = $seen[ $index + 1 ];
         $seen[ $index + 1 ] = $column;
-        $ARGS{CurrentDisplayColumns}     = $index + 1;
+        $CurrentDisplayColumns     = $index + 1;
     }
 }
 
-$Format = "";
+
+my @format_string;
 foreach my $field (@seen) {
     next unless $field;
-    $Format .= ", \n" if $Format;
-    $Format .= "'";
-    $Format .= $field->{Prefix};
-    $Format .= "__" . $field->{Column} . "__" if ( $field->{Column} ne "<blank>" ) ;
-    $Format .= $field->{Suffix};
-    $Format .= "'";
+    my $row = "'";
+    $row .= $field->{Prefix} if $field->{Prefix};
+    $row .= "__" . ($field->{Column} =~ m/\(/ ? $field->{Column} # func, don't escape
+                   : $m->interp->apply_escapes( $field->{Column}, 'h' )) . "__"
+      unless ( $field->{Column} eq "<blank>" );
+    $row .= $field->{Suffix} if $field->{Suffix};
+    $row .= "'";
+    push( @format_string, $row );
 }
+
+$Format = join(",\n", @format_string);
+
+
 return($Format, \@fields, \@seen);
 
 </%init>