ac41eec5c0fa94b9264b11b2e75d67f07902dd41
[freeside.git] / httemplate / edit / agent_type.cgi
1 <%
2 #<!-- $Id: agent_type.cgi,v 1.3 2001-09-04 15:06:03 ivan Exp $ -->
3
4 use strict;
5 use vars qw( $cgi $agent_type $action $hashref $p $part_pkg );
6 use CGI;
7 use CGI::Carp qw(fatalsToBrowser);
8 use FS::UID qw(cgisuidsetup);
9 use FS::Record qw(qsearch qsearchs fields);
10 use FS::agent_type;
11 use FS::CGI qw(header menubar popurl);
12 use FS::agent_type;
13 use FS::part_pkg;
14 use FS::type_pkgs;
15
16 $cgi = new CGI;
17
18 &cgisuidsetup($cgi);
19
20 if ( $cgi->param('error') ) {
21   $agent_type = new FS::agent_type ( {
22     map { $_, scalar($cgi->param($_)) } fields('agent')
23   } );
24 } elsif ( $cgi->keywords ) { #editing
25   my( $query ) = $cgi->keywords;
26   $query =~ /^(\d+)$/;
27   $agent_type=qsearchs('agent_type',{'typenum'=>$1});
28 } else { #adding
29   $agent_type = new FS::agent_type {};
30 }
31 $action = $agent_type->typenum ? 'Edit' : 'Add';
32 $hashref = $agent_type->hashref;
33
34 $p = popurl(2);
35 print $cgi->header( '-expires' => 'now' ), header("$action Agent Type", menubar(
36   'Main Menu' => "$p",
37   'View all agent types' => "${p}browse/agent_type.cgi",
38 ));
39
40 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
41       "</FONT>"
42   if $cgi->param('error');
43
44 print '<FORM ACTION="', popurl(1), 'process/agent_type.cgi" METHOD=POST>',
45       qq!<INPUT TYPE="hidden" NAME="typenum" VALUE="$hashref->{typenum}">!,
46       "Agent Type #", $hashref->{typenum} ? $hashref->{typenum} : "(NEW)";
47
48 print <<END;
49 <BR><BR>Agent Type <INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="$hashref->{atype}">
50 <BR><BR>Select which packages agents of this type may sell to customers<BR>
51 END
52
53 foreach $part_pkg ( qsearch('part_pkg',{}) ) {
54   print qq!<BR><INPUT TYPE="checkbox" NAME="pkgpart!,
55         $part_pkg->getfield('pkgpart'), qq!" !,
56        # ( 'CHECKED 'x scalar(
57         qsearchs('type_pkgs',{
58           'typenum' => $agent_type->getfield('typenum'),
59           'pkgpart'  => $part_pkg->getfield('pkgpart'),
60         })
61           ? 'CHECKED '
62           : '',
63         qq!VALUE="ON"> !,
64     qq!<A HREF="${p}edit/part_pkg.cgi?!, $part_pkg->pkgpart, 
65     '">', $part_pkg->getfield('pkg'), '</A>',
66   ;
67 }
68
69 print qq!<BR><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
79 %>