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,
17 my $customizing = ( ! $cgi->param('pkgpart') && $cgi->param('pkgnum') );
19 my $curuser = $FS::CurrentUser::CurrentUser;
21 my $edit_global = 'Edit global package definitions';
22 my $customize = 'Customize customer package';
25 unless $curuser->access_right('Edit package definitions')
26 || $curuser->access_right($edit_global)
27 || ( $customizing && $curuser->access_right($customize) );
29 my @agent_null_right = ( $edit_global );
30 push @agent_null_right, $customize if $customizing;
33 my $precheck_callback = sub {
36 my $conf = new FS::Conf;
38 foreach (qw( setuptax recurtax disabled )) {
39 $cgi->param($_, '') unless defined $cgi->param($_);
42 return 'Must select a tax class'
43 if $cgi->param('taxclass') eq '(select)';
46 foreach ($cgi->param('agent_type')) {
48 push @agents, $1 if $1;
50 return "At least one agent type must be specified."
51 unless scalar(@agents)
52 || ( $cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ )
53 || ( !$cgi->param('pkgpart') && $conf->exists('agent-defaultpkg') )
54 || $cgi->param('disabled')
55 || $cgi->param('agentnum');
63 my $args_callback = sub {
64 my( $cgi, $new ) = @_;
66 my @args = ( 'primary_svc' => scalar($cgi->param('pkg_svc_primary')) );
72 $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan';
75 tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
76 my $href = $plans{$plan}->{'fields'};
79 my $options = $cgi->param($plan."__OPTIONS");
80 my @options = split(',', $options);
82 map { my $optionname = $_;
83 my $param = $plan."__$optionname";
84 my $parser = exists($href->{$optionname}{parse})
85 ? $href->{$optionname}{parse}
87 my $value = join(', ', &$parser($cgi->param($param)));
88 my $check = $href->{$optionname}{check};
89 if ( $check && ! &$check($value) ) {
90 $value = join(', ', $cgi->param($param));
91 $error ||= "Illegal ".
92 ($href->{$optionname}{name}||$optionname). ": $value";
94 ( $optionname => $value );
96 grep { $_ !~ /^report_option_/ }
99 foreach ( split(',', $cgi->param('taxproductnums') ) ) {
100 my $value = $cgi->param("taxproductnum_$_");
101 $error ||= "Illegal taxproductnum_$_: $value"
102 unless ( $value =~ /^\d*$/ );
103 $options{"usage_taxproductnum_$_"} = $value;
106 foreach ( grep $_, $cgi->param('report_option') ) {
107 $error ||= "Illegal optional report class: $_" unless ( $_ =~ /^\d*$/ );
108 $options{"report_option_$_"} = 1;
111 $options{$_} = scalar( $cgi->param($_) )
112 for (qw( setup_fee recur_fee disable_line_item_date_ranges ));
114 push @args, 'options' => \%options;
120 my @svcparts = map { $_->svcpart } qsearch('part_svc', {});
121 my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) } @svcparts;
122 my %hidden_svc = map { $_ => scalar($cgi->param("hidden$_")) } @svcparts;
124 push @args, 'pkg_svc' => \%pkg_svc, 'hidden_svc' => \%hidden_svc;
127 # cust_pkg and custnum_ref (inserts only)
129 unless ( $cgi->param('pkgpart') ) {
130 push @args, 'cust_pkg' => scalar($cgi->param('pkgnum')),
131 'custnum_ref' => \$custnum;
135 foreach my $param ( $cgi->param ) {
136 if ( $param =~ /^export(\d+)$/ && length($cgi->param($param)) > 0 ) {
137 $part_pkg_vendor{$1} = $cgi->param($param);
140 if ( keys %part_pkg_vendor > 0 ) {
141 push @args, 'part_pkg_vendor' => \%part_pkg_vendor;
144 #warn "args: ".join('/', @args). "\n";
150 my $redirect_callback = sub {
151 #my( $cgi, $new ) = @_;
152 return '' unless $custnum;
153 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
156 #my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
158 #can we link back to the specific customized package? it would be nice...
159 popurl(3). "view/cust_main.cgi?custnum=$custnum$show;dummy=";
162 #these should probably move to @args above and be processed by part_pkg.pm...
164 $cgi->param('tax_override') =~ /^([\d,]+)$/;
165 my (@tax_overrides) = (grep "$_", split (",", $1));
169 'link_table' => 'part_pkg_taxoverride',
170 'target_table' => 'tax_class',
171 'params' => \@tax_overrides,
173 { 'link_table' => 'part_pkg_discount',
174 'target_table' => 'discount',
175 'params' => [ map $cgi->param($_),
176 grep /^discountnum/, $cgi->param
179 { 'link_table' => 'part_pkg_link',
180 'target_table' => 'part_pkg',
181 'base_field' => 'src_pkgpart',
182 'target_field' => 'dst_pkgpart',
183 'hashref' => { 'link_type' => 'svc', 'hidden' => '' },
184 'params' => [ map $cgi->param($_),
185 grep /^svc_dst_pkgpart/, $cgi->param
188 { 'link_table' => 'part_pkg_link',
189 'target_table' => 'part_pkg',
190 'base_field' => 'src_pkgpart',
191 'target_field' => 'dst_pkgpart',
192 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
193 'params' => [ map $cgi->param($_),
194 grep /^supp_dst_pkgpart/, $cgi->param
199 { 'link_table' => 'part_pkg_link',
200 'target_table' => 'part_pkg',
201 'base_field' => 'src_pkgpart',
202 'target_field' => 'dst_pkgpart',
203 'hashref' => { 'link_type' => 'bill', 'hidden' => $hidden },
204 'params' => [ map { $cgi->param($_) }
205 grep { my $param = "bill_dst_pkgpart__hidden";
207 (($digit) = /^bill_dst_pkgpart(\d+)/ ) &&
208 $cgi->param("$param$digit") eq $hidden;
216 foreach my $override_class ($cgi->param) {
217 next unless $override_class =~ /^tax_override_(\w+)$/;
220 my (@tax_overrides) = (grep "$_", split (",", $1))
221 if $cgi->param($override_class) =~ /^([\d,]+)$/;
224 'link_table' => 'part_pkg_taxoverride',
225 'target_table' => 'tax_class',
226 'hashref' => { 'usage_class' => $class },
227 'params' => [ @tax_overrides ],
232 my $conf = new FS::Conf;
234 if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
236 foreach ($cgi->param('agent_type')) {
238 push @agents, $1 if $1;
241 'link_table' => 'type_pkgs',
242 'target_table' => 'agent_type',
243 'params' => \@agents,