3 # Copyright 2007 Liblime Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 # Script to take some borrowers data in a known format and load it into Koha
24 # cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,
25 # address line , address line 2, city, zipcode, email, phone, mobile, fax, work email, work phone,
26 # alternate streetnumber, alternate streettype, alternate address line 1, alternate city,
27 # alternate zipcode, alternate email, alternate phone, date of birth, branchcode,
28 # categorycode, enrollment date, expiry date, noaddress, lost, debarred, contact surname,
29 # contact firstname, contact title, borrower notes, contact relationship, ethnicity, ethnicity notes
30 # gender, username, opac note, contact note, password, sort one, sort two
32 # any fields except cardnumber can be blank but the number of fields must match
33 # dates should be in the format you have set up Koha to expect
34 # branchcode and categorycode need to be valid
47 'cardnumber', 'surname', 'firstname', 'title',
48 'othernames', 'initials', 'streetnumber', 'streettype',
49 'address', 'address2', 'city', 'zipcode',
50 'email', 'phone', 'mobile', 'fax',
51 'emailpro', 'phonepro', 'B_streetnumber', 'B_streettype',
52 'B_address', 'B_city', 'B_zipcode', 'B_email',
53 'B_phone', 'dateofbirth', 'branchcode', 'categorycode',
54 'dateenrolled', 'dateexpiry', 'gonenoaddress', 'lost',
55 'debarred', 'contactname', 'contactfirstname', 'contacttitle',
56 'borrowernotes', 'relationship', 'ethnicity', 'ethnotes',
57 'sex', 'userid', 'opacnote', 'contactnote',
58 'password', 'sort1', 'sort2'
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "tools/import_borrowers.tmpl",
69 flagsrequired => { tools => 1 },
74 my $uploadborrowers = $input->param('uploadborrowers');
75 my $overwrite_cardnumber = $input->param('overwrite_cardnumber');
77 $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'} );
79 if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
80 my $csv = Text::CSV->new();
85 while ( my $borrowerline = <$uploadborrowers> ) {
87 my $status = $csv->parse($borrowerline);
88 my @columns = $csv->fields();
90 if ( @columns == @columnkeys ) {
92 @borrower{@columnkeys} = @columns;
94 GetMember( $borrower{'cardnumber'}, 'cardnumber' ) )
98 if ($overwrite_cardnumber) {
99 $borrower{'borrowernumber'} = $member->{'borrowernumber'};
100 ModMember(%borrower);
108 my $borrowernumber = AddMember(%borrower);
109 if ($borrowernumber) {
121 $template->param( 'uploadborrowers' => 1 );
123 'uploadborrowers' => 1,
124 'imported' => $imported,
125 'overwritten' => $overwritten,
126 'alreadyindb' => $alreadyindb,
127 'invalid' => $invalid,
128 'total' => $imported + $alreadyindb + $invalid + $overwritten,
132 output_html_with_http_headers $input, $cookie, $template->output;