This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / edit / process / quick-cust_pkg.cgi
1 %if ($error) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/order_pkg.html?'. $cgi->query_string ) %>
4 %} else {
5 %  my $frag = "cust_pkg". $cust_pkg->pkgnum;
6 %  my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
7 %               ? ''
8 %               : ';show=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
12
13     // XXX chop off trailing #target and replace... ?
14     window.top.location = '<% popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" %>';
15
16   </SCRIPT>
17
18   </BODY></HTML>
19 %}
20 <%init>
21
22 my $curuser = $FS::CurrentUser::CurrentUser;
23
24 die "access denied"
25   unless $curuser->access_right('Order customer package');
26
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');
30 my $custnum = $1;
31 my $cust_main = qsearchs({
32   'table'     => 'cust_main',
33   'hashref'   => { 'custnum' => $custnum },
34   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
35 });
36 die 'unknown custnum' unless $cust_main;
37
38 #probably not necessary, taken care of by cust_pkg::check
39 $cgi->param('pkgpart') =~ /^(\d+)$/
40   or die 'illegal pkgpart '. $cgi->param('pkgpart');
41 my $pkgpart = $1;
42 $cgi->param('refnum') =~ /^(\d*)$/
43   or die 'illegal refnum '. $cgi->param('refnum');
44 my $refnum = $1;
45 $cgi->param('locationnum') =~ /^(\-?\d*)$/
46   or die 'illegal locationnum '. $cgi->param('locationnum');
47 my $locationnum = $1;
48
49 my $cust_pkg = new FS::cust_pkg {
50   'custnum'     => $custnum,
51   'pkgpart'     => $pkgpart,
52   'start_date'  => ( scalar($cgi->param('start_date'))
53                        ? str2time($cgi->param('start_date'))
54                        : ''
55                    ),
56   'refnum'      => $refnum,
57   'locationnum' => $locationnum,
58 };
59
60 my %opt = ( 'cust_pkg' => $cust_pkg );
61
62 if ( $locationnum == -1 ) {
63   my $cust_location = new FS::cust_location {
64     map { $_ => scalar($cgi->param($_)) }
65         qw( custnum address1 address2 city county state zip country )
66   };
67   $opt{'cust_location'} = $cust_location;
68 }
69
70 my $error = $cust_main->order_pkg( %opt );
71
72 </%init>