ed420083014ac7656df4f51d7f03071733a630af
[freeside.git] / htdocs / edit / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_pkg.cgi,v 1.4 1999-01-19 05:13:38 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 # Note: Should be run setuid freeside as user nobody
11 #
12 # started with /sales/add/cust_pkg.cgi, which added packages
13 # ivan@voicenet.com 97-jan-5, 97-mar-21
14 #
15 # Rewrote for new API
16 # ivan@voicenet.com 97-jul-7
17 #
18 # FS::Search is no more, &cgisuidsetup needs $cgi, ivan@sisd.com 98-mar-7 
19 #
20 # Changes to allow page to work at a relative position in server
21 # Changed to display packages 2-wide in a table
22 #       bmccane@maxbaud.net     98-apr-3
23 #
24 # fixed a pretty cool bug from above which caused a visual glitch ivan@sisd.com
25 # 98-jun-1
26 #
27 # $Log: cust_pkg.cgi,v $
28 # Revision 1.4  1999-01-19 05:13:38  ivan
29 # for mod_perl: no more top-level my() variables; use vars instead
30 # also the last s/create/new/;
31 #
32 # Revision 1.3  1999/01/18 09:41:28  ivan
33 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
34 # (good idea anyway)
35 #
36 # Revision 1.2  1998/12/17 06:17:04  ivan
37 # fix double // in relative URLs, s/CGI::Base/CGI/;
38 #
39
40 use strict;
41 use vars qw( $cgi %pkg %comment $query $custnum $otaker $p1 @cust_pkg 
42              $cust_main $agent $type_pkgs $count );
43 use CGI;
44 use CGI::Carp qw(fatalsToBrowser);
45 use FS::UID qw(cgisuidsetup getotaker);
46 use FS::Record qw(qsearch qsearchs);
47 use FS::CGI qw(header popurl);
48 use FS::part_pkg;
49
50 $cgi = new CGI;
51 &cgisuidsetup($cgi);
52
53 foreach (qsearch('part_pkg', {})) {
54   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
55   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
56 }
57
58 #untaint custnum
59
60 ($query) = $cgi->keywords;
61 $query =~ /^(\d+)$/;
62 $custnum = $1;
63
64 $otaker = &getotaker;
65
66 $p1 = popurl(1);
67 print $cgi->header( '-expires' => 'now' ), header("Add/Edit Packages", ''), <<END;
68     <FORM ACTION="${p1}process/cust_pkg.cgi" METHOD=POST>
69     <HR>
70 END
71
72 #custnum
73 print qq!<INPUT TYPE="hidden" NAME="new_custnum" VALUE="$custnum">!;
74
75 #current packages (except cancelled packages)
76 @cust_pkg = grep ! $_->getfield('cancel'),
77   qsearch('cust_pkg',{'custnum'=>$custnum});
78
79 if (@cust_pkg) {
80   print <<END;
81 <CENTER><FONT SIZE="+2">Current packages</FONT></CENTER>
82 These are packages the customer currently has.  Select those packages you
83 wish to remove (if any).<BR><BR>
84 END
85
86   my ($count) = 0 ;
87   print qq!<CENTER><TABLE>! ;
88   foreach (@cust_pkg) {
89     print qq!<TR>! if ($count ==0) ;
90     my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
91     print qq!<TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="$pkgnum">!,
92           #qq!$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!,
93           #now you've got to admit this bug was pretty cool
94           qq!$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!;
95     $count ++ ;
96     if ($count == 2)
97     {
98       $count = 0 ;
99       print qq!</TR>\n! ;
100     }
101   }
102   print qq!</TABLE></CENTER>! ;
103
104   print "<HR>";
105 }
106
107 print <<END;
108 <CENTER><FONT SIZE="+2">New packages</FONT></CENTER>
109 These are packages the customer can purchase.  Specify the quantity to add
110 of each package.<BR><BR>
111 END
112
113 $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
114 $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
115
116 $count = 0 ;
117 print qq!<CENTER><TABLE>! ;
118 foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
119   my($pkgpart)=$type_pkgs->pkgpart;
120   print qq!<TR>! if ($count == 0) ;
121   print <<END;
122   <TD>
123   <INPUT TYPE="text" NAME="pkg$pkgpart" VALUE="0" SIZE="2" MAXLENGTH="2">
124   $pkgpart: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n
125 END
126   $count ++ ;
127   if ($count == 2)
128   {
129     print qq!</TR>\n! ;
130     $count = 0 ;
131   }
132 }
133 print qq!</TABLE></CENTER>! ;
134
135 #otaker
136 print qq!<INPUT TYPE="hidden" NAME="new_otaker" VALUE="$otaker">\n!;
137
138 #submit
139 print qq!<P><CENTER><INPUT TYPE="submit" VALUE="Order"></CENTER>\n!;
140
141 print <<END;
142     </FORM>
143   </BODY>
144 </HTML>
145 END