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 $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;
110 warn "args: ".join('/', @args). "\n";
116 my $redirect_callback = sub {
117 #my( $cgi, $new ) = @_;
118 return '' unless $custnum;
119 popurl(3). "view/cust_main.cgi?keywords=$custnum;dummy=";
122 #these should probably move to @args above and be processed by part_pkg.pm...
124 $cgi->param('tax_override') =~ /^([\d,]+)$/;
125 my (@tax_overrides) = (grep "$_", split (",", $1));
129 'link_table' => 'part_pkg_taxoverride',
130 'target_table' => 'tax_class',
131 'params' => \@tax_overrides,
133 { 'link_table' => 'part_pkg_link',
134 'target_table' => 'part_pkg',
135 'base_field' => 'src_pkgpart',
136 'target_field' => 'dst_pkgpart',
137 'hashref' => { 'link_type' => 'bill' },
138 'params' => [ map $cgi->param($_), grep /^bill_dst_pkgpart/, $cgi->param ],
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' => 'svc' },
145 'params' => [ map $cgi->param($_), grep /^svc_dst_pkgpart/, $cgi->param ],
149 my $conf = new FS::Conf;
151 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
153 foreach ($cgi->param('agent_type')) {
155 push @agents, $1 if $1;
158 'link_table' => 'type_pkgs',
159 'target_table' => 'agent_type',
160 'params' => \@agents,