9d8687299cd75b217f5db76ac9af615c01a941dd
[freeside.git] / htdocs / browse / agent_type.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: agent_type.cgi,v 1.8 1999-04-09 04:22:34 ivan Exp $
4 #
5 # ivan@sisd.com 97-dec-10
6 #
7 # Changes to allow page to work at a relative position in server
8 # Changes to make "Packages" display 2-wide in table (old way was too vertical)
9 #       bmccane@maxbaud.net 98-apr-3
10 #
11 # lose background, FS::CGI ivan@sisd.com 98-sep-2
12 #
13 # $Log: agent_type.cgi,v $
14 # Revision 1.8  1999-04-09 04:22:34  ivan
15 # also table()
16 #
17 # Revision 1.7  1999/04/09 03:52:55  ivan
18 # explicit & for table/itable/ntable
19 #
20 # Revision 1.6  1999/04/07 11:10:46  ivan
21 # harmless typo
22 #
23 # Revision 1.5  1999/01/19 05:13:25  ivan
24 # for mod_perl: no more top-level my() variables; use vars instead
25 # also the last s/create/new/;
26 #
27 # Revision 1.4  1999/01/18 09:41:15  ivan
28 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
29 # (good idea anyway)
30 #
31 # Revision 1.3  1998/12/17 05:25:17  ivan
32 # fix visual and other bugs
33 #
34 # Revision 1.2  1998/11/21 07:39:52  ivan
35 # visual
36 #
37
38 use strict;
39 use vars qw( $cgi $p $agent_type );
40 use CGI;
41 use CGI::Carp qw(fatalsToBrowser);
42 use FS::UID qw(cgisuidsetup swapuid);
43 use FS::Record qw(qsearch qsearchs);
44 use FS::CGI qw(header menubar popurl table);
45 use FS::agent_type;
46 use FS::type_pkgs;
47 use FS::part_pkg;
48
49 $cgi = new CGI;
50
51 &cgisuidsetup($cgi);
52
53 $p = popurl(2);
54 print $cgi->header( '-expires' => 'now' ), header("Agent Type Listing", menubar(
55   'Main Menu' => $p,
56 )), "Agent types define groups of packages that you can then assign to".
57     " particular agents.<BR><BR>", &table(), <<END;
58       <TR>
59         <TH COLSPAN=2>Agent Type</TH>
60         <TH COLSPAN="2">Packages</TH>
61       </TR>
62 END
63
64 foreach $agent_type ( sort { 
65   $a->getfield('typenum') <=> $b->getfield('typenum')
66 } qsearch('agent_type',{}) ) {
67   my($hashref)=$agent_type->hashref;
68   my(@type_pkgs)=qsearch('type_pkgs',{'typenum'=> $hashref->{typenum} });
69   my($rowspan)=scalar(@type_pkgs);
70   $rowspan = int($rowspan/2+0.5) ;
71   print <<END;
72       <TR>
73         <TD ROWSPAN=$rowspan><A HREF="${p}edit/agent_type.cgi?$hashref->{typenum}">
74           $hashref->{typenum}
75         </A></TD>
76         <TD ROWSPAN=$rowspan><A HREF="${p}edit/agent_type.cgi?$hashref->{typenum}">$hashref->{atype}</A></TD>
77 END
78
79   my($type_pkgs);
80   my($tdcount) = -1 ;
81   foreach $type_pkgs ( @type_pkgs ) {
82     my($pkgpart)=$type_pkgs->getfield('pkgpart');
83     my($part_pkg) = qsearchs('part_pkg',{'pkgpart'=> $pkgpart });
84     print qq!<TR>! if ($tdcount == 0) ;
85     $tdcount = 0 if ($tdcount == -1) ;
86     print qq!<TD><A HREF="${p}edit/part_pkg.cgi?$pkgpart">!,
87           $part_pkg->getfield('pkg'),"</A></TD>";
88     $tdcount ++ ;
89     if ($tdcount == 2)
90     {
91         print qq!</TR>\n! ;
92         $tdcount = 0 ;
93     }
94   }
95
96   print "</TR>";
97 }
98
99 print <<END;
100   <TR><TD COLSPAN=2><I><A HREF="${p}edit/agent_type.cgi">Add new agent type</A></I></TD></TR>
101     </TABLE>
102   </BODY>
103 </HTML>
104 END
105