bugfixes; fields isn't exported by derived classes
[freeside.git] / htdocs / edit / process / agent_type.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: agent_type.cgi,v 1.4 1998-12-30 23:03:27 ivan Exp $
4 #
5 # ivan@sisd.com 97-dec-11
6 #
7 # Changes to allow page to work at a relative position in server
8 #       bmccane@maxbaud.net     98-apr-3
9 #
10 # lose background, FS::CGI ivan@sisd.com 98-sep-2
11 #
12 # $Log: agent_type.cgi,v $
13 # Revision 1.4  1998-12-30 23:03:27  ivan
14 # bugfixes; fields isn't exported by derived classes
15 #
16 # Revision 1.3  1998/12/17 08:40:17  ivan
17 # s/CGI::Request/CGI.pm/; etc
18 #
19 # Revision 1.2  1998/11/21 07:49:20  ivan
20 # s/CGI::Request/CGI.pm/
21 #
22
23 use strict;
24 use CGI;
25 use CGI::Carp qw(fatalsToBrowser);
26 use FS::CGI qw(idiot popurl);
27 use FS::UID qw(cgisuidsetup);
28 use FS::Record qw(qsearch qsearchs fields);
29 use FS::agent_type;
30 use FS::type_pkgs;
31 use FS::part_pkg;
32
33 my($cgi)=new CGI;
34 &cgisuidsetup($cgi);
35
36 my($typenum)=$cgi->param('typenum');
37 my($old)=qsearchs('agent_type',{'typenum'=>$typenum}) if $typenum;
38
39 my($new)=create FS::agent_type ( {
40   map {
41     $_, scalar($cgi->param($_));
42   } fields('agent_type')
43 } );
44
45 my($error);
46 if ( $typenum ) {
47   $error=$new->replace($old);
48 } else {
49   $error=$new->insert;
50   $typenum=$new->getfield('typenum');
51 }
52
53 if ( $error ) {
54   idiot($error);
55   exit;
56 }
57
58 my($part_pkg);
59 foreach $part_pkg (qsearch('part_pkg',{})) {
60   my($pkgpart)=$part_pkg->getfield('pkgpart');
61
62   my($type_pkgs)=qsearchs('type_pkgs',{
63       'typenum' => $typenum,
64       'pkgpart' => $pkgpart,
65   });
66   if ( $type_pkgs && ! $cgi->param("pkgpart$pkgpart") ) {
67     my($d_type_pkgs)=$type_pkgs; #need to save $type_pkgs for below.
68     $error=$d_type_pkgs->delete;
69     if ( $error ) {
70       idiot($error);
71       exit;
72     }
73
74   } elsif ( $cgi->param("pkgpart$pkgpart")
75             && ! $type_pkgs
76   ) {
77     #ok to clobber it now (but bad form nonetheless?)
78     $type_pkgs=create FS::type_pkgs ({
79       'typenum' => $typenum,
80       'pkgpart' => $pkgpart,
81     });
82     $error= $type_pkgs->insert;
83     if ( $error ) {
84       idiot($error);
85       exit;
86     }
87   }
88
89 }
90
91 print $cgi->redirect(popurl(3). "browse/agent_type.cgi");
92