remove
[freeside.git] / httemplate / edit / cust_pkg.cgi
1 <!-- $Id: cust_pkg.cgi,v 1.6 2002-01-30 14:18:08 ivan Exp $ -->
2 <%
3
4 my %pkg = ();
5 my %comment = ();
6 foreach (qsearch('part_pkg', { 'disabled' => '' })) {
7   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
8   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
9 }
10
11 my($custnum, %remove_pkg);
12 if ( $cgi->param('error') ) {
13   $custnum = $cgi->param('custnum');
14   %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');
15 } else {
16   my($query) = $cgi->keywords;
17   $query =~ /^(\d+)$/;
18   $custnum = $1;
19   %remove_pkg = ();
20 }
21
22 my $p1 = popurl(1);
23 print header("Add/Edit Packages", '');
24
25 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
26       "</FONT>"
27   if $cgi->param('error');
28
29 print qq!<FORM ACTION="${p1}process/cust_pkg.cgi" METHOD=POST>!;
30
31 print qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!;
32
33 #current packages
34 my @cust_pkg = qsearch('cust_pkg',{ 'custnum' => $custnum, 'cancel' => '' } );
35
36 if (@cust_pkg) {
37   print <<END;
38 Current packages - select to remove (services are moved to a new package below)
39 <BR><BR>
40 END
41
42   my $count = 0 ;
43   print qq!<TABLE>! ;
44   foreach (@cust_pkg) {
45     print '<TR>' if $count == 0;
46     my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
47     print qq!<TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="$pkgnum"!;
48     print " CHECKED" if $remove_pkg{$pkgnum};
49     print qq!>$pkgnum: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n!;
50     $count ++ ;
51     if ($count == 2)
52     {
53       $count = 0 ;
54       print qq!</TR>\n! ;
55     }
56   }
57   print qq!</TABLE><BR><BR>!;
58 }
59
60 print <<END;
61 Order new packages<BR><BR>
62 END
63
64 my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
65 my $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
66
67 my $count = 0;
68 my $pkgparts = 0;
69 print qq!<TABLE>!;
70 foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
71   $pkgparts++;
72   my($pkgpart)=$type_pkgs->pkgpart;
73   next unless exists $pkg{$pkgpart}; #skip disabled ones
74   print qq!<TR>! if ( $count == 0 );
75   my $value = $cgi->param("pkg$pkgpart") || 0;
76   print <<END;
77   <TD>
78   <INPUT TYPE="text" NAME="pkg$pkgpart" VALUE="$value" SIZE="2" MAXLENGTH="2">
79   $pkgpart: $pkg{$pkgpart} - $comment{$pkgpart}</TD>\n
80 END
81   $count ++ ;
82   if ( $count == 2 ) {
83     print qq!</TR>\n! ;
84     $count = 0;
85   }
86 }
87 print qq!</TABLE>!;
88
89 unless ( $pkgparts ) {
90   my $p2 = popurl(2);
91   my $typenum = $agent->typenum;
92   my $agent_type = qsearchs( 'agent_type', { 'typenum' => $typenum } );
93   my $atype = $agent_type->atype;
94   print <<END;
95 (No <a href="${p2}browse/part_pkg.cgi">package definitions</a>, or agent type
96 <a href="${p2}edit/agent_type.cgi?$typenum">$atype</a> not allowed to purchase
97 any packages.)
98 END
99 }
100
101 #submit
102 print <<END;
103 <P><INPUT TYPE="submit" VALUE="Order">
104     </FORM>
105   </BODY>
106 </HTML>
107 END
108 %>