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