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