1 <% include( 'elements/process.html',
4 'viewall_dir' => 'browse',
5 'viewall_ext' => 'cgi',
7 #XXX usable with cloning? #'agent_null_right' => 'Edit global package definitions',
8 'precheck_callback' => $precheck_callback,
9 'args_callback' => $args_callback,
10 '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')
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 $options{$_} = scalar( $cgi->param($_) )
88 for (qw( setup_fee recur_fee ));
90 push @args, 'options' => \%options;
96 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
98 qsearch('part_svc', {} );
100 push @args, 'pkg_svc' => \%pkg_svc;
103 # cust_pkg and custnum_ref (inserts only)
105 unless ( $cgi->param('pkgpart') ) {
106 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
107 'custnum_ref' => \$custnum;
114 #these should probably move to @args above and be processed by part_pkg.pm...
116 $cgi->param('tax_override') =~ /^([\d,]+)$/;
117 my (@tax_overrides) = (grep "$_", split (",", $1));
121 'link_table' => 'part_pkg_taxoverride',
122 'target_table' => 'tax_class',
123 'params' => \@tax_overrides,
125 { 'link_table' => 'part_pkg_link',
126 'target_table' => 'part_pkg',
127 'base_field' => 'src_pkgpart',
128 'target_field' => 'dst_pkgpart',
129 'hashref' => { 'link_type' => 'bill' },
130 'params' => [ map $cgi->param($_), grep /^bill_dst_pkgpart/, $cgi->param ],
132 { 'link_table' => 'part_pkg_link',
133 'target_table' => 'part_pkg',
134 'base_field' => 'src_pkgpart',
135 'target_field' => 'dst_pkgpart',
136 'hashref' => { 'link_type' => 'svc' },
137 'params' => [ map $cgi->param($_), grep /^svc_dst_pkgpart/, $cgi->param ],
141 my $conf = new FS::Conf;
143 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
145 foreach ($cgi->param('agent_type')) {
147 push @agents, $1 if $1;
150 'link_table' => 'type_pkgs',
151 'target_table' => 'agent_type',
152 'params' => \@agents,