2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/order_pkg.html?'. $cgi->query_string ) %>
5 % my $frag = "cust_pkg". $cust_pkg->pkgnum;
6 % my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
9 <% header('Package ordered') %>
10 <SCRIPT TYPE="text/javascript">
11 // XXX fancy ajax rebuild table at some point, but a page reload will do for now
13 // XXX chop off trailing #target and replace... ?
14 window.top.location = '<% popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" %>';
22 my $curuser = $FS::CurrentUser::CurrentUser;
25 unless $curuser->access_right('Order customer package');
27 #untaint custnum (probably not necessary, searching for it is escape enough)
28 $cgi->param('custnum') =~ /^(\d+)$/
29 or die 'illegal custnum '. $cgi->param('custnum');
31 my $cust_main = qsearchs({
32 'table' => 'cust_main',
33 'hashref' => { 'custnum' => $custnum },
34 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
36 die 'unknown custnum' unless $cust_main;
38 #probably not necessary, taken care of by cust_pkg::check
39 $cgi->param('pkgpart') =~ /^(\d+)$/
40 or die 'illegal pkgpart '. $cgi->param('pkgpart');
42 $cgi->param('refnum') =~ /^(\d*)$/
43 or die 'illegal refnum '. $cgi->param('refnum');
45 $cgi->param('locationnum') =~ /^(\-?\d*)$/
46 or die 'illegal locationnum '. $cgi->param('locationnum');
48 $cgi->param('discountnum') =~ /^(\-?\d*)$/
49 or die 'illegal discountnum '. $cgi->param('discountnum');
53 my $cust_pkg = new FS::cust_pkg {
54 'custnum' => $custnum,
55 'pkgpart' => $pkgpart,
56 'start_date' => ( scalar($cgi->param('start_date'))
57 ? str2time($cgi->param('start_date'))
61 'locationnum' => $locationnum,
62 'discountnum' => $discountnum,
63 #for the create a new discount case
64 'discountnum__type' => scalar($cgi->param('discountnum__type')),
65 'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
66 'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
67 'discountnum_months' => scalar($cgi->param('discountnum_months')),
68 #'discountnum_disabled' => scalar($cgi->param('discountnum_disabled')),
71 my %opt = ( 'cust_pkg' => $cust_pkg );
73 if ( $locationnum == -1 ) {
74 my $cust_location = new FS::cust_location {
75 map { $_ => scalar($cgi->param($_)) }
76 qw( custnum address1 address2 city county state zip country )
78 $opt{'cust_location'} = $cust_location;
81 my $error = $cust_main->order_pkg( %opt );