oops, in 1.2 tree, can't do searches until [cgi|admin]suidsetup,
[freeside.git] / htdocs / edit / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_pkg.cgi,v 1.7 1999-04-14 01:03:01 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.7  1999-04-14 01:03:01  ivan
27 # oops, in 1.2 tree, can't do searches until [cgi|admin]suidsetup,
28 # bug is hidden by mod_perl persistance
29 #
30 # Revision 1.6  1999/02/28 00:03:36  ivan
31 # removed misleading comments
32 #
33 # Revision 1.5  1999/02/07 09:59:18  ivan
34 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
35 #
36 # Revision 1.4  1999/01/19 05:13:38  ivan
37 # for mod_perl: no more top-level my() variables; use vars instead
38 # also the last s/create/new/;
39 #
40 # Revision 1.3  1999/01/18 09:41:28  ivan
41 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
42 # (good idea anyway)
43 #
44 # Revision 1.2  1998/12/17 06:17:04  ivan
45 # fix double // in relative URLs, s/CGI::Base/CGI/;
46 #
47
48 use strict;
49 use vars qw( $cgi %pkg %comment $custnum $p1 @cust_pkg 
50              $cust_main $agent $type_pkgs $count %remove_pkg );
51 use CGI;
52 use CGI::Carp qw(fatalsToBrowser);
53 use FS::UID qw(cgisuidsetup);
54 use FS::Record qw(qsearch qsearchs);
55 use FS::CGI qw(header popurl);
56 use FS::part_pkg;
57 use FS::type_pkgs;
58
59 $cgi = new CGI;
60 &cgisuidsetup($cgi);
61
62 %pkg = ();
63 %comment = ();
64 foreach (qsearch('part_pkg', {})) {
65   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
66   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
67 }
68
69 if ( $cgi->param('error') ) {
70   $custnum = $cgi->param('custnum');
71   %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');
72 } else {
73   my($query) = $cgi->keywords;
74   $query =~ /^(\d+)$/;
75   $custnum = $1;
76   undef %remove_pkg;
77 }
78
79 $p1 = popurl(1);
80 print $cgi->header( '-expires' => 'now' ), header("Add/Edit Packages", '');
81
82 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
83       "</FONT>"
84   if $cgi->param('error');
85
86 print qq!<FORM ACTION="${p1}process/cust_pkg.cgi" METHOD=POST>!;
87
88 print qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!;
89
90 #current packages
91 @cust_pkg = qsearch('cust_pkg',{ 'custnum' => $custnum, 'cancel' => '' } );
92
93 if (@cust_pkg) {
94   print <<END;
95 Current packages - select to remove (services are moved to a new package below)
96 <BR><BR>
97 END
98
99   my ($count) = 0 ;
100   print qq!<TABLE>! ;
101   foreach (@cust_pkg) {
102     print '<TR>' if $count == 0;
103     my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
104     print qq!<TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="$pkgnum"!;
105     print " CHECKED" if $remove_pkg{$pkgnum};
106     print qq!>$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!;
107     $count ++ ;
108     if ($count == 2)
109     {
110       $count = 0 ;
111       print qq!</TR>\n! ;
112     }
113   }
114   print qq!</TABLE><BR><BR>!;
115 }
116
117 print <<END;
118 Order new packages<BR><BR>
119 END
120
121 $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
122 $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
123
124 $count = 0 ;
125 print qq!<TABLE>! ;
126 foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
127   my($pkgpart)=$type_pkgs->pkgpart;
128   print qq!<TR>! if ($count == 0) ;
129   my $value = $cgi->param("pkg$pkgpart") || 0;
130   print <<END;
131   <TD>
132   <INPUT TYPE="text" NAME="pkg$pkgpart" VALUE="$value" SIZE="2" MAXLENGTH="2">
133   $pkgpart: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n
134 END
135   $count ++ ;
136   if ($count == 2)
137   {
138     print qq!</TR>\n! ;
139     $count = 0 ;
140   }
141 }
142 print qq!</TABLE>! ;
143
144 #submit
145 print qq!<P><INPUT TYPE="submit" VALUE="Order">\n!;
146
147 print <<END;
148     </FORM>
149   </BODY>
150 </HTML>
151 END