finish up initial work on customer view tabs (ensure links back to customer view...
[freeside.git] / httemplate / edit / process / REAL_cust_pkg.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "REAL_cust_pkg.cgi?". $cgi->query_string ) %>
4 %} else { 
5 %  my $custnum = $new->custnum;
6 %  my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
7 %               ? ''
8 %               : ';show=packages';
9 %  my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
10 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" ) %>
11 %}
12 <%init>
13
14 my $curuser = $FS::CurrentUser::CurrentUser;
15
16 die "access denied"
17   unless $curuser->access_right('Edit customer package dates');
18
19 my $pkgnum = $cgi->param('pkgnum') or die;
20 my $old = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
21 my %hash = $old->hash;
22 $hash{'setup'} = $cgi->param('setup') ? str2time($cgi->param('setup')) : '';
23 $hash{'bill'} = $cgi->param('bill') ? str2time($cgi->param('bill')) : '';
24 $hash{'last_bill'} =
25   $cgi->param('last_bill') ? str2time($cgi->param('last_bill')) : '';
26 $hash{'adjourn'} = $cgi->param('adjourn') ? str2time($cgi->param('adjourn')) : '';
27 $hash{'expire'} = $cgi->param('expire') ? str2time($cgi->param('expire')) : '';
28
29 my $new;
30 my $error;
31 if ( $hash{'bill'} != $old->bill        # if the next bill date was changed
32      && $hash{'bill'} < time            # to a date in the past
33      && ! $cgi->param('bill_areyousure') # and it wasn't confirmed
34    )
35 {
36   $error = '_bill_areyousure';
37 } else {
38   $new = new FS::cust_pkg \%hash;
39   $error = $new->replace($old);
40 }
41
42 </%init>