eec43cf477b1aaa277fa04f7231418d2e3d559a7
[freeside.git] / htdocs / misc / process / link.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: link.cgi,v 1.5 1999-04-15 14:09:17 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.5  1999-04-15 14:09:17  ivan
16 # get rid of top-level my() variables
17 #
18 # Revision 1.4  1999/02/07 09:59:35  ivan
19 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
20 #
21 # Revision 1.3  1999/01/19 05:14:10  ivan
22 # for mod_perl: no more top-level my() variables; use vars instead
23 # also the last s/create/new/;
24 #
25 # Revision 1.2  1998/12/17 09:15:00  ivan
26 # s/CGI::Request/CGI.pm/;
27 #
28
29 use strict;
30 use vars qw ( $cgi $old $new $error $pkgnum $svcpart $svcnum );
31 use CGI;
32 use CGI::Carp qw(fatalsToBrowser);
33 use FS::CGI qw(popurl idiot);
34 use FS::UID qw(cgisuidsetup);
35 use FS::cust_svc;
36 use FS::Record qw(qsearchs);
37
38 $cgi = new CGI;
39 cgisuidsetup($cgi);
40
41 $cgi->param('pkgnum') =~ /^(\d+)$/;
42 $pkgnum = $1;
43 $cgi->param('svcpart') =~ /^(\d+)$/;
44 $svcpart = $1;
45 $cgi->param('svcnum') =~ /^(\d*)$/;
46 $svcnum = $1;
47
48 unless ( $svcnum ) {
49   my($part_svc) = qsearchs('part_svc',{'svcpart'=>$svcpart});
50   my($svcdb) = $part_svc->getfield('svcdb');
51   $cgi->param('link_field') =~ /^(\w+)$/; my($link_field)=$1;
52   my($svc_acct)=qsearchs($svcdb,{$link_field => $cgi->param('link_value') });
53   eidiot("$link_field not found!") unless $svc_acct;
54   $svcnum=$svc_acct->svcnum;
55 }
56
57 $old = qsearchs('cust_svc',{'svcnum'=>$svcnum});
58 die "svcnum not found!" unless $old;
59 $new = new FS::cust_svc ({
60   'svcnum' => $svcnum,
61   'pkgnum' => $pkgnum,
62   'svcpart' => $svcpart,
63 });
64
65 $error = $new->replace($old);
66
67 unless ($error) {
68   #no errors, so let's view this customer.
69   print $cgi->redirect(popurl(3). "view/cust_pkg.cgi?$pkgnum");
70 } else {
71   idiot($error);
72 }
73