yet more mod_perl stuff
[freeside.git] / htdocs / edit / agent_type.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: agent_type.cgi,v 1.10 1999-01-25 12:09:51 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.10  1999-01-25 12:09:51  ivan
17 # yet more mod_perl stuff
18 #
19 # Revision 1.9  1999/01/19 05:13:32  ivan
20 # for mod_perl: no more top-level my() variables; use vars instead
21 # also the last s/create/new/;
22 #
23 # Revision 1.8  1999/01/18 09:41:22  ivan
24 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
25 # (good idea anyway)
26 #
27 # Revision 1.7  1999/01/18 09:22:29  ivan
28 # changes to track email addresses for email invoicing
29 #
30 # Revision 1.6  1998/12/17 06:16:58  ivan
31 # fix double // in relative URLs, s/CGI::Base/CGI/;
32 #
33 # Revision 1.5  1998/11/21 07:58:27  ivan
34 # package names link to them
35 #
36 # Revision 1.4  1998/11/21 07:45:19  ivan
37 # visual, use FS::table_name when doing qsearch('table_name')
38 #
39 # Revision 1.3  1998/11/15 11:20:12  ivan
40 # s/CGI-Base/CGI.pm/ causes s/QUERY_STRING/keywords/;
41 #
42 # Revision 1.2  1998/11/13 09:56:46  ivan
43 # change configuration file layout to support multiple distinct databases (with
44 # own set of config files, export, etc.)
45 #
46
47 use strict;
48 use vars qw( $cgi $agent_type $action $hashref $p $part_pkg );
49 use CGI;
50 use CGI::Carp qw(fatalsToBrowser);
51 use FS::UID qw(cgisuidsetup);
52 use FS::Record qw(qsearch qsearchs fields);
53 use FS::agent_type;
54 use FS::CGI qw(header menubar popurl);
55 use FS::agent_type;
56 use FS::part_pkg;
57 use FS::type_pkgs;
58
59 $cgi = new CGI;
60
61 &cgisuidsetup($cgi);
62
63 if ( $cgi->param('error') ) {
64   $agent_type = new FS::agent_type ( {
65     map { $_, scalar($cgi->param($_)) } fields('agent')
66   } );
67 } elsif ( $cgi->keywords ) { #editing
68   my( $query ) = $cgi->keywords;
69   $query =~ /^(\d+)$/;
70   $agent_type=qsearchs('agent_type',{'typenum'=>$1});
71 } else { #adding
72   $agent_type = new FS::agent_type {};
73 }
74 $action = $agent_type->typenum ? 'Edit' : 'Add';
75 $hashref = $agent_type->hashref;
76
77 $p = popurl(2);
78 print $cgi->header( '-expires' => 'now' ), header("$action Agent Type", menubar(
79   'Main Menu' => "$p",
80   'View all agent types' => "${p}browse/agent_type.cgi",
81 ));
82
83 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
84       "</FONT>"
85   if $cgi->param('error');
86
87 print '<FORM ACTION="', popurl(1), 'process/agent_type.cgi" METHOD=POST>',
88       qq!<INPUT TYPE="hidden" NAME="typenum" VALUE="$hashref->{typenum}">!,
89       "Agent Type #", $hashref->{typenum} ? $hashref->{typenum} : "(NEW)";
90
91 print <<END;
92 <BR><BR>Agent Type <INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="$hashref->{atype}">
93 <BR><BR>Select which packages agents of this type may sell to customers<BR>
94 END
95
96 foreach $part_pkg ( qsearch('part_pkg',{}) ) {
97   print qq!<BR><INPUT TYPE="checkbox" NAME="pkgpart!,
98         $part_pkg->getfield('pkgpart'), qq!" !,
99        # ( 'CHECKED 'x scalar(
100         qsearchs('type_pkgs',{
101           'typenum' => $agent_type->getfield('typenum'),
102           'pkgpart'  => $part_pkg->getfield('pkgpart'),
103         })
104           ? 'CHECKED '
105           : '',
106         qq!"VALUE="ON"> !,
107     qq!<A HREF="${p}edit/part_pkg.cgi?!, $part_pkg->pkgpart, 
108     '">', $part_pkg->getfield('pkg'), '</A>',
109   ;
110 }
111
112 print qq!<BR><INPUT TYPE="submit" VALUE="!,
113       $hashref->{typenum} ? "Apply changes" : "Add agent type",
114       qq!">!;
115
116 print <<END;
117     </FORM>
118   </BODY>
119 </HTML>
120 END
121