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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #use warnings; FIXME - Bug 2505
32 use C4::Branch; # GetBranches
33 use C4::VirtualShelves (); #no import
35 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
36 load Koha::NorwegianPatronDB, qw( NLMarkForDeletion NLSync );
41 my ($template, $borrowernumber, $cookie)
42 = get_template_and_user({template_name => "members/deletemem.tt",
46 flagsrequired => {borrowers => 1},
50 #print $input->header;
51 my $member = $input->param('member');
53 # Handle deletion from the Norwegian national patron database, if it is enabled
54 # If the "deletelocal" parameter is set to "false", the regular deletion will be
55 # short circuited, and only a deletion from the national database can be carried
56 # out. If "deletelocal" is set to "true", or not set to anything normal
57 # deletion will be done.
58 my $deletelocal = $input->param('deletelocal') eq 'false' ? 0 : 1; # Deleting locally is the default
59 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
60 if ( $input->param('deleteremote') eq 'true' ) {
61 # Mark for deletion, then try a live sync
62 NLMarkForDeletion( $member );
63 NLSync({ 'borrowernumber' => $member });
67 my $issues = GetPendingIssues($member); # FIXME: wasteful call when really, we only want the count
68 my $countissues = scalar(@$issues);
70 my ($bor)=GetMemberDetails($member,'');
71 my $flags=$bor->{flags};
72 my $userenv = C4::Context->userenv;
76 if ($bor->{category_type} eq "S") {
77 unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) {
78 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
82 unless(C4::Auth::haspermission($userenv->{'id'},{'borrowers'=>1})) {
83 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
88 if (C4::Context->preference("IndependentBranches")) {
89 my $userenv = C4::Context->userenv;
90 if ( !C4::Context->IsSuperLibrarian() && $bor->{'branchcode'}){
91 unless ($userenv->{branch} eq $bor->{'branchcode'}){
92 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
98 my $dbh = C4::Context->dbh;
99 my $sth=$dbh->prepare("Select * from borrowers where guarantorid=?");
100 $sth->execute($member);
101 my $data=$sth->fetchrow_hashref;
102 if ($countissues > 0 or $flags->{'CHARGES'} or $data->{'borrowernumber'} or $deletelocal == 0){
103 # print $input->header;
105 my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'});
106 $template->param( picture => 1 ) if $picture;
108 $template->param(borrowernumber => $member,
109 surname => $bor->{'surname'},
110 title => $bor->{'title'},
111 cardnumber => $bor->{'cardnumber'},
112 firstname => $bor->{'firstname'},
113 categorycode => $bor->{'categorycode'},
114 category_type => $bor->{'category_type'},
115 categoryname => $bor->{'description'},
116 address => $bor->{'address'},
117 address2 => $bor->{'address2'},
118 city => $bor->{'city'},
119 zipcode => $bor->{'zipcode'},
120 country => $bor->{'country'},
121 phone => $bor->{'phone'},
122 email => $bor->{'email'},
123 branchcode => $bor->{'branchcode'},
124 branchname => GetBranchName($bor->{'branchcode'}),
125 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
126 RoutingSerials => C4::Context->preference('RoutingSerials'),
128 if ($countissues >0) {
129 $template->param(ItemsOnIssues => $countissues);
131 if ($flags->{'CHARGES'} ne '') {
132 $template->param(charges => $flags->{'CHARGES'}->{'amount'});
134 if ($data->{'borrowernumber'}) {
135 $template->param(guarantees => 1);
137 if ($deletelocal == 0) {
138 $template->param(keeplocal => 1);
140 output_html_with_http_headers $input, $cookie, $template->output;
143 MoveMemberToDeleted($member);
144 C4::VirtualShelves::HandleDelBorrower($member);
146 print $input->redirect("/cgi-bin/koha/members/members-home.pl");