]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/templates/default/opac/parts/header.tt2
9b9132c54595dd358f1c3a68e1aa415ca346c881
[working/Evergreen.git] / Open-ILS / web / templates / default / opac / parts / header.tt2
1 [%- USE money = format(l('$%.2f'));
2     USE date;
3     USE CGI = CGI_utf8;
4     USE POSIX;
5     SET DATE_FORMAT = l('%m/%d/%Y');
6
7     # Don't wrap in l() here; do that where this format string is actually used.
8     SET HUMAN_NAME_FORMAT = '[_1] [_2] [_3] [_4] [_5]';
9
10     # x and y are artifacts of using <input type="image" /> tags instead of
11     # true submit buttons, and their values are never used. page is used, but
12     # currently none of the use cases for rendering the query_string back
13     # into page output call for propagating the value of the page variable.
14
15     query_string = CGI.query_string |
16         replace(';x=\d+','') | replace(';y=\d+','') | replace(';page=\d*', '') |
17         replace(';', '&') | replace('&', '&amp;');
18
19     propagator = '?' _ query_string;
20
21     is_advanced = CGI.param("_adv").size;
22     is_special = CGI.param("_special").size;
23
24     # -----------------------------------------------------------------------------
25     # mkurl()
26     #
27     # Current page, updated params:
28     # mkurl('', {foo => 'bar', boo => 'baz'});
29     #
30     # New page, one param is a list:
31     # mkurl('http://flarg.baz/squz', {foo => 'bar', boo => ['baz', 'faz']});
32     #
33     # New page, clear all existing params before applying new ones:
34     # mkurl('/fuz/buster', {foo => 'bar', boo => 'baz'}, 1); 
35     #
36     # Current page, clear the 'some_param' from the existing params:
37     # mkurl('', {foo => 'bar', boo => 'baz'}, ['some_param']);
38     MACRO mkurl(page, params, clear_params) BLOCK;
39
40         # clone the query string to avoid clobberation
41         cgi = CGI.new(CGI.query_string);
42
43         # remove requested params
44         IF clear_params.0; # array
45             FOR p IN clear_params; cgi.delete(p); END;
46         ELSIF clear_params;
47             cgi.delete_all();
48         END;
49
50         # always remove these pesky artifacts
51         cgi.delete('x', 'y'); 
52
53         # apply user params
54         FOR k IN params.keys;
55             foo = cgi.param("-name", k, "-values", params.$k); 
56         END;
57
58         # for url brevity, remove any params that have no value
59         FOR p IN cgi.param;
60             val = cgi.param(p);
61             IF val == ''; cgi.delete(p); END;
62         END;
63
64         IF page;
65             page _ '?' _ cgi.query_string;
66         ELSE;
67             cgi.url("-path" => 1, "-query" => 1);
68         END;
69     END;
70 %]