fix "multiple states" links, RT#13922
[freeside.git] / httemplate / elements / tr-input-date-field.html
1 % unless ( $noinit ) {
2 <LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
3 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
4 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
5 <SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
6 % }
7
8 <TR>
9   <TD ALIGN="right"><% $label %></TD>
10   <TD>
11     <INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% $value %>">
12     <IMG SRC="<%$fsurl%>images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="<% mt('Select date') |h %>">
13   </TD>
14 </TR>
15
16 <SCRIPT TYPE="text/javascript">
17   Calendar.setup({
18     inputField: "<% $name %>_text",
19     ifFormat:   "<% $format %>",
20     button:     "<% $name %>_button",
21     align:      "BR"
22   });
23 </SCRIPT>
24
25 <%init>
26
27 my($name, $value, $label, $format, $usedatetime, $noinit);
28 if ( ref($_[0]) ) {
29   my $opt = shift;
30   $name        = $opt->{'name'};
31   $value       = $opt->{'value'};
32   $label       = $opt->{'label'};
33   $format      = $opt->{'format'};
34   $usedatetime = $opt->{'usedatetime'};
35   $noinit      = $opt->{'noinit'};
36 } else {
37   ($name, $value, $label, $format, $usedatetime) = @_;
38 }
39
40 my $conf = new FS::Conf;
41
42 $format ||= $conf->config('date_format') || '%m/%d/%Y';
43
44 $label = $name unless $label;
45
46 if ( $value =~ /\S/ ) {
47   if ( $usedatetime ) {
48     my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating');
49     $value = $dt->strftime($format);
50   } elsif ( $value =~ /^\d+$/ ) {
51     $value = time2str($format, $value);
52   }
53 } else {
54   $value = '';
55 }
56
57 </%init>
58