RT# 77021 - fixed advanced report criteria so agent and other fileds with a . in...
[freeside.git] / rt / share / html / Search / Build.html
index ae4c7ba..cffcbf4 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -53,7 +53,7 @@
 %#   Build/Edit.html (Advanced).)
 %#
 %#   After doing some stuff with default arguments and saved searches, the ParseQuery
 %#   Build/Edit.html (Advanced).)
 %#
 %#   After doing some stuff with default arguments and saved searches, the ParseQuery
-%#   function (which is similar to, but not the same as, _parser in lib/RT/Tickets_SQL.pm)
+%#   function (which is similar to, but not the same as, _parser in lib/RT/Tickets.pm)
 %#   converts the Query into a RT::Interface::Web::QueryBuilder::Tree.  This mason file
 %#   then adds stuff to or modifies the tree based on the actions that had been requested
 %#   by clicking buttons.  It then calls GetQueryAndOptionList on the tree to generate
 %#   converts the Query into a RT::Interface::Web::QueryBuilder::Tree.  This mason file
 %#   then adds stuff to or modifies the tree based on the actions that had been requested
 %#   by clicking buttons.  It then calls GetQueryAndOptionList on the tree to generate
@@ -67,7 +67,6 @@
 %#
 <& /Elements/Header, Title => $title &>
 <& /Elements/Tabs, %TabArgs &>
 %#
 <& /Elements/Header, Title => $title &>
 <& /Elements/Tabs, %TabArgs &>
-
 <form method="post" action="Build.html" name="BuildQuery" id="BuildQuery">
 <input type="hidden" class="hidden" name="SavedSearchId" value="<% $saved_search{'Id'} %>" />
 <input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $ARGS{'SavedChartSearchId'} %>" />
 <form method="post" action="Build.html" name="BuildQuery" id="BuildQuery">
 <input type="hidden" class="hidden" name="SavedSearchId" value="<% $saved_search{'Id'} %>" />
 <input type="hidden" class="hidden" name="SavedChartSearchId" value="<% $ARGS{'SavedChartSearchId'} %>" />
@@ -78,7 +77,7 @@
 
 
 <div id="pick-criteria">
 
 
 <div id="pick-criteria">
-    <& Elements/PickCriteria, query => $query{'Query'}, cfqueues => $queues &>
+    <& Elements/PickCriteria, query => $query{'Query'}, queues => $queues &>
 <& /Elements/Submit,  Label => loc('Add these terms'), SubmitId => 'AddClause', Name => 'AddClause'&>
 <& /Elements/Submit, Label => loc('Add these terms and Search'), SubmitId => 'DoSearch', Name => 'DoSearch'&>
 </div>
 <& /Elements/Submit,  Label => loc('Add these terms'), SubmitId => 'AddClause', Name => 'AddClause'&>
 <& /Elements/Submit, Label => loc('Add these terms and Search'), SubmitId => 'DoSearch', Name => 'DoSearch'&>
 </div>
