default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / select-cust_location.html
1 % my @pre_options  = $opt{pre_options}  ? @{ $opt{pre_options} } : ();
2 % if (     ! @pre_options
3 %       && ! $cust_main
4 %       && ! $opt{is_optional}
5 %       && ! @{ $opt{cust_location} }
6 %       && $addnew
7 % ) {
8     <INPUT NAME="locationnum" ID="locationnum" TYPE="hidden" VALUE="-1">
9 % } else {
10
11 <SELECT NAME     = "locationnum"
12         ID       = "locationnum"
13 %     if ( $opt{onchange} ) {
14         onchange = "<% $opt{onchange} %>"
15 %     }
16     >
17
18 % #false laziness w/select-table.html
19 % while ( @pre_options ) { 
20 %   my $pre_opt   = shift(@pre_options);
21 %   my $pre_label = shift(@pre_options);
22 %   my $selected = #$opt{'all_selected'}
23 %                  # || ( ref($locationnum) && $locationnum->{$pre_opt} )
24 %                  # ||
25 %                       ( $locationnum eq $pre_opt );
26     <OPTION VALUE="<% $pre_opt %>"
27             <% $selected ? 'SELECTED' : '' %>
28     ><% $pre_label %>
29 % } 
30
31 % if ( $cust_main ) {
32 %   my $selected = ( $locationnum == $cust_main->ship_locationnum );
33     <OPTION VALUE="<% $cust_main->ship_locationnum %>"
34             <% $selected ? 'SELECTED' : '' %>
35     ><% $opt{'empty_label'} || '(default service address)' |h %>
36 % }
37
38 % if ( $opt{'is_optional'} ) {
39   <OPTION VALUE="-2" <% $locationnum == -2 ? 'SELECTED' : ''%>><% $opt{'optional_label'} || '(not required)' |h %>
40 % }
41
42 % foreach my $loc ( @{ $opt{cust_location} } ) {
43 %   # don't show the ship_location redundantly
44 %   next if $cust_main && $cust_main->ship_locationnum == $loc->locationnum;
45     <OPTION VALUE="<% $loc->locationnum %>"
46             <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
47     ><% $loc->line( cust_main      => $cust_main,
48                     countrydefault => $countrydefault,
49                   )
50      |h %>
51 % }
52
53 % if ( $addnew ) {
54     <OPTION VALUE="-1"
55             <% $locationnum == -1 ? 'SELECTED' : '' %>
56     >Add new location
57 % }
58
59 </SELECT>
60 % }
61 <%init>
62
63 my $conf = new FS::Conf;
64 my $countrydefault = $conf->config('countrydefault') || 'US';
65
66 my %opt = @_;
67 my $cust_main     = $opt{'cust_main'};
68 my $locationnum   = $opt{'curr_value'};
69
70 $opt{'cust_location'} ||= [ $cust_main ? $cust_main->cust_location : () ];
71
72 my $addnew = exists($opt{addnew}) ? $opt{addnew}
73                                   : $cust_main ? 1 : ( $locationnum>0 ? 0 : 1 );
74
75 </%init>