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,
15 my $curuser = $FS::CurrentUser::CurrentUser;
18 unless $curuser->access_right('Edit package definitions')
19 || $curuser->access_right('Edit global package definitions')
20 || ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
22 my $precheck_callback = sub {
25 my $conf = new FS::Conf;
27 foreach (qw( setuptax recurtax disabled )) {
28 $cgi->param($_, '') unless defined $cgi->param($_);
31 return 'Must select a tax class'
32 if $cgi->param('taxclass') eq '(select)';
35 foreach ($cgi->param('agent_type')) {
37 push @agents, $1 if $1;
39 return "At least one agent type must be specified."
40 unless( scalar(@agents) ||
41 $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ ||
42 !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg')
51 my $args_callback = sub {
52 my( $cgi, $new ) = @_;
54 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
60 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
63 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
64 my $href = $plans{$plan}->{'fields'};
67 my $options = $cgi->param($plan."__OPTIONS");
68 my @options = split(',', $options);
70 map { my $optionname = $_;
71 my $param = $plan."__$optionname";
72 my $parser = exists($href->{$optionname}{parse})
73 ? $href->{$optionname}{parse}
75 my $value = join(', ', &$parser($cgi->param($param)));
76 my $check = $href->{$optionname}{check};
77 if ( $check && ! &$check($value) ) {
78 $value = join(', ', $cgi->param($param));
79 $error ||= "Illegal ".
80 ($href->{$optionname}{name}||$optionname). ": $value";
82 ( $optionname => $value );
86 $options{$_} = scalar( $cgi->param($_) )
87 for (qw( setup_fee recur_fee ));
89 push @args, 'options' => \%options;
95 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
97 qsearch('part_svc', {} );
99 push @args, 'pkg_svc' => \%pkg_svc;
102 # cust_pkg and custnum_ref (inserts only)
104 unless ( $cgi->param('pkgpart') ) {
105 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
106 'custnum_ref' => \$custnum;
113 #these should probably move to @args above and be processed by part_pkg.pm...
115 $cgi->param('tax_override') =~ /^([\d,]+)$/;
116 my (@tax_overrides) = (grep "$_", split (",", $1));
120 'link_table' => 'part_pkg_taxoverride',
121 'target_table' => 'tax_class',
122 'params' => \@tax_overrides,
124 { 'link_table' => 'part_pkg_link',
125 'target_table' => 'part_pkg',
126 'base_field' => 'src_pkgpart',
127 'target_field' => 'dst_pkgpart',
128 'hashref' => { 'link_type' => 'bill' },
129 'params' => [ map $cgi->param($_), grep /^bill_dst_pkgpart/, $cgi->param ],
131 { 'link_table' => 'part_pkg_link',
132 'target_table' => 'part_pkg',
133 'base_field' => 'src_pkgpart',
134 'target_field' => 'dst_pkgpart',
135 'hashref' => { 'link_type' => 'svc' },
136 'params' => [ map $cgi->param($_), grep /^svc_dst_pkgpart/, $cgi->param ],
140 my $conf = new FS::Conf;
142 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
144 foreach ($cgi->param('agent_type')) {
146 push @agents, $1 if $1;
149 'link_table' => 'type_pkgs',
150 'target_table' => 'agent_type',
151 'params' => \@agents,