fix "URL limit exceeded" when errors are present on quick payment entry, RT#9917
authorivan <ivan>
Sat, 27 Nov 2010 03:55:07 +0000 (03:55 +0000)
committerivan <ivan>
Sat, 27 Nov 2010 03:55:07 +0000 (03:55 +0000)
httemplate/elements/create_uri_query [new file with mode: 0644]
httemplate/elements/handle_uri_query [new file with mode: 0644]
httemplate/misc/batch-cust_pay.html
httemplate/misc/process/batch-cust_pay.cgi

diff --git a/httemplate/elements/create_uri_query b/httemplate/elements/create_uri_query
new file mode 100644 (file)
index 0000000..32d8e2f
--- /dev/null
@@ -0,0 +1,25 @@
+<% $query %>\
+<%init>
+
+my $query = $cgi->query_string;
+
+if ( length($query) > 1920 ) { #stupid IE 2083 URL limit
+
+  my $session = int(rand(4294967296)); #XXX
+  my $pref = new FS::access_user_pref({
+    'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
+    'prefname'   => "redirect$session",
+    'prefvalue'  => $query,
+    'expiration' => time + 3600, #1h?  1m?
+  });
+  my $pref_error = $pref->insert;
+  if ( $pref_error ) {
+    die "FATAL: couldn't even set redirect cookie: $pref_error".
+        " attempting to set redirect$session to $query\n";
+  }
+
+  $query = "redirect=$session";
+
+}
+
+</%init>
diff --git a/httemplate/elements/handle_uri_query b/httemplate/elements/handle_uri_query
new file mode 100644 (file)
index 0000000..eb7ea1a
--- /dev/null
@@ -0,0 +1,8 @@
+<%init>
+if ( $cgi->param('redirect') ) {
+  my $session = $cgi->param('redirect');
+  my $pref = $FS::CurrentUser::CurrentUser->option("redirect$session");
+  die "unknown redirect session $session\n" unless length($pref);
+  $cgi = new CGI($pref);
+}
+</%init>
index 610f6e1..c5ed6d8 100644 (file)
@@ -107,7 +107,7 @@ my @footer  = ( '$', '_TOTAL', '' );
 my @footer_align = ( 'c', 'r', 'r' );
 my $custnum_update_callback = '';
 
-if ( FS::Record->scalar_sql('SELECT count(*) FROM part_pkg_discount') ) {
+if ( FS::Record->scalar_sql('SELECT COUNT(*) FROM part_pkg_discount') ) {
   push @header, '';
   push @fields, 'discount_term';
   push @types, 'immutable';
@@ -128,4 +128,6 @@ push @colors, '#ff0000';
 push @footer, '';
 push @footer_align, '';
 
+$m->comp('/elements/handle_uri_query');
+
 </%init>
index e51b9e6..aa37126 100644 (file)
 %
 %    my $erow=0;
 %    $cgi->param('error'. $erow++, shift @errors) while @errors;
-%
 %    
-<% $cgi->redirect($p.'batch-cust_pay.html?'. $cgi->query_string)
+%    my $query = $m->scomp('/elements/create_uri_query');
+%
+<% $cgi->redirect($p."batch-cust_pay.html?$query")
 
   %>
 % } else {