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-239
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'}; |
231 |
} |
270 |
} |
232 |
} elsif ($extended) { |
271 |
} |
233 |
if (defined($matchpoint_attr_type)) { |
272 |
elsif ($extended) { |
|
|
273 |
if ( defined($matchpoint_attr_type) ) { |
234 |
foreach my $attr (@$patron_attributes) { |
274 |
foreach my $attr (@$patron_attributes) { |
235 |
if ($attr->{code} eq $matchpoint and $attr->{value} ne '') { |
275 |
if ( $attr->{code} eq $matchpoint and $attr->{value} ne '' ) { |
236 |
my @borrowernumbers = $matchpoint_attr_type->get_patrons($attr->{value}); |
276 |
my @borrowernumbers = $matchpoint_attr_type->get_patrons( $attr->{value} ); |
237 |
$borrowernumber = $borrowernumbers[0] if scalar(@borrowernumbers) == 1; |
277 |
$borrowernumber = $borrowernumbers[0] if scalar(@borrowernumbers) == 1; |
238 |
last; |
278 |
last; |
239 |
} |
279 |
} |
Lines 242-284
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
242 |
} |
282 |
} |
243 |
|
283 |
|
244 |
if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) { |
284 |
if ( C4::Members::checkcardnumber( $borrower{cardnumber}, $borrowernumber ) ) { |
245 |
push @errors, { |
285 |
push @errors, |
|
|
286 |
{ |
246 |
invalid_cardnumber => 1, |
287 |
invalid_cardnumber => 1, |
247 |
borrowernumber => $borrowernumber, |
288 |
borrowernumber => $borrowernumber, |
248 |
cardnumber => $borrower{cardnumber} |
289 |
cardnumber => $borrower{cardnumber} |
249 |
}; |
290 |
}; |
250 |
$invalid++; |
291 |
$invalid++; |
251 |
next; |
292 |
next; |
252 |
} |
293 |
} |
253 |
|
294 |
|
254 |
|
|
|
255 |
if ($borrowernumber) { |
295 |
if ($borrowernumber) { |
|
|
296 |
|
256 |
# borrower exists |
297 |
# borrower exists |
257 |
unless ($overwrite_cardnumber) { |
298 |
unless ($overwrite_cardnumber) { |
258 |
$alreadyindb++; |
299 |
$alreadyindb++; |
259 |
$template->param('lastalreadyindb'=>$borrower{'surname'}.' / '.$borrowernumber); |
300 |
$template->param( 'lastalreadyindb' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
260 |
next LINE; |
301 |
next LINE; |
261 |
} |
302 |
} |
262 |
$borrower{'borrowernumber'} = $borrowernumber; |
303 |
$borrower{'borrowernumber'} = $borrowernumber; |
263 |
for my $col (keys %borrower) { |
304 |
for my $col ( keys %borrower ) { |
|
|
305 |
|
264 |
# use values from extant patron unless our csv file includes this column or we provided a default. |
306 |
# use values from extant patron unless our csv file includes this column or we provided a default. |
265 |
# FIXME : You cannot update a field with a perl-evaluated false value using the defaults. |
307 |
# FIXME : You cannot update a field with a perl-evaluated false value using the defaults. |
266 |
|
308 |
|
267 |
# The password is always encrypted, skip it! |
309 |
# The password is always encrypted, skip it! |
268 |
next if $col eq 'password'; |
310 |
next if $col eq 'password'; |
269 |
|
311 |
|
270 |
unless(exists($csvkeycol{$col}) || $defaults{$col}) { |
312 |
unless ( exists( $csvkeycol{$col} ) || $defaults{$col} ) { |
271 |
$borrower{$col} = $member->{$col} if($member->{$col}) ; |
313 |
$borrower{$col} = $member->{$col} if ( $member->{$col} ); |
272 |
} |
314 |
} |
273 |
} |
315 |
} |
274 |
unless (ModMember(%borrower)) { |
316 |
unless ( ModMember(%borrower) ) { |
275 |
$invalid++; |
317 |
$invalid++; |
|
|
318 |
|
276 |
# untill we have better error trapping, we have no way of knowing why ModMember errored out... |
319 |
# untill we have better error trapping, we have no way of knowing why ModMember errored out... |
277 |
push @errors, {unknown_error => 1}; |
320 |
push @errors, { unknown_error => 1 }; |
278 |
$template->param('lastinvalid'=>$borrower{'surname'}.' / '.$borrowernumber); |
321 |
$template->param( 'lastinvalid' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
279 |
next LINE; |
322 |
next LINE; |
280 |
} |
323 |
} |
281 |
if ( $borrower{debarred} ) { |
324 |
if ( $borrower{debarred} ) { |
|
|
325 |
|
282 |
# Check to see if this debarment already exists |
326 |
# Check to see if this debarment already exists |
283 |
my $debarrments = GetDebarments( |
327 |
my $debarrments = GetDebarments( |
284 |
{ |
328 |
{ |
Lines 287-292
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
287 |
comment => $borrower{debarredcomment} |
331 |
comment => $borrower{debarredcomment} |
288 |
} |
332 |
} |
289 |
); |
333 |
); |
|
|
334 |
|
290 |
# If it doesn't, then add it! |
335 |
# If it doesn't, then add it! |
291 |
unless (@$debarrments) { |
336 |
unless (@$debarrments) { |
292 |
AddDebarment( |
337 |
AddDebarment( |
Lines 301-319
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
301 |
if ($extended) { |
346 |
if ($extended) { |
302 |
if ($ext_preserve) { |
347 |
if ($ext_preserve) { |
303 |
my $old_attributes = GetBorrowerAttributes($borrowernumber); |
348 |
my $old_attributes = GetBorrowerAttributes($borrowernumber); |
304 |
$patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes); #TODO: expose repeatable options in template |
349 |
$patron_attributes = extended_attributes_merge( $old_attributes, $patron_attributes ) |
|
|
350 |
; #TODO: expose repeatable options in template |
305 |
} |
351 |
} |
306 |
push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes); |
352 |
push @errors, { unknown_error => 1 } |
|
|
353 |
unless SetBorrowerAttributes( $borrower{'borrowernumber'}, $patron_attributes ); |
307 |
} |
354 |
} |
308 |
$overwritten++; |
355 |
$overwritten++; |
309 |
$template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber); |
356 |
$template->param( 'lastoverwritten' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
310 |
} else { |
357 |
} |
|
|
358 |
else { |
311 |
# FIXME: fixup_cardnumber says to lock table, but the web interface doesn't so this doesn't either. |
359 |
# FIXME: fixup_cardnumber says to lock table, but the web interface doesn't so this doesn't either. |
312 |
# At least this is closer to AddMember than in members/memberentry.pl |
360 |
# At least this is closer to AddMember than in members/memberentry.pl |
313 |
if (!$borrower{'cardnumber'}) { |
361 |
if ( !$borrower{'cardnumber'} ) { |
314 |
$borrower{'cardnumber'} = fixup_cardnumber(undef); |
362 |
$borrower{'cardnumber'} = fixup_cardnumber(undef); |
315 |
} |
363 |
} |
316 |
if ($borrowernumber = AddMember(%borrower)) { |
364 |
if ( $borrowernumber = AddMember(%borrower) ) { |
317 |
|
365 |
|
318 |
if ( $borrower{debarred} ) { |
366 |
if ( $borrower{debarred} ) { |
319 |
AddDebarment( |
367 |
AddDebarment( |
Lines 326-350
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
326 |
} |
374 |
} |
327 |
|
375 |
|
328 |
if ($extended) { |
376 |
if ($extended) { |
329 |
SetBorrowerAttributes($borrowernumber, $patron_attributes); |
377 |
SetBorrowerAttributes( $borrowernumber, $patron_attributes ); |
330 |
} |
378 |
} |
331 |
|
379 |
|
332 |
if ($set_messaging_prefs) { |
380 |
if ($set_messaging_prefs) { |
333 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults({ borrowernumber => $borrowernumber, |
381 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
334 |
categorycode => $borrower{categorycode} }); |
382 |
{ |
|
|
383 |
borrowernumber => $borrowernumber, |
384 |
categorycode => $borrower{categorycode} |
385 |
} |
386 |
); |
335 |
} |
387 |
} |
336 |
|
388 |
|
337 |
$imported++; |
389 |
$imported++; |
338 |
$template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber); |
390 |
$template->param( 'lastimported' => $borrower{'surname'} . ' / ' . $borrowernumber ); |
339 |
} else { |
391 |
} |
|
|
392 |
else { |
340 |
$invalid++; |
393 |
$invalid++; |
341 |
push @errors, {unknown_error => 1}; |
394 |
push @errors, { unknown_error => 1 }; |
342 |
$template->param('lastinvalid'=>$borrower{'surname'}.' / AddMember'); |
395 |
$template->param( 'lastinvalid' => $borrower{'surname'} . ' / AddMember' ); |
343 |
} |
396 |
} |
344 |
} |
397 |
} |
345 |
} |
398 |
} |
346 |
(@errors ) and $template->param( ERRORS=>\@errors ); |
399 |
(@errors) and $template->param( ERRORS => \@errors ); |
347 |
(@feedback) and $template->param(FEEDBACK=>\@feedback); |
400 |
(@feedback) and $template->param( FEEDBACK => \@feedback ); |
348 |
$template->param( |
401 |
$template->param( |
349 |
'uploadborrowers' => 1, |
402 |
'uploadborrowers' => 1, |
350 |
'imported' => $imported, |
403 |
'imported' => $imported, |
Lines 354-370
if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
Link Here
|
354 |
'total' => $imported + $alreadyindb + $invalid + $overwritten, |
407 |
'total' => $imported + $alreadyindb + $invalid + $overwritten, |
355 |
); |
408 |
); |
356 |
|
409 |
|
357 |
} else { |
410 |
} |
|
|
411 |
else { |
358 |
if ($extended) { |
412 |
if ($extended) { |
359 |
my @matchpoints = (); |
413 |
my @matchpoints = (); |
360 |
my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes(undef, 1); |
414 |
my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes( undef, 1 ); |
361 |
foreach my $type (@attr_types) { |
415 |
foreach my $type (@attr_types) { |
362 |
my $attr_type = C4::Members::AttributeTypes->fetch($type->{code}); |
416 |
my $attr_type = C4::Members::AttributeTypes->fetch( $type->{code} ); |
363 |
if ($attr_type->unique_id()) { |
417 |
if ( $attr_type->unique_id() ) { |
364 |
push @matchpoints, { code => "patron_attribute_" . $attr_type->code(), description => $attr_type->description() }; |
418 |
push @matchpoints, |
|
|
419 |
{ code => "patron_attribute_" . $attr_type->code(), description => $attr_type->description() }; |
365 |
} |
420 |
} |
366 |
} |
421 |
} |
367 |
$template->param(matchpoints => \@matchpoints); |
422 |
$template->param( matchpoints => \@matchpoints ); |
368 |
} |
423 |
} |
369 |
} |
424 |
} |
370 |
|
425 |
|
371 |
- |
|
|