Lines 51-98
use C4::Templates;
Link Here
|
51 |
use Koha::Borrower::Debarments; |
51 |
use Koha::Borrower::Debarments; |
52 |
|
52 |
|
53 |
use Text::CSV; |
53 |
use Text::CSV; |
|
|
54 |
|
54 |
# Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: |
55 |
# Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: |
55 |
# ė |
56 |
# ė |
56 |
# č |
57 |
# č |
57 |
|
58 |
|
58 |
use CGI qw ( -utf8 ); |
59 |
use CGI qw ( -utf8 ); |
|
|
60 |
|
59 |
# use encoding 'utf8'; # don't do this |
61 |
# use encoding 'utf8'; # don't do this |
60 |
|
62 |
|
61 |
my (@errors, @feedback); |
63 |
my ( @errors, @feedback ); |
62 |
my $extended = C4::Context->preference('ExtendedPatronAttributes'); |
64 |
my $extended = C4::Context->preference('ExtendedPatronAttributes'); |
63 |
my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); |
65 |
my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); |
64 |
my @columnkeys = C4::Members::columns(); |
66 |
my @columnkeys = C4::Members::columns(); |
65 |
@columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } @columnkeys; |
67 |
@columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } @columnkeys; |
66 |
if ($extended) { |
68 |
if ($extended) { |
67 |
push @columnkeys, 'patron_attributes'; |
69 |
push @columnkeys, 'patron_attributes'; |
68 |
} |
70 |
} |
69 |
|
71 |
|
70 |
my $input = CGI->new(); |
72 |
my $input = CGI->new(); |
71 |
our $csv = Text::CSV->new({binary => 1}); # binary needed for non-ASCII Unicode |
73 |
our $csv = Text::CSV->new( { binary => 1 } ); # binary needed for non-ASCII Unicode |
|
|
74 |
|
72 |
#push @feedback, {feedback=>1, name=>'backend', value=>$csv->backend, backend=>$csv->backend}; #XXX |
75 |
#push @feedback, {feedback=>1, name=>'backend', value=>$csv->backend, backend=>$csv->backend}; #XXX |
73 |
|
76 |
|
74 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ |
77 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
|
|
78 |
{ |
75 |
template_name => "tools/import_borrowers.tt", |
79 |
template_name => "tools/import_borrowers.tt", |
76 |
query => $input, |
80 |
query => $input, |
77 |
type => "intranet", |
81 |
type => "intranet", |
78 |
authnotrequired => 0, |
82 |
authnotrequired => 0, |
79 |
flagsrequired => { tools => 'import_patrons' }, |
83 |
flagsrequired => { tools => 'import_patrons' }, |
80 |
debug => 1, |
84 |
debug => 1, |
81 |
}); |
85 |
} |
|
|
86 |
); |
82 |
|
87 |
|
83 |
# get the branches and pass them to the template |
88 |
# get the branches and pass them to the template |
84 |
my $branches = GetBranchesLoop(); |
89 |
my $branches = GetBranchesLoop(); |
85 |
$template->param( branches => $branches ) if ( $branches ); |
90 |
$template->param( branches => $branches ) if ($branches); |
|
|
91 |
|
86 |
# get the patron categories and pass them to the template |
92 |
# get the patron categories and pass them to the template |
87 |
my $categories = GetBorrowercategoryList(); |
93 |
my $categories = GetBorrowercategoryList(); |
88 |
$template->param( categories => $categories ) if ( $categories ); |
94 |
$template->param( categories => $categories ) if ($categories); |
89 |
my $columns = C4::Templates::GetColumnDefs( $input )->{borrowers}; |
95 |
my $columns = C4::Templates::GetColumnDefs($input)->{borrowers}; |
90 |
$columns = [ grep { $_->{field} ne 'borrowernumber' ? $_ : () } @$columns ]; |
96 |
$columns = [ grep { $_->{field} ne 'borrowernumber' ? $_ : () } @$columns ]; |
91 |
$template->param( borrower_fields => $columns ); |
97 |
$template->param( borrower_fields => $columns ); |
92 |
|
98 |
|
93 |
if ($input->param('sample')) { |
99 |
if ( $input->param('sample') ) { |
94 |
print $input->header( |
100 |
print $input->header( |
95 |
-type => 'application/vnd.sun.xml.calc', # 'application/vnd.ms-excel' ? |
101 |
-type => 'application/vnd.sun.xml.calc', # 'application/vnd.ms-excel' ? |
96 |
-attachment => 'patron_import.csv', |
102 |
-attachment => 'patron_import.csv', |
97 |
); |
103 |
); |
98 |
$csv->combine(@columnkeys); |
104 |
$csv->combine(@columnkeys); |
Lines 109-230
my $overwrite_cardnumber = $input->param('overwrite_cardnumber');
Link Here
|
109 |
$template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'} ); |
115 |
$template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'} ); |
110 |
|
116 |
|
111 |
if ( $uploadborrowers && length($uploadborrowers) > 0 ) { |
117 |
if ( $uploadborrowers && length($uploadborrowers) > 0 ) { |
112 |
push @feedback, {feedback=>1, name=>'filename', value=>$uploadborrowers, filename=>$uploadborrowers}; |
118 |
push @feedback, { feedback => 1, name => 'filename', value => $uploadborrowers, filename => $uploadborrowers }; |
113 |
my $handle = $input->upload('uploadborrowers'); |
119 |
my $handle = $input->upload('uploadborrowers'); |
114 |
my $uploadinfo = $input->uploadInfo($uploadborrowers); |
120 |
my $uploadinfo = $input->uploadInfo($uploadborrowers); |
115 |
foreach (keys %$uploadinfo) { |
121 |
foreach ( keys %$uploadinfo ) { |
116 |
push @feedback, {feedback=>1, name=>$_, value=>$uploadinfo->{$_}, $_=>$uploadinfo->{$_}}; |
122 |
push @feedback, { feedback => 1, name => $_, value => $uploadinfo->{$_}, $_ => $uploadinfo->{$_} }; |
117 |
} |
123 |
} |
118 |
my $imported = 0; |
124 |
my $imported = 0; |
119 |
my $alreadyindb = 0; |
125 |
my $alreadyindb = 0; |
120 |
my $overwritten = 0; |
126 |
my $overwritten = 0; |
121 |
my $invalid = 0; |
127 |
my $invalid = 0; |
122 |
my $matchpoint_attr_type; |
128 |
my $matchpoint_attr_type; |
123 |
my %defaults = $input->Vars; |
129 |
my %defaults = $input->Vars; |
124 |
|
130 |
|
125 |
# use header line to construct key to column map |
131 |
# use header line to construct key to column map |
126 |
my $borrowerline = <$handle>; |
132 |
my $borrowerline = <$handle>; |
127 |
my $status = $csv->parse($borrowerline); |
133 |
my $status = $csv->parse($borrowerline); |
128 |
($status) or push @errors, {badheader=>1,line=>$., lineraw=>$borrowerline}; |
134 |
($status) or push @errors, { badheader => 1, line => $., lineraw => $borrowerline }; |
129 |
my @csvcolumns = $csv->fields(); |
135 |
my @csvcolumns = $csv->fields(); |
130 |
my %csvkeycol; |
136 |
my %csvkeycol; |
131 |
my $col = 0; |
137 |
my $col = 0; |
132 |
foreach my $keycol (@csvcolumns) { |
138 |
foreach my $keycol (@csvcolumns) { |
133 |
# columnkeys don't contain whitespace, but some stupid tools add it |
139 |
|
134 |
$keycol =~ s/ +//g; |
140 |
# columnkeys don't contain whitespace, but some stupid tools add it |
|
|
141 |
$keycol =~ s/ +//g; |
135 |
$csvkeycol{$keycol} = $col++; |
142 |
$csvkeycol{$keycol} = $col++; |
136 |
} |
143 |
} |
|
|
144 |
|
137 |
#warn($borrowerline); |
145 |
#warn($borrowerline); |
138 |
my $ext_preserve = $input->param('ext_preserve') || 0; |
146 |
my $ext_preserve = $input->param('ext_preserve') || 0; |
139 |
if ($extended) { |
147 |
if ($extended) { |
140 |
$matchpoint_attr_type = C4::Members::AttributeTypes->fetch($matchpoint); |
148 |
$matchpoint_attr_type = C4::Members::AttributeTypes->fetch($matchpoint); |
141 |
} |
149 |
} |
142 |
|
150 |
|
143 |
push @feedback, {feedback=>1, name=>'headerrow', value=>join(', ', @csvcolumns)}; |
151 |
push @feedback, { feedback => 1, name => 'headerrow', value => join( ', ', @csvcolumns ) }; |
144 |
my $today_iso = C4::Dates->new()->output('iso'); |
152 |
my $today_iso = C4::Dates->new()->output('iso'); |
145 |
my @criticals = qw(surname branchcode categorycode); # there probably should be others |
153 |
my @criticals = qw(surname branchcode categorycode); # there probably should be others |
146 |
my @bad_dates; # I've had a few. |
154 |
my @bad_dates; # I've had a few. |
147 |
my $date_re = C4::Dates->new->regexp('syspref'); |
155 |
my $date_re = C4::Dates->new->regexp('syspref'); |
148 |
my $iso_re = C4::Dates->new->regexp('iso'); |
156 |
my $iso_re = C4::Dates->new->regexp('iso'); |
149 |
LINE: while ( my $borrowerline = <$handle> ) { |
157 |
LINE: while ( my $borrowerline = <$handle> ) { |
150 |
my %borrower; |
158 |
my %borrower; |
151 |
my @missing_criticals; |
159 |
my @missing_criticals; |
152 |
my $patron_attributes; |
160 |
my $patron_attributes; |
153 |
my $status = $csv->parse($borrowerline); |
161 |
my $status = $csv->parse($borrowerline); |
154 |
my @columns = $csv->fields(); |
162 |
my @columns = $csv->fields(); |
155 |
if (! $status) { |
163 |
if ( !$status ) { |
156 |
push @missing_criticals, {badparse=>1, line=>$., lineraw=>$borrowerline}; |
164 |
push @missing_criticals, { badparse => 1, line => $., lineraw => $borrowerline }; |
157 |
} elsif (@columns == @columnkeys) { |
165 |
} |
|
|
166 |
elsif ( @columns == @columnkeys ) { |
158 |
@borrower{@columnkeys} = @columns; |
167 |
@borrower{@columnkeys} = @columns; |
|
|
168 |
|
159 |
# MJR: try to fill blanks gracefully by using default values |
169 |
# MJR: try to fill blanks gracefully by using default values |
160 |
foreach my $key (@columnkeys) { |
170 |
foreach my $key (@columnkeys) { |
161 |
if ($borrower{$key} !~ /\S/) { |
171 |
if ( $borrower{$key} !~ /\S/ ) { |
162 |
$borrower{$key} = $defaults{$key}; |
172 |
$borrower{$key} = $defaults{$key}; |
163 |
} |
173 |
} |
164 |
} |
174 |
} |
165 |
} else { |
175 |
} |
|
|
176 |
else { |
166 |
# MJR: try to recover gracefully by using default values |
177 |
# MJR: try to recover gracefully by using default values |
167 |
foreach my $key (@columnkeys) { |
178 |
foreach my $key (@columnkeys) { |
168 |
if (defined($csvkeycol{$key}) and $columns[$csvkeycol{$key}] =~ /\S/) { |
179 |
if ( defined( $csvkeycol{$key} ) and $columns[ $csvkeycol{$key} ] =~ /\S/ ) { |
169 |
$borrower{$key} = $columns[$csvkeycol{$key}]; |
180 |
$borrower{$key} = $columns[ $csvkeycol{$key} ]; |
170 |
} elsif ( $defaults{$key} ) { |
181 |
} |
171 |
$borrower{$key} = $defaults{$key}; |
182 |
elsif ( $defaults{$key} ) { |
172 |
} elsif ( scalar grep {$key eq $_} @criticals ) { |
183 |
$borrower{$key} = $defaults{$key}; |
173 |
# a critical field is undefined |
184 |
} |
174 |
push @missing_criticals, {key=>$key, line=>$., lineraw=>$borrowerline}; |
185 |
elsif ( scalar grep { $key eq $_ } @criticals ) { |
175 |
} else { |
186 |
|
176 |
$borrower{$key} = ''; |
187 |
# a critical field is undefined |
177 |
} |
188 |
push @missing_criticals, { key => $key, line => $., lineraw => $borrowerline }; |
|
|
189 |
} |
190 |
else { |
191 |
$borrower{$key} = ''; |
192 |
} |
178 |
} |
193 |
} |
179 |
} |
194 |
} |
|
|
195 |
|
180 |
#warn join(':',%borrower); |
196 |
#warn join(':',%borrower); |
181 |
if ($borrower{categorycode}) { |
197 |
if ( $borrower{categorycode} ) { |
182 |
push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline, value=>$borrower{categorycode}, category_map=>1} |
198 |
push @missing_criticals, |
183 |
unless GetBorrowercategory($borrower{categorycode}); |
199 |
{ |
184 |
} else { |
200 |
key => 'categorycode', |
185 |
push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline}; |
201 |
line => $., |
|
|
202 |
lineraw => $borrowerline, |
203 |
value => $borrower{categorycode}, |
204 |
category_map => 1 |
205 |
} |
206 |
unless GetBorrowercategory( $borrower{categorycode} ); |
207 |
} |
208 |
else { |
209 |
push @missing_criticals, { key => 'categorycode', line => $., lineraw => $borrowerline }; |
186 |
} |
210 |
} |
187 |
if ($borrower{branchcode}) { |
211 |
if ( $borrower{branchcode} ) { |
188 |
push @missing_criticals, {key=>'branchcode', line=>$. , lineraw=>$borrowerline, value=>$borrower{branchcode}, branch_map=>1} |
212 |
push @missing_criticals, |
189 |
unless GetBranchName($borrower{branchcode}); |
213 |
{ |
190 |
} else { |
214 |
key => 'branchcode', |
191 |
push @missing_criticals, {key=>'branchcode', line=>$. , lineraw=>$borrowerline}; |
215 |
line => $., |
|
|
216 |
lineraw => $borrowerline, |
217 |
value => $borrower{branchcode}, |
218 |
branch_map => 1 |
219 |
} |
220 |
unless GetBranchName( $borrower{branchcode} ); |
221 |
} |
222 |
else { |
223 |
push @missing_criticals, { key => 'branchcode', line => $., lineraw => $borrowerline }; |
192 |
} |
224 |
} |
193 |
if (@missing_criticals) { |
225 |
if (@missing_criticals) { |
194 |
foreach (@missing_criticals) { |
226 |
foreach (@missing_criticals) { |
195 |
$_->{borrowernumber} = $borrower{borrowernumber} || 'UNDEF'; |
227 |
$_->{borrowernumber} = $borrower{borrowernumber} || 'UNDEF'; |
196 |
$_->{surname} = $borrower{surname} || 'UNDEF'; |
228 |
$_->{surname} = $borrower{surname} || 'UNDEF'; |
197 |
} |
229 |
} |
198 |
$invalid++; |
230 |
$invalid++; |
199 |
(25 > scalar @errors) and push @errors, {missing_criticals=>\@missing_criticals}; |
231 |
( 25 > scalar @errors ) and push @errors, { missing_criticals => \@missing_criticals }; |
|
|
232 |
|
200 |
# The first 25 errors are enough. Keeping track of 30,000+ would destroy performance. |
233 |
# The first 25 errors are enough. Keeping track of 30,000+ would destroy performance. |
201 |
next LINE; |
234 |
next LINE; |
202 |
} |
235 |
} |
203 |
if ($extended) { |
236 |
if ($extended) { |
204 |
my $attr_str = $borrower{patron_attributes}; |
237 |
my $attr_str = $borrower{patron_attributes}; |
205 |
$attr_str =~ s/\xe2\x80\x9c/"/g; # fixup double quotes in case we are passed smart quotes |
238 |
$attr_str =~ s/\xe2\x80\x9c/"/g; # fixup double quotes in case we are passed smart quotes |
206 |
$attr_str =~ s/\xe2\x80\x9d/"/g; |
239 |
$attr_str =~ s/\xe2\x80\x9d/"/g; |
207 |
push @feedback, {feedback=>1, name=>'attribute string', value=>$attr_str, filename=>$uploadborrowers}; |
240 |
push @feedback, |
208 |
delete $borrower{patron_attributes}; # not really a field in borrowers, so we don't want to pass it to ModMember. |
241 |
{ feedback => 1, name => 'attribute string', value => $attr_str, filename => $uploadborrowers }; |
209 |
$patron_attributes = extended_attributes_code_value_arrayref($attr_str); |
242 |
delete $borrower{patron_attributes} |
|
|
243 |
; # not really a field in borrowers, so we don't want to pass it to ModMember. |
244 |
$patron_attributes = extended_attributes_code_value_arrayref($attr_str); |
210 |
} |
245 |
} |
211 |
# Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it. |
246 |
|
|
|
247 |
# Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it. |
212 |
foreach (qw(dateofbirth dateenrolled dateexpiry)) { |
248 |
foreach (qw(dateofbirth dateenrolled dateexpiry)) { |
213 |
my $tempdate = $borrower{$_} or next; |
249 |
my $tempdate = $borrower{$_} or next; |
214 |
if ($tempdate =~ /$date_re/) { |
250 |
if ( $tempdate =~ /$date_re/ ) { |
215 |
$borrower{$_} = format_date_in_iso($tempdate); |
251 |
$borrower{$_} = format_date_in_iso($tempdate); |
216 |
} elsif ($tempdate =~ /$iso_re/) { |
252 |
} |
|
|
253 |
elsif ( $tempdate =~ /$iso_re/ ) { |
217 |
$borrower{$_} = $tempdate; |
254 |
$borrower{$_} = $tempdate; |
218 |
} else { |
255 |
} |
|
|
256 |
else { |
219 |
$borrower{$_} = ''; |
257 |
$borrower{$_} = ''; |
220 |
push @missing_criticals, {key=>$_, line=>$. , lineraw=>$borrowerline, bad_date=>1}; |
258 |
push @missing_criticals, { key => $_, line => $., lineraw => $borrowerline, bad_date => 1 }; |
221 |
} |
259 |
} |
222 |
} |
260 |
} |
223 |
$borrower{dateenrolled} = $today_iso unless $borrower{dateenrolled}; |
261 |
$borrower{dateenrolled} = $today_iso unless $borrower{dateenrolled}; |
224 |
$borrower{dateexpiry} = GetExpiryDate($borrower{categorycode},$borrower{dateenrolled}) unless $borrower{dateexpiry}; |
262 |
$borrower{dateexpiry} = GetExpiryDate( $borrower{categorycode}, $borrower{dateenrolled} ) |
|
|
263 |
unless $borrower{dateexpiry}; |
225 |
my $borrowernumber; |
264 |
my $borrowernumber; |
226 |
my $member; |
265 |
my $member; |
227 |
if ( ($matchpoint eq 'cardnumber') && ($borrower{'cardnumber'}) ) { |
266 |
if ( ( $matchpoint eq 'cardnumber' ) && ( $borrower{'cardnumber'} ) ) { |
228 |
$member = GetMember( 'cardnumber' => $borrower{'cardnumber'} ); |
267 |
$member = GetMember( 'cardnumber' => $borrower{'cardnumber'} ); |
229 |
if ($member) { |
268 |
if ($member) { |
230 |
$borrowernumber = $member->{'borrowernumber'}; |
269 |
$borrowernumber = $member->{'borrowernumber'}; |
Lines 237-244
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
237 |
} elsif ($extended) { |
276 |
} elsif ($extended) { |
238 |
if (defined($matchpoint_attr_type)) { |
277 |
if (defined($matchpoint_attr_type)) { |
239 |
foreach my $attr (@$patron_attributes) { |
278 |
foreach my $attr (@$patron_attributes) { |
240 |
if ($attr->{code} eq $matchpoint and $attr->{value} ne '') { |
279 |
if ( $attr->{code} eq $matchpoint and $attr->{value} ne '' ) { |
241 |
my @borrowernumbers = $matchpoint_attr_type->get_patrons($attr->{value}); |
280 |
my @borrowernumbers = $matchpoint_attr_type->get_patrons( $attr->{value} ); |
242 |
$borrowernumber = $borrowernumbers[0] if scalar(@borrowernumbers) == 1; |
281 |
$borrowernumber = $borrowernumbers[0] if scalar(@borrowernumbers) == 1; |
243 |
last; |
282 |
last; |
244 |
} |
283 |
} |
Lines 247-289
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
247 |
} |
286 |
} |
248 |
|
287 |
|
249 |
if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) { |
288 |
if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) { |
250 |
push @errors, { |
289 |
push @errors, |
|
|
290 |
{ |
251 |
invalid_cardnumber => 1, |
291 |
invalid_cardnumber => 1, |
252 |
borrowernumber => $borrowernumber, |
292 |
borrowernumber => $borrowernumber, |
253 |
cardnumber => $borrower{cardnumber} |
293 |
cardnumber => $borrower{cardnumber} |
254 |
}; |
294 |
}; |
255 |
$invalid++; |
295 |
$invalid++; |
256 |
next; |
296 |
next; |
257 |
} |
297 |
} |
258 |
|
298 |
|
259 |
|
|
|
260 |
if ($borrowernumber) { |
299 |
if ($borrowernumber) { |
|
|
300 |
|
261 |
# borrower exists |
301 |
# borrower exists |
262 |
unless ($overwrite_cardnumber) { |
302 |
unless ($overwrite_cardnumber) { |
263 |
$alreadyindb++; |
303 |
$alreadyindb++; |
264 |
$template->param('lastalreadyindb'=>$borrower{'surname'}.' / '.$borrowernumber); |
304 |
$template->param( 'lastalreadyindb' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
265 |
next LINE; |
305 |
next LINE; |
266 |
} |
306 |
} |
267 |
$borrower{'borrowernumber'} = $borrowernumber; |
307 |
$borrower{'borrowernumber'} = $borrowernumber; |
268 |
for my $col (keys %borrower) { |
308 |
for my $col ( keys %borrower ) { |
|
|
309 |
|
269 |
# use values from extant patron unless our csv file includes this column or we provided a default. |
310 |
# use values from extant patron unless our csv file includes this column or we provided a default. |
270 |
# FIXME : You cannot update a field with a perl-evaluated false value using the defaults. |
311 |
# FIXME : You cannot update a field with a perl-evaluated false value using the defaults. |
271 |
|
312 |
|
272 |
# The password is always encrypted, skip it! |
313 |
# The password is always encrypted, skip it! |
273 |
next if $col eq 'password'; |
314 |
next if $col eq 'password'; |
274 |
|
315 |
|
275 |
unless(exists($csvkeycol{$col}) || $defaults{$col}) { |
316 |
unless ( exists( $csvkeycol{$col} ) || $defaults{$col} ) { |
276 |
$borrower{$col} = $member->{$col} if($member->{$col}) ; |
317 |
$borrower{$col} = $member->{$col} if ( $member->{$col} ); |
277 |
} |
318 |
} |
278 |
} |
319 |
} |
279 |
unless (ModMember(%borrower)) { |
320 |
unless ( ModMember(%borrower) ) { |
280 |
$invalid++; |
321 |
$invalid++; |
|
|
322 |
|
281 |
# untill we have better error trapping, we have no way of knowing why ModMember errored out... |
323 |
# untill we have better error trapping, we have no way of knowing why ModMember errored out... |
282 |
push @errors, {unknown_error => 1}; |
324 |
push @errors, { unknown_error => 1 }; |
283 |
$template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber); |
325 |
$template->param( 'lastinvalid' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
284 |
next LINE; |
326 |
next LINE; |
285 |
} |
327 |
} |
286 |
if ( $borrower{debarred} ) { |
328 |
if ( $borrower{debarred} ) { |
|
|
329 |
|
287 |
# Check to see if this debarment already exists |
330 |
# Check to see if this debarment already exists |
288 |
my $debarrments = GetDebarments( |
331 |
my $debarrments = GetDebarments( |
289 |
{ |
332 |
{ |
Lines 292-297
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
292 |
comment => $borrower{debarredcomment} |
335 |
comment => $borrower{debarredcomment} |
293 |
} |
336 |
} |
294 |
); |
337 |
); |
|
|
338 |
|
295 |
# If it doesn't, then add it! |
339 |
# If it doesn't, then add it! |
296 |
unless (@$debarrments) { |
340 |
unless (@$debarrments) { |
297 |
AddDebarment( |
341 |
AddDebarment( |
Lines 306-324
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
306 |
if ($extended) { |
350 |
if ($extended) { |
307 |
if ($ext_preserve) { |
351 |
if ($ext_preserve) { |
308 |
my $old_attributes = GetBorrowerAttributes($borrowernumber); |
352 |
my $old_attributes = GetBorrowerAttributes($borrowernumber); |
309 |
$patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes); #TODO: expose repeatable options in template |
353 |
$patron_attributes = extended_attributes_merge( $old_attributes, $patron_attributes ) |
|
|
354 |
; #TODO: expose repeatable options in template |
310 |
} |
355 |
} |
311 |
push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes); |
356 |
push @errors, { unknown_error => 1 } |
|
|
357 |
unless SetBorrowerAttributes( $borrower{'borrowernumber'}, $patron_attributes ); |
312 |
} |
358 |
} |
313 |
$overwritten++; |
359 |
$overwritten++; |
314 |
$template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber); |
360 |
$template->param( 'lastoverwritten' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
315 |
} else { |
361 |
} |
|
|
362 |
else { |
316 |
# FIXME: fixup_cardnumber says to lock table, but the web interface doesn't so this doesn't either. |
363 |
# FIXME: fixup_cardnumber says to lock table, but the web interface doesn't so this doesn't either. |
317 |
# At least this is closer to AddMember than in members/memberentry.pl |
364 |
# At least this is closer to AddMember than in members/memberentry.pl |
318 |
if (!$borrower{'cardnumber'}) { |
365 |
if ( !$borrower{'cardnumber'} ) { |
319 |
$borrower{'cardnumber'} = fixup_cardnumber(undef); |
366 |
$borrower{'cardnumber'} = fixup_cardnumber(undef); |
320 |
} |
367 |
} |
321 |
if ($borrowernumber = AddMember(%borrower)) { |
368 |
if ( $borrowernumber = AddMember(%borrower) ) { |
322 |
|
369 |
|
323 |
if ( $borrower{debarred} ) { |
370 |
if ( $borrower{debarred} ) { |
324 |
AddDebarment( |
371 |
AddDebarment( |
Lines 331-355
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
331 |
} |
378 |
} |
332 |
|
379 |
|
333 |
if ($extended) { |
380 |
if ($extended) { |
334 |
SetBorrowerAttributes($borrowernumber, $patron_attributes); |
381 |
SetBorrowerAttributes( $borrowernumber, $patron_attributes ); |
335 |
} |
382 |
} |
336 |
|
383 |
|
337 |
if ($set_messaging_prefs) { |
384 |
if ($set_messaging_prefs) { |
338 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults({ borrowernumber => $borrowernumber, |
385 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
339 |
categorycode => $borrower{categorycode} }); |
386 |
{ |
|
|
387 |
borrowernumber => $borrowernumber, |
388 |
categorycode => $borrower{categorycode} |
389 |
} |
390 |
); |
340 |
} |
391 |
} |
341 |
|
392 |
|
342 |
$imported++; |
393 |
$imported++; |
343 |
$template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber); |
394 |
$template->param( 'lastimported' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
344 |
} else { |
395 |
} |
|
|
396 |
else { |
345 |
$invalid++; |
397 |
$invalid++; |
346 |
push @errors, {unknown_error => 1}; |
398 |
push @errors, { unknown_error => 1 }; |
347 |
$template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember'); |
399 |
$template->param( 'lastinvalid' => $borrower{'surname'} . ' / AddMember' ); |
348 |
} |
400 |
} |
349 |
} |
401 |
} |
350 |
} |
402 |
} |
351 |
(@errors ) and $template->param( ERRORS=>\@errors ); |
403 |
(@errors) and $template->param( ERRORS => \@errors ); |
352 |
(@feedback) and $template->param(FEEDBACK=>\@feedback); |
404 |
(@feedback) and $template->param( FEEDBACK => \@feedback ); |
353 |
$template->param( |
405 |
$template->param( |
354 |
'uploadborrowers' => 1, |
406 |
'uploadborrowers' => 1, |
355 |
'imported' => $imported, |
407 |
'imported' => $imported, |
Lines 359-375
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
359 |
'total' => $imported + $alreadyindb + $invalid + $overwritten, |
411 |
'total' => $imported + $alreadyindb + $invalid + $overwritten, |
360 |
); |
412 |
); |
361 |
|
413 |
|
362 |
} else { |
414 |
} |
|
|
415 |
else { |
363 |
if ($extended) { |
416 |
if ($extended) { |
364 |
my @matchpoints = (); |
417 |
my @matchpoints = (); |
365 |
my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1); |
418 |
my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes( undef, 1 ); |
366 |
foreach my $type (@attr_types) { |
419 |
foreach my $type (@attr_types) { |
367 |
my $attr_type = C4::Members::AttributeTypes->fetch($type->{code}); |
420 |
my $attr_type = C4::Members::AttributeTypes->fetch( $type->{code} ); |
368 |
if ($attr_type->unique_id()) { |
421 |
if ( $attr_type->unique_id() ) { |
369 |
push @matchpoints, { code => "patron_attribute_" . $attr_type->code(), description => $attr_type->description() }; |
422 |
push @matchpoints, |
|
|
423 |
{ code => "patron_attribute_" . $attr_type->code(), description => $attr_type->description() }; |
370 |
} |
424 |
} |
371 |
} |
425 |
} |
372 |
$template->param(matchpoints => \@matchpoints); |
426 |
$template->param( matchpoints => \@matchpoints ); |
373 |
} |
427 |
} |
374 |
} |
428 |
} |
375 |
|
429 |
|
376 |
- |
|
|