3 #script to delete items
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 #use warnings; FIXME - Bug 2505
28 use Digest
::MD5
qw(md5_base64);
29 use Encode
qw( encode );
36 use Koha
::Patron
::Images
;
39 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
40 load Koha
::NorwegianPatronDB
, qw( NLMarkForDeletion NLSync );
45 my ($template, $borrowernumber, $cookie)
46 = get_template_and_user
({template_name
=> "members/deletemem.tt",
50 flagsrequired
=> {borrowers
=> 1},
54 #print $input->header;
55 my $member = $input->param('member');
57 #Do not delete yourself...
58 if ($borrowernumber == $member ) {
59 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_YOURSELF");
60 exit 0; # Exit without error
63 # Handle deletion from the Norwegian national patron database, if it is enabled
64 # If the "deletelocal" parameter is set to "false", the regular deletion will be
65 # short circuited, and only a deletion from the national database can be carried
66 # out. If "deletelocal" is set to "true", or not set to anything normal
67 # deletion will be done.
68 my $deletelocal = $input->param('deletelocal') eq 'false' ?
0 : 1; # Deleting locally is the default
69 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
70 if ( $input->param('deleteremote') eq 'true' ) {
71 # Mark for deletion, then try a live sync
72 NLMarkForDeletion
( $member );
73 NLSync
({ 'borrowernumber' => $member });
77 my $issues = GetPendingIssues
($member); # FIXME: wasteful call when really, we only want the count
78 my $countissues = scalar(@
$issues);
80 my $bor = C4
::Members
::GetMember
( borrowernumber
=> $member );
81 my $flags = C4
::Members
::patronflags
( $bor );
82 my $userenv = C4
::Context
->userenv;
86 if ($bor->{category_type
} eq "S") {
87 unless(C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) {
88 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
89 exit 0; # Exit without error
92 unless(C4
::Auth
::haspermission
($userenv->{'id'},{'borrowers'=>1})) {
93 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
94 exit 0; # Exit without error
98 if (C4
::Context
->preference("IndependentBranches")) {
99 my $userenv = C4
::Context
->userenv;
100 if ( !C4
::Context
->IsSuperLibrarian() && $bor->{'branchcode'}){
101 unless ($userenv->{branch
} eq $bor->{'branchcode'}){
102 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
103 exit 0; # Exit without error
108 my $op = $input->param('op') || 'delete_confirm';
109 my $dbh = C4
::Context
->dbh;
110 my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member);
111 if ( $op eq 'delete_confirm' or $countissues > 0 or $flags->{'CHARGES'} or $is_guarantor or $deletelocal == 0) {
112 my $patron_image = Koha
::Patron
::Images
->find($bor->{borrowernumber
});
113 $template->param( picture
=> 1 ) if $patron_image;
115 $template->param(borrowernumber
=> $member,
116 surname
=> $bor->{'surname'},
117 title
=> $bor->{'title'},
118 cardnumber
=> $bor->{'cardnumber'},
119 firstname
=> $bor->{'firstname'},
120 categorycode
=> $bor->{'categorycode'},
121 category_type
=> $bor->{'category_type'},
122 categoryname
=> $bor->{'description'},
123 address
=> $bor->{'address'},
124 address2
=> $bor->{'address2'},
125 city
=> $bor->{'city'},
126 zipcode
=> $bor->{'zipcode'},
127 country
=> $bor->{'country'},
128 phone
=> $bor->{'phone'},
129 email
=> $bor->{'email'},
130 branchcode
=> $bor->{'branchcode'},
131 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
132 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
134 if ($countissues >0) {
135 $template->param(ItemsOnIssues
=> $countissues);
137 if ($flags->{'CHARGES'} ne '') {
138 $template->param(charges
=> $flags->{'CHARGES'}->{'amount'});
141 $template->param(guarantees
=> 1);
143 if ($deletelocal == 0) {
144 $template->param(keeplocal
=> 1);
146 # This is silly written but reflect the same conditions as above
147 if ( not $countissues > 0 and not $flags->{CHARGES
} ne '' and not $is_guarantor and not $deletelocal == 0 ) {
149 op
=> 'delete_confirm',
150 csrf_token
=> Koha
::Token
->new->generate_csrf(
151 { id
=> C4
::Context
->userenv->{id
},
152 secret
=> md5_base64
( Encode
::encode
( 'UTF-8', C4
::Context
->config('pass') ) ),
157 } elsif ( $op eq 'delete_confirmed' ) {
159 die "Wrong CSRF token"
160 unless Koha
::Token
->new->check_csrf({
161 id
=> C4
::Context
->userenv->{id
},
162 secret
=> md5_base64
( Encode
::encode
( 'UTF-8', C4
::Context
->config('pass') ) ),
163 token
=> scalar $input->param('csrf_token'),
165 my $patron = Koha
::Patrons
->find( $member );
166 $patron->move_to_deleted;
168 # TODO Tell the user everything went ok
169 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
170 exit 0; # Exit without error
173 output_html_with_http_headers
$input, $cookie, $template->output;