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