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