Will things ever be the same again?
[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 %#$error  ||= $new->process_m2m( );
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 %  my $error = $new->process_m2m(
27 %    'link_table'   => 'type_pkgs',
28 %    'target_table' => 'part_pkg',
29 %    'params'       => scalar($cgi->Vars)
30 %  );
31 %  die $error if $error;
32 %
33 %  print $cgi->redirect(popurl(3). "browse/agent_type.cgi");
34 %}
35 %
36 %
37