no more exit() in templates
[freeside.git] / httemplate / edit / process / agent_type.cgi
1 <!-- $Id: agent_type.cgi,v 1.4 2002-02-09 18:24:01 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 } else {
25
26   foreach my $part_pkg (qsearch('part_pkg',{})) {
27     my($pkgpart)=$part_pkg->getfield('pkgpart');
28
29     my($type_pkgs)=qsearchs('type_pkgs',{
30         'typenum' => $typenum,
31         'pkgpart' => $pkgpart,
32     });
33     if ( $type_pkgs && ! $cgi->param("pkgpart$pkgpart") ) {
34       my($d_type_pkgs)=$type_pkgs; #need to save $type_pkgs for below.
35       $error=$d_type_pkgs->delete;
36       die $error if $error;
37
38     } elsif ( $cgi->param("pkgpart$pkgpart")
39               && ! $type_pkgs
40     ) {
41       #ok to clobber it now (but bad form nonetheless?)
42       $type_pkgs=new FS::type_pkgs ({
43         'typenum' => $typenum,
44         'pkgpart' => $pkgpart,
45       });
46       $error= $type_pkgs->insert;
47       die $error if $error;
48     }
49
50   }
51
52   print $cgi->redirect(popurl(3). "browse/agent_type.cgi");
53 }
54
55 %>