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