summaryrefslogtreecommitdiff
path: root/httemplate/elements/input-date-field.html
blob: 182efbb93eb3f33223a580fd8a025401ba05240f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% if(!$noinit) {
<LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
% }

<INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% $value %>">
<IMG SRC="<%$fsurl%>images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="<% mt('Select date') |h %>">

<SCRIPT TYPE="text/javascript">
  Calendar.setup({
    inputField: "<% $name %>_text",
    ifFormat:   "<% $format %>",
    button:     "<% $name %>_button",
    align:      "BR"
  });
</SCRIPT>

<%init>

my($name, $value, $format, $usedatetime, $noinit);
if ( ref($_[0]) ) {
  my $opt = shift;
  $name        = $opt->{'name'};
  $value       = $opt->{'value'};
  $format      = $opt->{'format'};
  $usedatetime = $opt->{'usedatetime'};
  $noinit      = $opt->{'noinit'};
} else {
  ($name, $value, $format, $usedatetime) = @_;
}

my $conf = new FS::Conf;

$format ||= $conf->config('date_format') || '%m/%d/%Y';

if ( $value =~ /\S/ ) {
  if ( $usedatetime ) {
    my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating');
    $value = $dt->strftime($format);
  } elsif ( $value =~ /^\d+$/ ) {
    $value = time2str($format, $value);
  }
} else {
  $value = '';
}

</%init>