b9fff4530fa1201cfe5bf8f64614092ff920f6cd
[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 use strict;
14 use CGI::Base;
15 use CGI::Carp qw(fatalsToBrowser);
16 use FS::UID qw(cgisuidsetup);
17 use FS::Record qw(qsearch qsearchs);
18 use FS::agent_type;
19 use FS::CGI qw(header menubar);
20
21 my($cgi) = new CGI::Base;
22 $cgi->get;
23
24 &cgisuidsetup($cgi);
25
26 SendHeaders(); # one guess.
27
28 my($agent_type,$action);
29 if ( $cgi->var('QUERY_STRING') =~ /^(\d+)$/ ) { #editing
30   $agent_type=qsearchs('agent_type',{'typenum'=>$1});
31   $action='Edit';
32 } else { #adding
33   $agent_type=create FS::agent_type {};
34   $action='Add';
35 }
36 my($hashref)=$agent_type->hashref;
37
38 print header("$action Agent Type", menubar(
39   'Main Menu' => '../',
40   'View all agent types' => '../browse/agent_type.cgi',
41 )), '<FORM ACTION="process/agent_type.cgi" METHOD=POST>';
42
43 print qq!<INPUT TYPE="hidden" NAME="typenum" VALUE="$hashref->{typenum}">!,
44       "Agent Type #", $hashref->{typenum} ? $hashref->{typenum} : "(NEW)";
45
46 print <<END;
47 <BR>Type <INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="$hashref->{atype}">
48 <P>Select which packages agents of this type may sell to customers</P>
49 END
50
51 my($part_pkg);
52 foreach $part_pkg ( qsearch('part_pkg',{}) ) {
53   print qq!<BR><INPUT TYPE="checkbox" NAME="pkgpart!,
54         $part_pkg->getfield('pkgpart'), qq!" !,
55        # ( 'CHECKED 'x scalar(
56         qsearchs('type_pkgs',{
57           'typenum' => $agent_type->getfield('typenum'),
58           'pkgpart'  => $part_pkg->getfield('pkgpart'),
59         })
60           ? 'CHECKED '
61           : '',
62         qq!"VALUE="ON"> !,$part_pkg->getfield('pkg')
63   ;
64 }
65
66 print qq!<BR><INPUT TYPE="submit" VALUE="!,
67       $hashref->{typenum} ? "Apply changes" : "Add agent type",
68       qq!">!;
69
70 print <<END;
71     </FORM>
72   </BODY>
73 </HTML>
74 END
75