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