@@ -140,7 +139,11 @@ if ( $NewQuery ) {
 
     my $current = $session{'CurrentSearchHash'};
     my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
 
     my $current = $session{'CurrentSearchHash'};
     my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
-    my $default = { Query => '', Format => '', OrderBy => 'id', Order => 'ASC', RowsPerPage => 50 };
+    my $default = { Query => '',
+                    Format => '',
+                    OrderBy => RT->Config->Get('DefaultSearchResultOrderBy'),
+                    Order => RT->Config->Get('DefaultSearchResultOrder'),
+                    RowsPerPage => 50 };
 
     for( qw(Query Format OrderBy Order RowsPerPage) ) {
         $query{$_} = $current->{$_} unless defined $query{$_};
 
     for( qw(Query Format OrderBy Order RowsPerPage) ) {
         $query{$_} = $current->{$_} unless defined $query{$_};
@@ -188,9 +191,15 @@ my @options = $tree->GetDisplayedNodes;
 my @current_values = grep defined, @options[@clauses];
 my @new_values = ();
 
 my @current_values = grep defined, @options[@clauses];
 my @new_values = ();
 
+my $cf_field_names =
+    join "|",
+     map quotemeta,
+    grep { $RT::Tickets::FIELD_METADATA{$_}->[0] eq 'CUSTOMFIELD' }
+    sort keys %RT::Tickets::FIELD_METADATA;
+
 # Try to find if we're adding a clause
 foreach my $arg ( keys %ARGS ) {
 # Try to find if we're adding a clause
 foreach my $arg ( keys %ARGS ) {
-    next unless $arg =~ m/^ValueOf([\w\.]+|'CF.{.*?}')$/
+    next unless $arg =~ m/^ValueOf([\w\.]+|($cf_field_names).\{.*?\})$/
                 && ( ref $ARGS{$arg} eq "ARRAY"
                      ? grep $_ ne '', @{ $ARGS{$arg} }
                      : $ARGS{$arg} ne '' );
                 && ( ref $ARGS{$arg} eq "ARRAY"
                      ? grep $_ ne '', @{ $ARGS{$arg} }
                      : $ARGS{$arg} ne '' );
@@ -220,8 +229,9 @@ foreach my $arg ( keys %ARGS ) {
     for ( my $i = 0; $i < @ops; $i++ ) {
         my ( $op, $value ) = ( $ops[$i], $values[$i] );
         next if !defined $value || $value eq '';
     for ( my $i = 0; $i < @ops; $i++ ) {
         my ( $op, $value ) = ( $ops[$i], $values[$i] );
         next if !defined $value || $value eq '';
+        my $rawvalue = $value;
 
 
-        if ( $value eq 'NULL' && $op =~ /=/ ) {
+        if ( $value =~ /^NULL$/i && $op =~ /=/ ) {
             if ( $op eq '=' ) {
                 $op = "IS";
             }
             if ( $op eq '=' ) {
                 $op = "IS";
             }
@@ -234,16 +244,15 @@ foreach my $arg ( keys %ARGS ) {
             $value = "'$value'";
         }
 
             $value = "'$value'";
         }
 
-        if ($keyword =~ /^'CF\.{(.*)}'/) {
-            my $cf = $1;
-            $cf =~ s/(['\\])/\\$1/g;
-            $keyword = "'CF.{$cf}'";
+        if ($keyword =~ s/(['\\])/\\$1/g or $keyword =~ /[^{}\w\.]/) {
+            $keyword = "'$keyword'";
         }
 
         my $clause = {
             Key   => $keyword,
             Op    => $op,
         }
 
         my $clause = {
             Key   => $keyword,
             Op    => $op,
-            Value => $value
+            Value => $value,
+            RawValue => $rawvalue,
         };
 
         push @new_values, RT::Interface::Web::QueryBuilder::Tree->new($clause);
         };
 
         push @new_values, RT::Interface::Web::QueryBuilder::Tree->new($clause);
@@ -275,7 +284,7 @@ my ( $AvailableColumns, $CurrentFormat );
 ( $query{'Format'}, $AvailableColumns, $CurrentFormat ) = $m->comp(
     'Elements/BuildFormatString',
     %ARGS,
 ( $query{'Format'}, $AvailableColumns, $CurrentFormat ) = $m->comp(
     'Elements/BuildFormatString',
     %ARGS,
-    cfqueues => $queues,
+    queues => $queues,
     Format => $query{'Format'},
 );
 
     Format => $query{'Format'},
 );
 
@@ -308,7 +317,7 @@ if ( $ARGS{'DoSearch'} ) {
         SavedChartSearchId => $ARGS{'SavedChartSearchId'},
         SavedSearchId => $saved_search{'Id'},
     );
         SavedChartSearchId => $ARGS{'SavedChartSearchId'},
         SavedSearchId => $saved_search{'Id'},
     );
-    RT::Interface::Web::Redirect(RT->Config->Get('WebPath') . '/Search/Results.html?' . $redir_query_string);
+    RT::Interface::Web::Redirect(RT->Config->Get('WebURL') . 'Search/Results.html?' . $redir_query_string);
     $m->abort;
 }
 
     $m->abort;
 }