1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
%if ( $error ) {
% $dbh->rollback if $oldAutoCommit;
% $cgi->param('error', $error );
<% $cgi->redirect(popurl(2). "part_pkg.cgi?". $cgi->query_string ) %>
%} elsif ( $custnum ) {
% $dbh->commit or die $dbh->errstr if $oldAutoCommit;
<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
%} else {
% $dbh->commit or die $dbh->errstr if $oldAutoCommit;
<% $cgi->redirect(popurl(3). "browse/part_pkg.cgi") %>
%}
<%init>
my $dbh = dbh;
my $conf = new FS::Conf;
my $pkgpart = $cgi->param('pkgpart');
my $old = qsearchs('part_pkg',{'pkgpart'=>$pkgpart}) if $pkgpart;
tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
my $href = $plans{$cgi->param('plan')}->{'fields'};
#fixup plandata
my $error;
my $plandata = $cgi->param('plandata');
my @plandata = split(',', $plandata);
$cgi->param('plandata',
join('', map { my $parser = sub { shift };
$parser = $href->{$_}{parse} if exists($href->{$_}{parse});
my $value = join(', ', &$parser($cgi->param($_)));
my $check = $href->{$_}{check};
if ( $check && ! &$check($value) ) {
$value = join(', ', $cgi->param($_));
$error ||= "Illegal ". ($href->{$_}{name}||$_). ": $value";
}
"$_=$value\n";
} @plandata )
);
foreach (qw( setuptax recurtax disabled )) {
$cgi->param($_, '') unless defined $cgi->param($_);
}
my @agents;
foreach ($cgi->param('agent_type')) {
/^(\d+)$/;
push @agents, $1 if $1;
}
$error = "At least one agent type must be specified."
unless( scalar(@agents) ||
$cgi->param('clone') && $cgi->param('clone') =~ /^\d+$/ ||
!$pkgpart && $conf->exists('agent-defaultpkg')
);
my $new = new FS::part_pkg ( {
map {
$_ => scalar($cgi->param($_));
} fields('part_pkg')
} );
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my %pkg_svc = map { $_ => scalar($cgi->param("pkg_svc$_")) }
map { $_->svcpart }
qsearch('part_svc', {} );
my $curuser = $FS::CurrentUser::CurrentUser;
my $custnum = '';
if ( $error ) {
# fall through
} elsif ( $cgi->param('taxclass') eq '(select)' ) {
$error = 'Must select a tax class';
} elsif ( $pkgpart ) {
die "access denied"
unless $curuser->access_right('Edit package definitions')
|| $curuser->access_right('Edit global package definitions');
$error = $new->replace( $old,
pkg_svc => \%pkg_svc,
primary_svc => scalar($cgi->param('pkg_svc_primary')),
);
} else {
die "access denied"
unless $curuser->access_right('Edit package definitions')
|| $curuser->access_right('Edit global package definitions')
|| ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
$error = $new->insert( pkg_svc => \%pkg_svc,
primary_svc => scalar($cgi->param('pkg_svc_primary')),
cust_pkg => $cgi->param('pkgnum'),
custnum_ref => \$custnum,
);
$pkgpart = $new->pkgpart;
}
unless ( $error || $conf->exists('agent_defaultpkg') ) {
my $error = $new->process_m2m(
'link_table' => 'type_pkgs',
'target_table' => 'agent_type',
'params' => \@agents,
);
}
</%init>
|