bugfix to work for regular aswell as custom pricing
[freeside.git] / htdocs / edit / agent_type.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: agent_type.cgi,v 1.3 1998-11-15 11:20:12 ivan Exp $
4 #
5 # agent_type.cgi: Add/Edit agent type (output form)
6 #
7 # ivan@sisd.com 97-dec-10
8 #
9 # Changes to allow page to work at a relative position in server
10 # Changed 'type' to 'atype' because Pg6.3 reserves the type word
11 #       bmccane@maxbaud.net     98-apr-3
12 #
13 # use FS::CGI, added inline documentation ivan@sisd.com 98-jul-12
14 #
15 # $Log: agent_type.cgi,v $
16 # Revision 1.3  1998-11-15 11:20:12  ivan
17 # s/CGI-Base/CGI.pm/ causes s/QUERY_STRING/keywords/;
18 #
19 # Revision 1.2  1998/11/13 09:56:46  ivan
20 # change configuration file layout to support multiple distinct databases (with
21 # own set of config files, export, etc.)
22 #
23
24 use strict;
25 use CGI;
26 use CGI::Carp qw(fatalsToBrowser);
27 use FS::UID qw(cgisuidsetup);
28 use FS::Record qw(qsearch qsearchs);
29 use FS::agent_type;
30 use FS::CGI qw(header menubar);
31
32 my($cgi) = new CGI;
33
34 &cgisuidsetup($cgi);
35
36 my($agent_type,$action);
37 if ( $cgi->keywords =~ /^(\d+)$/ ) { #editing
38   $agent_type=qsearchs('agent_type',{'typenum'=>$1});
39   $action='Edit';
40 } else { #adding
41   $agent_type=create FS::agent_type {};
42   $action='Add';
43 }
44 my($hashref)=$agent_type->hashref;
45
46 print $cgi->header, header("$action Agent Type", menubar(
47   'Main Menu' => '../',
48   'View all agent types' => '../browse/agent_type.cgi',
49 )), '<FORM ACTION="process/agent_type.cgi" METHOD=POST>';
50
51 print qq!<INPUT TYPE="hidden" NAME="typenum" VALUE="$hashref->{typenum}">!,
52       "Agent Type #", $hashref->{typenum} ? $hashref->{typenum} : "(NEW)";
53
54 print <<END;
55 <BR>Type <INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="$hashref->{atype}">
56 <P>Select which packages agents of this type may sell to customers</P>
57 END
58
59 my($part_pkg);
60 foreach $part_pkg ( qsearch('part_pkg',{}) ) {
61   print qq!<BR><INPUT TYPE="checkbox" NAME="pkgpart!,
62         $part_pkg->getfield('pkgpart'), qq!" !,
63        # ( 'CHECKED 'x scalar(
64         qsearchs('type_pkgs',{
65           'typenum' => $agent_type->getfield('typenum'),
66           'pkgpart'  => $part_pkg->getfield('pkgpart'),
67         })
68           ? 'CHECKED '
69           : '',
70         qq!"VALUE="ON"> !,$part_pkg->getfield('pkg')
71   ;
72 }
73
74 print qq!<BR><INPUT TYPE="submit" VALUE="!,
75       $hashref->{typenum} ? "Apply changes" : "Add agent type",
76       qq!">!;
77
78 print <<END;
79     </FORM>
80   </BODY>
81 </HTML>
82 END
83