Initial revision
[freeside.git] / htdocs / edit / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # cust_pkg.cgi: Add/edit packages (output form)
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 use strict;
28 use CGI::Base qw(:DEFAULT :CGI); # CGI module
29 use CGI::Carp qw(fatalsToBrowser);
30 use FS::UID qw(cgisuidsetup getotaker);
31 use FS::Record qw(qsearch qsearchs);
32
33 my($cgi) = new CGI::Base;
34 $cgi->get;
35 &cgisuidsetup($cgi);
36
37 my(%pkg,%comment);
38 foreach (qsearch('part_pkg', {})) {
39   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
40   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
41 }
42
43 #untaint custnum
44 $QUERY_STRING =~ /^(\d+)$/;
45 my($custnum)=$1;
46
47 my($otaker)=&getotaker;
48
49 SendHeaders();
50 print <<END;
51 <HTML>   
52   <HEAD>
53     <TITLE>Add/Edit Packages</TITLE>
54   </HEAD>
55   <BODY>
56     <CENTER>
57     <H1>Add/Edit Packages</H1>
58     </CENTER>
59     <FORM ACTION="process/cust_pkg.cgi" METHOD=POST>
60     <HR>
61 END
62
63 #custnum
64 print qq!<INPUT TYPE="hidden" NAME="new_custnum" VALUE="$custnum">!;
65
66 #current packages (except cancelled packages)
67 my(@cust_pkg) = grep ! $_->getfield('cancel'),
68   qsearch('cust_pkg',{'custnum'=>$custnum});
69
70 if (@cust_pkg) {
71   print <<END;
72 <CENTER><FONT SIZE="+2">Current packages</FONT></CENTER>
73 These are packages the customer currently has.  Select those packages you
74 wish to remove (if any).<BR><BR>
75 END
76
77   my ($count) = 0 ;
78   print qq!<CENTER><TABLE>! ;
79   foreach (@cust_pkg) {
80     print qq!<TR>! if ($count ==0) ;
81     my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
82     print qq!<TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="$pkgnum">!,
83           #qq!$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!,
84           #now you've got to admit this bug was pretty cool
85           qq!$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!;
86     $count ++ ;
87     if ($count == 2)
88     {
89       $count = 0 ;
90       print qq!</TR>\n! ;
91     }
92   }
93   print qq!</TABLE></CENTER>! ;
94
95   print "<HR>";
96 }
97
98 print <<END;
99 <CENTER><FONT SIZE="+2">New packages</FONT></CENTER>
100 These are packages the customer can purchase.  Specify the quantity to add
101 of each package.<BR><BR>
102 END
103
104 my($cust_main)=qsearchs('cust_main',{'custnum'=>$custnum});
105 my($agent)=qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
106
107 my($type_pkgs);
108 my ($count) = 0 ;
109 print qq!<CENTER><TABLE>! ;
110 foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
111   my($pkgpart)=$type_pkgs->pkgpart;
112   print qq!<TR>! if ($count == 0) ;
113   print <<END;
114   <TD>
115   <INPUT TYPE="text" NAME="pkg$pkgpart" VALUE="0" SIZE="2" MAXLENGTH="2">
116   $pkgpart: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n
117 END
118   $count ++ ;
119   if ($count == 2)
120   {
121     print qq!</TR>\n! ;
122     $count = 0 ;
123   }
124 }
125 print qq!</TABLE></CENTER>! ;
126
127 #otaker
128 print qq!<INPUT TYPE="hidden" NAME="new_otaker" VALUE="$otaker">\n!;
129
130 #submit
131 print qq!<P><CENTER><INPUT TYPE="submit" VALUE="Order"></CENTER>\n!;
132
133 print <<END;
134     </FORM>
135   </BODY>
136 </HTML>
137 END