more mod_perl fixes, and bugfixes Peter Wemm sent via email
[freeside.git] / htdocs / misc / process / link.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: link.cgi,v 1.4 1999-02-07 09:59:35 ivan Exp $
4 #
5 # ivan@voicenet.com 97-feb-5
6 #
7 # rewrite ivan@sisd.com 98-mar-18
8 #
9 # Changes to allow page to work at a relative position in server
10 #       bmccane@maxbaud.net     98-apr-3
11 #
12 # can also link on some other fields now (about time) ivan@sisd.com 98-jun-24
13 #
14 # $Log: link.cgi,v $
15 # Revision 1.4  1999-02-07 09:59:35  ivan
16 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
17 #
18 # Revision 1.3  1999/01/19 05:14:10  ivan
19 # for mod_perl: no more top-level my() variables; use vars instead
20 # also the last s/create/new/;
21 #
22 # Revision 1.2  1998/12/17 09:15:00  ivan
23 # s/CGI::Request/CGI.pm/;
24 #
25
26 use strict;
27 use vars qw ( $cgi $old $new $error );
28 use CGI;
29 use CGI::Carp qw(fatalsToBrowser);
30 use FS::CGI qw(popurl idiot);
31 use FS::UID qw(cgisuidsetup);
32 use FS::cust_svc;
33 use FS::Record qw(qsearchs);
34
35 $cgi = new CGI;
36 cgisuidsetup($cgi);
37
38 $cgi->param('pkgnum') =~ /^(\d+)$/; my($pkgnum)=$1;
39 $cgi->param('svcpart') =~ /^(\d+)$/; my($svcpart)=$1;
40
41 $cgi->param('svcnum') =~ /^(\d*)$/; my($svcnum)=$1;
42 unless ( $svcnum ) {
43   my($part_svc) = qsearchs('part_svc',{'svcpart'=>$svcpart});
44   my($svcdb) = $part_svc->getfield('svcdb');
45   $cgi->param('link_field') =~ /^(\w+)$/; my($link_field)=$1;
46   my($svc_acct)=qsearchs($svcdb,{$link_field => $cgi->param('link_value') });
47   eidiot("$link_field not found!") unless $svc_acct;
48   $svcnum=$svc_acct->svcnum;
49 }
50
51 $old = qsearchs('cust_svc',{'svcnum'=>$svcnum});
52 die "svcnum not found!" unless $old;
53 $new = new FS::cust_svc ({
54   'svcnum' => $svcnum,
55   'pkgnum' => $pkgnum,
56   'svcpart' => $svcpart,
57 });
58
59 $error = $new->replace($old);
60
61 unless ($error) {
62   #no errors, so let's view this customer.
63   print $cgi->redirect(popurl(3). "view/cust_pkg.cgi?$pkgnum");
64 } else {
65   idiot($error);
66 }
67