Merge branch 'new/bug_6479' into kcmaster
[koha.git] / members / deletemem.pl
blobb1ba709c65c0cef0dc30ca6e5548e393f47cb968
1 #!/usr/bin/perl
3 #script to delete items
4 #written 2/5/00
5 #by chris@katipo.co.nz
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
14 # version.
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.
24 use strict;
25 #use warnings; FIXME - Bug 2505
27 use CGI;
28 use C4::Context;
29 use C4::Output;
30 use C4::Auth;
31 use C4::Members;
32 use C4::Branch; # GetBranches
34 my $input = new CGI;
36 my ($template, $borrowernumber, $cookie)
37 = get_template_and_user({template_name => "members/deletemem.tmpl",
38 query => $input,
39 type => "intranet",
40 authnotrequired => 0,
41 flagsrequired => {borrowers => 1},
42 debug => 1,
43 });
45 #print $input->header;
46 my $member=$input->param('member');
47 my $issues = GetPendingIssues($member); # FIXME: wasteful call when really, we only want the count
48 my $countissues = scalar(@$issues);
50 my ($bor)=GetMemberDetails($member,'');
51 my $flags=$bor->{flags};
52 my $userenv = C4::Context->userenv;
56 if ($bor->{category_type} eq "S") {
57 unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) {
58 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
59 exit 1;
61 } else {
62 unless(C4::Auth::haspermission($userenv->{'id'},{'borrowers'=>1})) {
63 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
64 exit 1;
68 if (C4::Context->preference("IndependantBranches")) {
69 my $userenv = C4::Context->userenv;
70 if (($userenv->{flags} % 2 != 1) && $bor->{'branchcode'}){
71 unless ($userenv->{branch} eq $bor->{'branchcode'}){
72 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
73 exit;
78 my $dbh = C4::Context->dbh;
79 my $sth=$dbh->prepare("Select * from borrowers where guarantorid=?");
80 $sth->execute($member);
81 my $data=$sth->fetchrow_hashref;
82 if ($countissues > 0 or $flags->{'CHARGES'} or $data->{'borrowernumber'}){
83 # print $input->header;
85 my ($picture, $dberror) = GetPatronImage($bor->{'cardnumber'});
86 $template->param( picture => 1 ) if $picture;
88 $template->param(borrowernumber => $member,
89 surname => $bor->{'surname'},
90 title => $bor->{'title'},
91 cardnumber => $bor->{'cardnumber'},
92 firstname => $bor->{'firstname'},
93 categorycode => $bor->{'categorycode'},
94 category_type => $bor->{'category_type'},
95 categoryname => $bor->{'description'},
96 address => $bor->{'address'},
97 address2 => $bor->{'address2'},
98 city => $bor->{'city'},
99 zipcode => $bor->{'zipcode'},
100 country => $bor->{'country'},
101 phone => $bor->{'phone'},
102 email => $bor->{'email'},
103 branchcode => $bor->{'branchcode'},
104 branchname => GetBranchName($bor->{'branchcode'}),
106 if ($countissues >0) {
107 $template->param(ItemsOnIssues => $countissues);
109 if ($flags->{'CHARGES'} ne '') {
110 $template->param(charges => $flags->{'CHARGES'}->{'amount'});
112 if ($data) {
113 $template->param(guarantees => 1);
115 output_html_with_http_headers $input, $cookie, $template->output;
117 } else {
118 MoveMemberToDeleted($member);
119 DelMember($member);
120 print $input->redirect("/cgi-bin/koha/members/members-home.pl");