customer edit: abstract out billing info to billing.html, re-do payment type selectio...
[freeside.git] / httemplate / elements / select-month_year.html
diff --git a/httemplate/elements/select-month_year.html b/httemplate/elements/select-month_year.html
new file mode 100644 (file)
index 0000000..a0ea74d
--- /dev/null
@@ -0,0 +1,50 @@
+<%
+
+  my %opt = @_;
+
+  my $prefix = $opt{'prefix'} || '';
+  my $disabled = $opt{'disabled'} || '';
+  my $empty = $opt{'empty_option'} || '';
+  my $date = $opt{'selected_date'} || '';
+  $date = '' if $date eq '-';
+  #$date ||= '01-2000' unless $empty;
+  my $start_year = $opt{'start_year'};
+  my $end_year = $opt{'end_year'} || '2037';
+
+  my( $mon, $year ) = (0, 0);
+  if ( $date ) {
+    if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
+      ( $mon, $year ) = ( $2, $1 );
+    } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
+      ( $mon, $year ) = ( $1, $3 );
+    } else {
+      die "unrecognized expiration date format: $date";
+    }
+  }
+
+  unless ( $start_year ) {
+    my @t = localtime;
+    $start_year = $t[5] + 1900;
+  }
+  $start_year = $year if $start_year > $year && $year > 0;
+
+%>
+
+<SELECT NAME="<%= $prefix %>_month" SIZE="1" <%= $disabled%>>
+
+<%= $empty ? '<OPTION VALUE="">' : '' %>
+
+<% for ( 1 .. 12 ) { %>
+   <OPTION<%= $_ == $mon ? ' SELECTED' : '' %> VALUE="<%= $_ %>"><%= $_ %>
+<% } %>
+
+</SELECT>/<SELECT NAME="<%= $prefix %>_year" SIZE="1" <%= $disabled%>>
+
+<%= $empty ? '<OPTION VALUE="">' : '' %>
+
+<% for ( $start_year .. $end_year ) { %>
+   <OPTION<%= $_ == $year ? ' SELECTED' : '' %> VALUE="<%= $_ %>"><%= $_ %>
+<% } %>
+
+</SELECT>
+