1 <% include( 'elements/process.html',
5 'agent_null_right' => \@agent_null_right,
6 'redirect' => $redirect_callback,
7 'viewall_dir' => 'browse',
8 'viewall_ext' => 'cgi',
10 'precheck_callback' => $precheck_callback,
11 'args_callback' => $args_callback,
12 'process_m2m' => \@process_m2m,
13 'process_o2m' => \@process_o2m,
18 my $customizing = ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') );
20 my $curuser = $FS::CurrentUser::CurrentUser;
22 my $edit_global = 'Edit global package definitions';
23 my $customize = 'Customize customer package';
26 unless $curuser->access_right('Edit package definitions')
27 || $curuser->access_right($edit_global)
28 || ( $customizing && $curuser->access_right($customize) );
30 my @agent_null_right = ( $edit_global );
31 push @agent_null_right, $customize if $customizing;
34 my $precheck_callback = sub {
37 my $conf = new FS::Conf;
39 foreach (qw( setuptax recurtax disabled )) {
40 $cgi->param($_, '') unless defined $cgi->param($_);
43 return 'Must select a tax class'
44 if $cgi->param('taxclass') eq '(select)';
47 foreach ($cgi->param('agent_type')) {
49 push @agents, $1 if $1;
51 return "At least one agent type must be specified."
52 unless scalar(@agents)
53 || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
54 || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') )
55 || $cgi->param('disabled')
56 || $cgi->param('agentnum');
64 my $args_callback = sub {
65 my( $cgi, $new ) = @_;
67 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
73 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
76 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
77 my $href = $plans{$plan}->{'fields'};
80 my $options = $cgi->param($plan."__OPTIONS");
81 my @options = split(',', $options);
83 map { my $optionname = $_;
84 my $param = $plan."__$optionname";
85 my $parser = exists($href->{$optionname}{parse})
86 ? $href->{$optionname}{parse}
88 my $value = join(', ', &$parser($cgi->param($param)));
89 my $check = $href->{$optionname}{check};
90 if ( $check && ! &$check($value) ) {
91 $value = join(', ', $cgi->param($param));
92 $error ||= "Illegal ".
93 ($href->{$optionname}{name}||$optionname). ": $value";
95 ( $optionname => $value );
97 grep { $_ !~ /^report_option_/ }
100 foreach ( split(',', $cgi->param('taxproductnums') ) ) {
101 my $value = $cgi->param("taxproductnum_$_");
102 $error ||= "Illegal taxproductnum_$_: $value"
103 unless ( $value =~ /^\d*$/ );
104 $options{"usage_taxproductnum_$_"} = $value;
107 foreach ( grep $_, $cgi->param('report_option') ) {
108 $error ||= "Illegal optional report class: $_" unless ( $_ =~ /^\d*$/ );
109 $options{"report_option_$_"} = 1;
112 $options{$_} = scalar( $cgi->param($_) )
113 for (qw( setup_fee recur_fee disable_line_item_date_ranges ));
115 push @args, 'options' => \%options;
121 my %part_pkg_currency = (
122 map { $_ => scalar($cgi->param($_)) }
123 #grep /._[A-Z]{3}$/, #support other options
124 grep /^(setup|recur)_fee_[A-Z]{3}$/,
128 push @args, 'part_pkg_currency' => \%part_pkg_currency;
134 my @svcparts = map { $_->svcpart } qsearch('part_svc', {});
135 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) } @svcparts;
136 my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_")) } @svcparts;
138 push @args, 'pkg_svc' => \%pkg_svc, 'hidden_svc' => \%hidden_svc;
141 # cust_pkg and custnum_ref (inserts only)
143 unless ( $cgi->param('pkgpart') ) {
144 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
145 'custnum_ref' => \$custnum;
149 foreach my $param ( $cgi->param ) {
150 if ( $param =~ /^export(\d+)$/ && length($cgi->param($param)) > 0 ) {
151 $part_pkg_vendor{$1} = $cgi->param($param);
154 if ( keys %part_pkg_vendor > 0 ) {
155 push @args, 'part_pkg_vendor' => \%part_pkg_vendor;
158 #warn "args: ".join('/', @args). "\n";
164 my $redirect_callback = sub {
165 #my( $cgi, $new ) = @_;
166 return '' unless $custnum;
167 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
170 #my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
172 #can we link back to the specific customized package? it would be nice...
173 popurl(3). "view/cust_main.cgi?custnum=$custnum$show;dummy=";
176 #these should probably move to @args above and be processed by part_pkg.pm...
178 $cgi->param('tax_override') =~ /^([\d,]+)$/;
179 my (@tax_overrides) = (grep "$_", split (",", $1));
183 'link_table' => 'part_pkg_taxoverride',
184 'target_table' => 'tax_class',
185 'params' => \@tax_overrides,
187 { 'link_table' => 'part_pkg_discount',
188 'target_table' => 'discount',
189 'params' => [ map $cgi->param($_),
190 grep /^discountnum/, $cgi->param
193 { 'link_table' => 'part_pkg_link',
194 'target_table' => 'part_pkg',
195 'base_field' => 'src_pkgpart',
196 'target_field' => 'dst_pkgpart',
197 'hashref' => { 'link_type' => 'svc', 'hidden' => '' },
198 'params' => [ map $cgi->param($_),
199 grep /^svc_dst_pkgpart/, $cgi->param
202 { 'link_table' => 'part_pkg_link',
203 'target_table' => 'part_pkg',
204 'base_field' => 'src_pkgpart',
205 'target_field' => 'dst_pkgpart',
206 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
207 'params' => [ map $cgi->param($_),
208 grep /^supp_dst_pkgpart/, $cgi->param
213 { 'link_table' => 'part_pkg_link',
214 'target_table' => 'part_pkg',
215 'base_field' => 'src_pkgpart',
216 'target_field' => 'dst_pkgpart',
217 'hashref' => { 'link_type' => 'bill', 'hidden' => $hidden },
218 'params' => [ map { $cgi->param($_) }
219 grep { my $param = "bill_dst_pkgpart__hidden";
221 (($digit) = /^bill_dst_pkgpart(\d+)/ ) &&
222 $cgi->param("$param$digit") eq $hidden;
230 foreach my $override_class ($cgi->param) {
231 next unless $override_class =~ /^tax_override_(\w+)$/;
234 my (@tax_overrides) = (grep "$_", split (",", $1))
235 if $cgi->param($override_class) =~ /^([\d,]+)$/;
238 'link_table' => 'part_pkg_taxoverride',
239 'target_table' => 'tax_class',
240 'hashref' => { 'usage_class' => $class },
241 'params' => [ @tax_overrides ],
246 my $conf = new FS::Conf;
248 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
250 foreach ($cgi->param('agent_type')) {
252 push @agents, $1 if $1;
255 'link_table' => 'type_pkgs',
256 'target_table' => 'agent_type',
257 'params' => \@agents,
263 'table' => 'part_pkg_msgcat',
264 'fields' => [qw( locale pkg )],