1 <% include( 'elements/process.html',
4 'redirect' => $redirect_callback,
5 'viewall_dir' => 'browse',
6 'viewall_ext' => 'cgi',
8 #XXX usable with cloning? #'agent_null_right' => 'Edit global package definitions',
9 'precheck_callback' => $precheck_callback,
10 'args_callback' => $args_callback,
11 'process_m2m' => \@process_m2m,
16 my $curuser = $FS::CurrentUser::CurrentUser;
19 unless $curuser->access_right('Edit package definitions')
20 || $curuser->access_right('Edit global package definitions')
21 || ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
23 my $precheck_callback = sub {
26 my $conf = new FS::Conf;
28 foreach (qw( setuptax recurtax disabled )) {
29 $cgi->param($_, '') unless defined $cgi->param($_);
32 return 'Must select a tax class'
33 if $cgi->param('taxclass') eq '(select)';
36 foreach ($cgi->param('agent_type')) {
38 push @agents, $1 if $1;
40 return "At least one agent type must be specified."
41 unless scalar(@agents)
42 || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
43 || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') )
44 || $cgi->param('disabled');
52 my $args_callback = sub {
53 my( $cgi, $new ) = @_;
55 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
61 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
64 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
65 my $href = $plans{$plan}->{'fields'};
68 my $options = $cgi->param($plan."__OPTIONS");
69 my @options = split(',', $options);
71 map { my $optionname = $_;
72 my $param = $plan."__$optionname";
73 my $parser = exists($href->{$optionname}{parse})
74 ? $href->{$optionname}{parse}
76 my $value = join(', ', &$parser($cgi->param($param)));
77 my $check = $href->{$optionname}{check};
78 if ( $check && ! &$check($value) ) {
79 $value = join(', ', $cgi->param($param));
80 $error ||= "Illegal ".
81 ($href->{$optionname}{name}||$optionname). ": $value";
83 ( $optionname => $value );
87 foreach ( split(',', $cgi->param('taxproductnums') ) ) {
88 my $value = $cgi->param("taxproductnum_$_");
89 $error ||= "Illegal taxproductnum_$_: $value"
90 unless ( $value =~ /^\d*$/ );
91 $options{"usage_taxproductnum_$_"} = $value;
94 $options{$_} = scalar( $cgi->param($_) )
95 for (qw( setup_fee recur_fee ));
97 push @args, 'options' => \%options;
103 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
105 qsearch('part_svc', {} );
107 push @args, 'pkg_svc' => \%pkg_svc;
110 # cust_pkg and custnum_ref (inserts only)
112 unless ( $cgi->param('pkgpart') ) {
113 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
114 'custnum_ref' => \$custnum;
117 warn "args: ".join('/', @args). "\n";
123 my $redirect_callback = sub {
124 #my( $cgi, $new ) = @_;
125 return '' unless $custnum;
126 popurl(3). "view/cust_main.cgi?keywords=$custnum;dummy=";
129 #these should probably move to @args above and be processed by part_pkg.pm...
131 $cgi->param('tax_override') =~ /^([\d,]+)$/;
132 my (@tax_overrides) = (grep "$_", split (",", $1));
136 'link_table' => 'part_pkg_taxoverride',
137 'target_table' => 'tax_class',
138 'params' => \@tax_overrides,
140 { 'link_table' => 'part_pkg_link',
141 'target_table' => 'part_pkg',
142 'base_field' => 'src_pkgpart',
143 'target_field' => 'dst_pkgpart',
144 'hashref' => { 'link_type' => 'bill' },
145 'params' => [ map $cgi->param($_), grep /^bill_dst_pkgpart/, $cgi->param ],
147 { 'link_table' => 'part_pkg_link',
148 'target_table' => 'part_pkg',
149 'base_field' => 'src_pkgpart',
150 'target_field' => 'dst_pkgpart',
151 'hashref' => { 'link_type' => 'svc' },
152 'params' => [ map $cgi->param($_), grep /^svc_dst_pkgpart/, $cgi->param ],
156 foreach my $override_class ($cgi->param) {
157 next unless $override_class =~ /^tax_override_(\w+)$/;
160 my (@tax_overrides) = (grep "$_", split (",", $1))
161 if $cgi->param($override_class) =~ /^([\d,]+)$/;
164 'link_table' => 'part_pkg_taxoverride',
165 'target_table' => 'tax_class',
166 'hashref' => { 'usage_class' => $class },
167 'params' => [ @tax_overrides ],
172 my $conf = new FS::Conf;
174 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
176 foreach ($cgi->param('agent_type')) {
178 push @agents, $1 if $1;
181 'link_table' => 'type_pkgs',
182 'target_table' => 'agent_type',
183 'params' => \@agents,