Initial revision
[freeside.git] / htdocs / browse / agent_type.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # agent_type.cgi: browse agent_type
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 use strict;
14 use CGI::Base;
15 use FS::UID qw(cgisuidsetup swapuid);
16 use FS::Record qw(qsearch qsearchs);
17 use FS::CGI qw(header menubar);
18
19 my($cgi) = new CGI::Base;
20 $cgi->get;
21
22 &cgisuidsetup($cgi);
23
24 SendHeaders(); # one guess.
25
26 print header("Agent Type Listing", menubar(
27   'Main Menu' => '../',
28   'Add new agent type' => "../edit/agent_type.cgi",
29 )), <<END;
30     <BR>Click on agent type number to edit.
31     <TABLE BORDER>
32       <TR>
33         <TH><FONT SIZE=-1>Type #</FONT></TH>
34         <TH>Type</TH>
35         <TH colspan="2">Packages</TH>
36       </TR>
37 END
38
39 my($agent_type);
40 foreach $agent_type ( sort { 
41   $a->getfield('typenum') <=> $b->getfield('typenum')
42 } qsearch('agent_type',{}) ) {
43   my($hashref)=$agent_type->hashref;
44   my(@type_pkgs)=qsearch('type_pkgs',{'typenum'=> $hashref->{typenum} });
45   my($rowspan)=scalar(@type_pkgs);
46   $rowspan = int($rowspan/2+0.5) ;
47   print <<END;
48       <TR>
49         <TD ROWSPAN=$rowspan><A HREF="../edit/agent_type.cgi?$hashref->{typenum}">
50           $hashref->{typenum}
51         </A></TD>
52         <TD ROWSPAN=$rowspan>$hashref->{atype}</TD>
53 END
54
55   my($type_pkgs);
56   my($tdcount) = -1 ;
57   foreach $type_pkgs ( @type_pkgs ) {
58     my($pkgpart)=$type_pkgs->getfield('pkgpart');
59     my($part_pkg) = qsearchs('part_pkg',{'pkgpart'=> $pkgpart });
60     print qq!<TR>! if ($tdcount == 0) ;
61     $tdcount = 0 if ($tdcount == -1) ;
62     print qq!<TD><A HREF="../edit/part_pkg.cgi?$pkgpart">!,
63           $part_pkg->getfield('pkg'),"</A></TD>";
64     $tdcount ++ ;
65     if ($tdcount == 2)
66     {
67         print qq!</TR>\n! ;
68         $tdcount = 0 ;
69     }
70   }
71
72   print "</TR>";
73 }
74
75 print <<END;
76     </TR></TABLE>
77     </CENTER>
78   </BODY>
79 </HTML>
80 END
81