Will things ever be the same again?
[freeside.git] / httemplate / edit / agent_type.cgi
index 849da81..5438e5c 100755 (executable)
@@ -1,79 +1,57 @@
-<%
-#<!-- $Id: agent_type.cgi,v 1.5 2001-10-30 14:54:07 ivan Exp $ -->
-
-use strict;
-use vars qw( $cgi $agent_type $action $hashref $p $part_pkg );
-use CGI;
-use CGI::Carp qw(fatalsToBrowser);
-use FS::UID qw(cgisuidsetup);
-use FS::Record qw(qsearch qsearchs fields);
-use FS::agent_type;
-use FS::CGI qw(header menubar popurl);
-use FS::agent_type;
-use FS::part_pkg;
-use FS::type_pkgs;
-
-$cgi = new CGI;
-
-&cgisuidsetup($cgi);
-
-if ( $cgi->param('error') ) {
-  $agent_type = new FS::agent_type ( {
-    map { $_, scalar($cgi->param($_)) } fields('agent')
-  } );
-} elsif ( $cgi->keywords ) { #editing
-  my( $query ) = $cgi->keywords;
-  $query =~ /^(\d+)$/;
-  $agent_type=qsearchs('agent_type',{'typenum'=>$1});
-} else { #adding
-  $agent_type = new FS::agent_type {};
-}
-$action = $agent_type->typenum ? 'Edit' : 'Add';
-$hashref = $agent_type->hashref;
-
-$p = popurl(2);
-print header("$action Agent Type", menubar(
+%
+%
+%my($agent_type);
+%if ( $cgi->param('error') ) {
+%  $agent_type = new FS::agent_type ( {
+%    map { $_, scalar($cgi->param($_)) } fields('agent')
+%  } );
+%} elsif ( $cgi->keywords ) { #editing
+%  my( $query ) = $cgi->keywords;
+%  $query =~ /^(\d+)$/;
+%  $agent_type=qsearchs('agent_type',{'typenum'=>$1});
+%} else { #adding
+%  $agent_type = new FS::agent_type {};
+%}
+%my $action = $agent_type->typenum ? 'Edit' : 'Add';
+%
+%
+<% include("/elements/header.html","$action Agent Type", menubar(
   'Main Menu' => "$p",
   'View all agent types' => "${p}browse/agent_type.cgi",
-));
+))
+%>
+% if ( $cgi->param('error') ) { 
+
+  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
+% } 
 
-print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
-      "</FONT>"
-  if $cgi->param('error');
 
-print '<FORM ACTION="', popurl(1), 'process/agent_type.cgi" METHOD=POST>',
-      qq!<INPUT TYPE="hidden" NAME="typenum" VALUE="$hashref->{typenum}">!,
-      "Agent Type #", $hashref->{typenum} ? $hashref->{typenum} : "(NEW)";
+<FORM ACTION="<% popurl(1) %>process/agent_type.cgi" METHOD=POST>
+<INPUT TYPE="hidden" NAME="typenum" VALUE="<% $agent_type->typenum %>">
+Agent Type #<% $agent_type->typenum || "(NEW)" %>
+<BR>
 
-print <<END;
-<BR><BR>Agent Type <INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="$hashref->{atype}">
-<BR><BR>Select which packages agents of this type may sell to customers<BR>
-END
+Agent Type
+<INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="<% $agent_type->atype %>">
+<BR><BR>
 
-foreach $part_pkg ( qsearch('part_pkg',{}) ) {
-  print qq!<BR><INPUT TYPE="checkbox" NAME="pkgpart!,
-        $part_pkg->getfield('pkgpart'), qq!" !,
-       # ( 'CHECKED 'x scalar(
-        qsearchs('type_pkgs',{
-          'typenum' => $agent_type->getfield('typenum'),
-          'pkgpart'  => $part_pkg->getfield('pkgpart'),
-        })
-          ? 'CHECKED '
-          : '',
-        qq!VALUE="ON"> !,
-    qq!<A HREF="${p}edit/part_pkg.cgi?!, $part_pkg->pkgpart, 
-    '">', $part_pkg->getfield('pkg'), '</A>',
-  ;
-}
+Select which packages agents of this type may sell to customers<BR>
+<% ntable("#cccccc", 2) %><TR><TD>
+<% include('/elements/checkboxes-table.html',
+              'source_obj'    => $agent_type,
+              'link_table'    => 'type_pkgs',
+              'target_table'  => 'part_pkg',
+              'name_callback' => sub { $_[0]->pkg. ' - '. $_[0]->comment; },
+              'target_link'   => $p.'edit/part_pkg.cgi?',
+              'disable-able'  => 1,
 
-print qq!<BR><BR><INPUT TYPE="submit" VALUE="!,
-      $hashref->{typenum} ? "Apply changes" : "Add agent type",
-      qq!">!;
+           )
+%>
+</TD></TR></TABLE>
+<BR>
+
+<INPUT TYPE="submit" VALUE="<% $agent_type->typenum ? "Apply changes" : "Add agent type" %>">
 
-print <<END;
     </FORM>
-  </BODY>
-</HTML>
-END
 
-%>
+<% include('/elements/footer.html') %>