stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / browse / agent_type.cgi
index 9d51a37..0c011ce 100755 (executable)
-<%
-#
-# $Id: agent_type.cgi,v 1.1 2001-07-30 07:36:03 ivan Exp $
-#
-# ivan@sisd.com 97-dec-10
-#
-# Changes to allow page to work at a relative position in server
-# Changes to make "Packages" display 2-wide in table (old way was too vertical)
-#      bmccane@maxbaud.net 98-apr-3
-#
-# lose background, FS::CGI ivan@sisd.com 98-sep-2
-#
-# $Log: agent_type.cgi,v $
-# Revision 1.1  2001-07-30 07:36:03  ivan
-# templates!!!
-#
-# Revision 1.8  1999/04/09 04:22:34  ivan
-# also table()
-#
-# Revision 1.7  1999/04/09 03:52:55  ivan
-# explicit & for table/itable/ntable
-#
-# Revision 1.6  1999/04/07 11:10:46  ivan
-# harmless typo
-#
-# Revision 1.5  1999/01/19 05:13:25  ivan
-# for mod_perl: no more top-level my() variables; use vars instead
-# also the last s/create/new/;
-#
-# Revision 1.4  1999/01/18 09:41:15  ivan
-# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
-# (good idea anyway)
-#
-# Revision 1.3  1998/12/17 05:25:17  ivan
-# fix visual and other bugs
-#
-# Revision 1.2  1998/11/21 07:39:52  ivan
-# visual
-#
+<& elements/browse.html,
+     'title'              => 'Agent Types',
+     'menubar'            => [ 'Agents' => "${p}browse/agent.cgi" ],
+     'html_init'          => $html_init,
+     'name'               => 'agent types',
+     'disableable'        => 1,
+     'disabled_statuspos' => 2,
+     'query'              => { 'table'     => 'agent_type',
+                               'hashref'   => {},
+                               'order_by' => 'ORDER BY typenum', # atype?
+                             },
+     'count_query'        => $count_query,
+     'header'             => [ '#',
+                               'Agent Type',
+                               'Packages',
+                             ],
+     'fields'             => [ 'typenum',
+                               'atype',
+                               $packages_sub,
+                             ],
+     'links'              => [ $link,
+                               $link,
+                               '',
+                             ],
+&>
+<%init>
 
-use strict;
-use vars qw( $cgi $p $agent_type );
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(cgisuidsetup swapuid);
-use FS::Record qw(qsearch qsearchs);
-use FS::CGI qw(header menubar popurl table);
-use FS::agent_type;
-use FS::type_pkgs;
-use FS::part_pkg;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-$cgi = new CGI;
+my $html_init = 
+'Agent types define groups of packages that you can then assign to'.
+' particular agents.<BR><BR>'.
+qq!<A HREF="${p}edit/agent_type.cgi"><I>Add a new agent type</I></A><BR><BR>!;
 
-&cgisuidsetup($cgi);
+my $count_query = 'SELECT COUNT(*) FROM agent_type';
 
-$p = popurl(2);
-print $cgi->header( '-expires' => 'now' ), header("Agent Type Listing", menubar(
-  'Main Menu' => $p,
-)), "Agent types define groups of packages that you can then assign to".
-    " particular agents.<BR><BR>", &table(), <<END;
-      <TR>
-        <TH COLSPAN=2>Agent Type</TH>
-        <TH COLSPAN="2">Packages</TH>
-      </TR>
-END
+#false laziness w/access_user.html
+my $packages_sub = sub {
+  my $agent_type = shift;
+  my @type_pkgs = $agent_type->type_pkgs_enabled;
+  return '(lots; edit agent type to view)' if scalar(@type_pkgs) > 32;
 
-foreach $agent_type ( sort { 
-  $a->getfield('typenum') <=> $b->getfield('typenum')
-} qsearch('agent_type',{}) ) {
-  my($hashref)=$agent_type->hashref;
-  my(@type_pkgs)=qsearch('type_pkgs',{'typenum'=> $hashref->{typenum} });
-  my($rowspan)=scalar(@type_pkgs);
-  $rowspan = int($rowspan/2+0.5) ;
-  print <<END;
-      <TR>
-        <TD ROWSPAN=$rowspan><A HREF="${p}edit/agent_type.cgi?$hashref->{typenum}">
-          $hashref->{typenum}
-        </A></TD>
-        <TD ROWSPAN=$rowspan><A HREF="${p}edit/agent_type.cgi?$hashref->{typenum}">$hashref->{atype}</A></TD>
-END
+  [ map {
+          my $type_pkgs = $_;
+          #my $part_pkg = $type_pkgs->part_pkg;
+          [
+            {
+              #'data'  => $part_pkg->pkg. ' - '. $part_pkg->comment,
+              'data'  => encode_entities($type_pkgs->pkg). ' - '.
+                         ( $type_pkgs->custom ? '(CUSTOM) ' : '' ).
+                         encode_entities($type_pkgs->comment),
+              'align' => 'left',
+              'link'  => $p. 'edit/part_pkg.cgi?'. $type_pkgs->pkgpart,
+            },
+          ];
+        }
+      @type_pkgs
+  ];
 
-  my($type_pkgs);
-  my($tdcount) = -1 ;
-  foreach $type_pkgs ( @type_pkgs ) {
-    my($pkgpart)=$type_pkgs->getfield('pkgpart');
-    my($part_pkg) = qsearchs('part_pkg',{'pkgpart'=> $pkgpart });
-    print qq!<TR>! if ($tdcount == 0) ;
-    $tdcount = 0 if ($tdcount == -1) ;
-    print qq!<TD><A HREF="${p}edit/part_pkg.cgi?$pkgpart">!,
-          $part_pkg->getfield('pkg'),"</A></TD>";
-    $tdcount ++ ;
-    if ($tdcount == 2)
-    {
-       print qq!</TR>\n! ;
-       $tdcount = 0 ;
-    }
-  }
+};
 
-  print "</TR>";
-}
+my $link = [ $p.'edit/agent_type.cgi?', 'typenum' ];
 
-print <<END;
-  <TR><TD COLSPAN=2><I><A HREF="${p}edit/agent_type.cgi">Add new agent type</A></I></TD></TR>
-    </TABLE>
-  </BODY>
-</HTML>
-END
-
-%>
+</%init>