remove
[freeside.git] / httemplate / edit / process / agent_type.cgi
1 <!-- $Id: agent_type.cgi,v 1.3 2002-01-30 14:18:08 ivan Exp $ -->
2 <%
3
4 my $typenum = $cgi->param('typenum');
5 my $old = qsearchs('agent_type',{'typenum'=>$typenum}) if $typenum;
6
7 my $new = new FS::agent_type ( {
8   map {
9     $_, scalar($cgi->param($_));
10   } fields('agent_type')
11 } );
12
13 my $error;
14 if ( $typenum ) {
15   $error=$new->replace($old);
16 } else {
17   $error=$new->insert;
18   $typenum=$new->getfield('typenum');
19 }
20
21 if ( $error ) {
22   $cgi->param('error', $error);
23   print $cgi->redirect(popurl(2). "agent_type.cgi?". $cgi->query_string );
24   exit;
25 }
26
27 foreach my $part_pkg (qsearch('part_pkg',{})) {
28   my($pkgpart)=$part_pkg->getfield('pkgpart');
29
30   my($type_pkgs)=qsearchs('type_pkgs',{
31       'typenum' => $typenum,
32       'pkgpart' => $pkgpart,
33   });
34   if ( $type_pkgs && ! $cgi->param("pkgpart$pkgpart") ) {
35     my($d_type_pkgs)=$type_pkgs; #need to save $type_pkgs for below.
36     $error=$d_type_pkgs->delete;
37     die $error if $error;
38
39   } elsif ( $cgi->param("pkgpart$pkgpart")
40             && ! $type_pkgs
41   ) {
42     #ok to clobber it now (but bad form nonetheless?)
43     $type_pkgs=new FS::type_pkgs ({
44       'typenum' => $typenum,
45       'pkgpart' => $pkgpart,
46     });
47     $error= $type_pkgs->insert;
48     die $error if $error;
49   }
50
51 }
52
53 print $cgi->redirect(popurl(3). "browse/agent_type.cgi");
54
55 %>