2 % $cgi->param('error' => \%part_pkg_usage);
3 % # internal redirect, because it's a lot of state to pass through
4 <& /browse/part_pkg_usage.html &>
6 % # uh, not quite sure...
7 <% $cgi->redirect($fsurl.'browse/part_pkg.cgi') %>
10 my %vars = $cgi->Vars;
13 foreach my $pkgpart ($cgi->param('pkgpart')) {
14 next unless $pkgpart =~ /^\d+$/;
15 my $part_pkg = FS::part_pkg->by_key($pkgpart)
16 or die "unknown pkgpart $pkgpart";
17 my %old = map { $_->pkgusagepart => $_ } $part_pkg->part_pkg_usage;
18 $part_pkg_usage{$pkgpart} ||= [];
20 foreach (grep /^pkgpart$pkgpart/, keys %vars) {
21 /^pkgpart\d+_(\w+\D)(\d+)$/ or die "misspelled field name '$_'";
22 my $value = delete $vars{$_};
26 $rows[$row]->{$field} = $value;
29 foreach my $row (@rows) {
30 next if !defined($row);
33 foreach my $class (grep /^class/, keys %$row) {
34 $class =~ /^class(\d+)_$/;
36 $classes{$classnum} = delete $row->{$class};
38 my $usage = FS::part_pkg_usage->new($row);
39 $usage->set('pkgpart', $pkgpart);
40 if ( $usage->pkgusagepart and $row->{minutes} > 0 ) {
41 $error = $usage->replace(\%classes);
42 # and don't delete the existing one
43 delete($old{$usage->pkgusagepart});
44 } elsif ( $row->{minutes} > 0 ) {
45 $error = $usage->insert(\%classes);
50 $usage->set('error', $error);
53 push @{ $part_pkg_usage{$pkgpart} }, $usage;
56 foreach my $usage (values %old) {
57 # all of these were not sent back by the client, so delete them
58 my $error = $usage->delete;
60 $usage->set('error', $error);
62 unshift @{ $part_pkg_usage{$pkgpart} }, $usage;