silly HTML typo
[freeside.git] / htdocs / edit / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_pkg.cgi,v 1.6 1999-02-28 00:03:36 ivan Exp $
4 #
5 # this is for changing packages around, not editing things within the package
6 #
7 # Usage: cust_pkg.cgi custnum
8 #        http://server.name/path/cust_pkg.cgi?custnum
9 #
10 # started with /sales/add/cust_pkg.cgi, which added packages
11 # ivan@voicenet.com 97-jan-5, 97-mar-21
12 #
13 # Rewrote for new API
14 # ivan@voicenet.com 97-jul-7
15 #
16 # FS::Search is no more, &cgisuidsetup needs $cgi, ivan@sisd.com 98-mar-7 
17 #
18 # Changes to allow page to work at a relative position in server
19 # Changed to display packages 2-wide in a table
20 #       bmccane@maxbaud.net     98-apr-3
21 #
22 # fixed a pretty cool bug from above which caused a visual glitch ivan@sisd.com
23 # 98-jun-1
24 #
25 # $Log: cust_pkg.cgi,v $
26 # Revision 1.6  1999-02-28 00:03:36  ivan
27 # removed misleading comments
28 #
29 # Revision 1.5  1999/02/07 09:59:18  ivan
30 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
31 #
32 # Revision 1.4  1999/01/19 05:13:38  ivan
33 # for mod_perl: no more top-level my() variables; use vars instead
34 # also the last s/create/new/;
35 #
36 # Revision 1.3  1999/01/18 09:41:28  ivan
37 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
38 # (good idea anyway)
39 #
40 # Revision 1.2  1998/12/17 06:17:04  ivan
41 # fix double // in relative URLs, s/CGI::Base/CGI/;
42 #
43
44 use strict;
45 use vars qw( $cgi %pkg %comment $custnum $p1 @cust_pkg 
46              $cust_main $agent $type_pkgs $count %remove_pkg );
47 use CGI;
48 use CGI::Carp qw(fatalsToBrowser);
49 use FS::UID qw(cgisuidsetup);
50 use FS::Record qw(qsearch qsearchs);
51 use FS::CGI qw(header popurl);
52 use FS::part_pkg;
53 use FS::type_pkgs;
54
55 foreach (qsearch('part_pkg', {})) {
56   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
57   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
58 }
59
60 $cgi = new CGI;
61 &cgisuidsetup($cgi);
62
63 if ( $cgi->param('error') ) {
64   $custnum = $cgi->param('custnum');
65   %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');
66 } else {
67   my($query) = $cgi->keywords;
68   $query =~ /^(\d+)$/;
69   $custnum = $1;
70   undef %remove_pkg;
71 }
72
73 $p1 = popurl(1);
74 print $cgi->header( '-expires' => 'now' ), header("Add/Edit Packages", '');
75
76 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
77       "</FONT>"
78   if $cgi->param('error');
79
80 print qq!<FORM ACTION="${p1}process/cust_pkg.cgi" METHOD=POST>!;
81
82 print qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!;
83
84 #current packages
85 @cust_pkg = qsearch('cust_pkg',{ 'custnum' => $custnum, 'cancel' => '' } );
86
87 if (@cust_pkg) {
88   print <<END;
89 Current packages - select to remove (services are moved to a new package below)
90 <BR><BR>
91 END
92
93   my ($count) = 0 ;
94   print qq!<TABLE>! ;
95   foreach (@cust_pkg) {
96     print '<TR>' if $count == 0;
97     my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
98     print qq!<TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="$pkgnum"!;
99     print " CHECKED" if $remove_pkg{$pkgnum};
100     print qq!>$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!;
101     $count ++ ;
102     if ($count == 2)
103     {
104       $count = 0 ;
105       print qq!</TR>\n! ;
106     }
107   }
108   print qq!</TABLE><BR><BR>!;
109 }
110
111 print <<END;
112 Order new packages<BR><BR>
113 END
114
115 $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
116 $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
117
118 $count = 0 ;
119 print qq!<TABLE>! ;
120 foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
121   my($pkgpart)=$type_pkgs->pkgpart;
122   print qq!<TR>! if ($count == 0) ;
123   my $value = $cgi->param("pkg$pkgpart") || 0;
124   print <<END;
125   <TD>
126   <INPUT TYPE="text" NAME="pkg$pkgpart" VALUE="$value" SIZE="2" MAXLENGTH="2">
127   $pkgpart: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n
128 END
129   $count ++ ;
130   if ($count == 2)
131   {
132     print qq!</TR>\n! ;
133     $count = 0 ;
134   }
135 }
136 print qq!</TABLE>! ;
137
138 #submit
139 print qq!<P><INPUT TYPE="submit" VALUE="Order">\n!;
140
141 print <<END;
142     </FORM>
143   </BODY>
144 </HTML>
145 END