replace FS::CGI::header function with header-popup component, related to #71249
[freeside.git] / httemplate / misc / process / change_pkg_contact.html
1 <& /elements/header-popup.html, emt("Package contact $past_method") &>
2   <SCRIPT TYPE="text/javascript">
3     topreload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Change customer package');
11
12 #untaint pkgnum
13 my $pkgnum = $cgi->param('pkgnum');
14 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
15 $pkgnum = $1;
16
17 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} ); #needs agent virt
18
19 my $contactnum = $cgi->param('contactnum');
20 $contactnum =~ /^(-?\d*)$/ or die "Illegal contactnum";
21 $contactnum = $1;
22
23 my $past_method = $cust_pkg->contactnum ? 'changed' : 'added';
24
25 my $error = '';
26
27 if ( $contactnum == -1 ) {
28
29   #little false laziness w/edit/process/quick-cust_pkg.cgi, also the whole
30   # thing should be a single transaction
31   my $contact = new FS::contact {
32     'custnum' => $cust_pkg->custnum,
33     map { $_ => scalar($cgi->param("contactnum_$_")) } qw( first last )
34   };
35   $error = $contact->insert;
36   $cust_pkg->contactnum( $contact->contactnum );
37
38 } else {
39   $cust_pkg->contactnum($contactnum);
40 }
41
42 $error ||= $cust_pkg->replace;
43
44 if ($error) {
45   $cgi->param('error', $error);
46   print $cgi->redirect(popurl(2). "change_pkg_contact.html?". $cgi->query_string );
47 }
48
49 </%init>