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