From: Ivan Kohler Date: Tue, 20 Feb 2018 22:17:55 +0000 (-0800) Subject: fix broadband reporting with giant query URLs (large numbers of package defs, etc... X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=266e0c3c894568fb06a15dfbcf4a4eb9bc6989b3 fix broadband reporting with giant query URLs (large numbers of package defs, etc.), RT#76765 --- diff --git a/httemplate/elements/create_uri_query b/httemplate/elements/create_uri_query index ce6249e0e..4d360b255 100644 --- a/httemplate/elements/create_uri_query +++ b/httemplate/elements/create_uri_query @@ -1,3 +1,24 @@ +<%doc> + +Instead of: + + my $link = $self_url. '?'. $cgi->query_string; + +which will fail when the query string exceeds ~2k (browser-dependent) + + +Usage: + + my $query = $m->scomp('/elements/create_uri_query'); + my $link = $self_url. '?'. $query; + +You can also pass an optional 'secure'=>1 parameter to force handling as +session data, even for short query strings. + + +See also handle_uri_query which needs to be used by the target page. + + <% $query %>\ <%init> @@ -14,7 +35,7 @@ if ( $opt{secure} ) { } -my $query = $cgi->query_string; +my $query = $opt{query} || $cgi->query_string; if ( length($query) > 1920 || $opt{secure} ) { #stupid IE 2083 URL limit diff --git a/httemplate/elements/email-link.html b/httemplate/elements/email-link.html index 16935cf98..012afff1a 100644 --- a/httemplate/elements/email-link.html +++ b/httemplate/elements/email-link.html @@ -1,18 +1,19 @@ % if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) { -<%$label%> +<%$label%> % } <%init> my %opt = @_; -my $table = $opt{'table'}; -my $agent_virt_agentnum = $opt{'agent_virt_agentnum'}; my $search_hash = $opt{'search_hash'}; -die "'table' required" if !$table; +die "'table' required" if !$opt{'table'}; die "'search_hash' required" if !$search_hash; my $uri = new URI; my @params = map { $_, $search_hash->{$_} } sort keys %$search_hash; -$uri->query_form(@params); -my $query = $uri->query; +$uri->query_form( @params, + table => $opt{'table'}, + agent_virt_agentnum => $opt{'agent_virt_agentnum'} + ); +my $query = $m->scomp('/elements/create_uri_query', query=>$uri->query); my $label = ($opt{'label'} || 'Email a notice to these customers'); diff --git a/httemplate/elements/handle_uri_query b/httemplate/elements/handle_uri_query index 2dea96a6d..b86ef0092 100644 --- a/httemplate/elements/handle_uri_query +++ b/httemplate/elements/handle_uri_query @@ -1,9 +1,17 @@ +<%doc> + +Usage (before accessing any $cgi parameters): + +$m->comp('/elements/handle_uri_query'); + + <%init> -my %opt = @_; +#my %opt = @_; if ( $cgi->param('redirect') ) { my $session = $cgi->param('redirect'); + my $maxrecords = $cgi->param('maxrecords'); my $pref = $FS::CurrentUser::CurrentUser->option("redirect$session"); die "unknown redirect session $session\n" unless length($pref); @@ -16,5 +24,7 @@ if ( $cgi->param('redirect') ) { $cgi->param($param, $decrypted); } + $cgi->param('maxrecords', $maxrecords) if $maxrecords =~ /^(\d+)$/; + } diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html index f52c6b36a..3f8816caa 100644 --- a/httemplate/misc/email-customers.html +++ b/httemplate/misc/email-customers.html @@ -302,6 +302,8 @@ my $process_url = $opt{'process_url'} || 'process/email-customers.html'; my $title = $opt{'title'} || 'Send customer notices'; push( @no_search_fields, @{$opt{'no_search_fields'}} ) if $opt{'no_search_fields'}; +$m->comp('/elements/handle_uri_query'); + my $table = $cgi->param('table') or die "'table' required"; my $agent_virt_agentnum = $cgi->param('agent_virt_agentnum') || ''; diff --git a/httemplate/search/elements/search-html.html b/httemplate/search/elements/search-html.html index 147a2d984..29e0999c9 100644 --- a/httemplate/search/elements/search-html.html +++ b/httemplate/search/elements/search-html.html @@ -95,8 +95,9 @@ % { % $cgi->delete('maxrecords'); % $cgi->param('_dummy', 1); +% my $query = $m->scomp('/elements/create_uri_query'); - ( show ;maxrecords=' + this.options[this.selectedIndex].value;"> % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) { @@ -139,18 +140,22 @@ <% $opt{'download_label'} || 'Download results:' %> % $cgi->param('_type', "$xlsname.xls" ); - query_string %>">Spreadsheet |  +% my $query = $m->scomp('/elements/create_uri_query'); + ">Spreadsheet |  % $cgi->param('_type', 'csv'); - query_string %>">CSV |  +% my $query = $m->scomp('/elements/create_uri_query'); + ">CSV |  % if ( defined($opt{xml_elements}) ) { % $cgi->param('_type', 'xml'); - query_string %>">XML |  +% my $query = $m->scomp('/elements/create_uri_query'); + ">XML |  % } % $cgi->param('_type', 'html-print'); - query_string %>">webpage +% my $query = $m->scomp('/elements/create_uri_query'); + ">webpage %# "save search" -- for now, obey disable_download and the 'Download %# report data' ACL, because saving a search allows the user to receive @@ -307,8 +312,8 @@ my $self_url = $cgi->url('-path_info' => 1, '-full' =>1); % } else { % $cgi->param('order_by', $field); % } -% $label = qq($label); +% my $query = $m->scomp('/elements/create_uri_query'); +% $label = qq($label); % } % % $colspan = ref($header) ? $header->{colspan} : 0; diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 18b4c0ec5..0e8c69a51 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -222,6 +222,8 @@ my(%opt) = @_; my $curuser = $FS::CurrentUser::CurrentUser; +$m->comp('/elements/handle_uri_query'); + my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|xml|select|html(-print)?)$/ ? $1 : 'html' ; diff --git a/httemplate/search/report_svc_broadband.html b/httemplate/search/report_svc_broadband.html index 210112bc4..45246c74a 100755 --- a/httemplate/search/report_svc_broadband.html +++ b/httemplate/search/report_svc_broadband.html @@ -1,6 +1,6 @@ <% include('/elements/header.html', $title ) %> -
+ %# extensive false laziness with svc_acct diff --git a/httemplate/search/svc_broadband-map.html b/httemplate/search/svc_broadband-map.html index 41f4b8dfd..65830b5d2 100755 --- a/httemplate/search/svc_broadband-map.html +++ b/httemplate/search/svc_broadband-map.html @@ -10,6 +10,8 @@ die "access denied" unless my $conf = new FS::Conf; +$m->comp('/elements/handle_uri_query'); + my @features; # geoJSON structure # accept all the search logic from svc_broadband.cgi... diff --git a/httemplate/search/svc_broadband.cgi b/httemplate/search/svc_broadband.cgi index 80345dc91..53a0aa097 100755 --- a/httemplate/search/svc_broadband.cgi +++ b/httemplate/search/svc_broadband.cgi @@ -82,6 +82,8 @@ my %cust_pkg_cache; my $conf = new FS::Conf; +$m->comp('/elements/handle_uri_query'); + my %search_hash; if ( $cgi->param('magic') eq 'unlinked' ) { %search_hash = ( 'unlinked' => 1 ); @@ -132,9 +134,12 @@ my $html_init = include('/elements/email-link.html', 'search_hash' => \%search_hash, 'table' => 'svc_broadband' ); + +my $query = $m->scomp('/elements/create_uri_query'); + $html_init .= ' | ' . '' . emt('View a map of these services') . ''; my (@header_pkg,@fields_pkg,@blank_pkg);