default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / create_uri_query
1 <%doc>
2
3 Instead of:
4
5   my $link = $self_url. '?'. $cgi->query_string;
6
7 which will fail when the query string exceeds ~2k (browser-dependent)
8
9
10 Usage:
11
12   my $query = $m->scomp('/elements/create_uri_query');
13   my $link = $self_url. '?'. $query;
14
15 You can also pass an optional 'secure'=>1 parameter to force handling as
16 session data, even for short query strings.
17
18
19 See also handle_uri_query which needs to be used by the target page.
20
21 </%doc>
22 <% $query %>\
23 <%init>
24
25 my %opt = @_;
26
27 if ( $opt{secure} ) {
28
29   foreach my $param (grep /pay(info\d?|cvv)$/, $cgi->param) {
30     my $value = $cgi->param($param);
31     next unless length($value);
32     my $encrypted = FS::Record->encrypt( $value );
33     $cgi->param($param, $encrypted);
34   }
35
36 }
37
38 my $query = $opt{query} || $cgi->query_string;
39
40 if ( length($query) > 1920 || $opt{secure} ) { #stupid IE 2083 URL limit
41
42   my $session = int(rand(4294967296)); #XXX
43   my $pref = new FS::access_user_pref({
44     'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
45     'prefname'   => "redirect$session",
46     'prefvalue'  => $query,
47     'expiration' => time + ( $opt{secure} ? 120  #2m?
48                                           : 3600 #1h?
49                            ),
50   });
51   local($FS::Record::no_history) = 1;
52
53   my $pref_error = $pref->insert;
54   if ( $pref_error ) {
55     die "FATAL: couldn't even set redirect cookie: $pref_error".
56         " attempting to set redirect$session to $query\n";
57   }
58
59   $query = "redirect=$session";
60
61 }
62
63 </%init>