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