99b779de5662a7b6b349589881ecf864c22497b1
[koha.git] / members / deletemem.pl
1 #!/usr/bin/perl
2
3 #script to delete items
4 #written 2/5/00
5 #by chris@katipo.co.nz
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 # use warnings; # FIXME
26
27 use CGI;
28 use C4::Context;
29 use C4::Output;
30 use C4::Auth;
31 use C4::Members;
32
33 my $input = new CGI;
34
35 my ($template, $borrowernumber, $cookie)
36                 = get_template_and_user({template_name => "members/deletemem.tmpl",
37                                         query => $input,
38                                         type => "intranet",
39                                         authnotrequired => 0,
40                                         flagsrequired => {borrowers => 1},
41                                         debug => 1,
42                                         });
43
44 #print $input->header;
45 my $member=$input->param('member');
46 my $issues = GetPendingIssues($member);     # FIXME: wasteful call when really, we only want the count
47 my $countissues = scalar(@$issues);
48
49 my ($bor)=GetMemberDetails($member,'');
50 my $flags=$bor->{flags};
51 my $userenv = C4::Context->userenv;
52 if ($bor->{category_type} eq "S") {
53     unless(C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) {
54         print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
55         exit 1;
56     }
57 }
58
59 if (C4::Context->preference("IndependantBranches")) {
60     unless ($userenv->{flags} % 2 == 1){
61         unless ($userenv->{'branch'} eq $bor->{'branchcode'}){
62 #           warn "user ".$userenv->{'branch'} ."borrower :". $bor->{'branchcode'};
63             print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
64             exit 1;
65         }
66     }
67 }
68 my $dbh = C4::Context->dbh;
69 my $sth=$dbh->prepare("Select * from borrowers where guarantorid=?");
70 $sth->execute($member);
71 my $data=$sth->fetchrow_hashref;
72 if ($countissues > 0 or $flags->{'CHARGES'}  or $data->{'borrowernumber'}){
73     #   print $input->header;
74     $template->param(borrowernumber => $member);
75     if ($countissues >0) {
76         $template->param(ItemsOnIssues => $countissues);
77     }
78     if ($flags->{'CHARGES'} ne '') {
79         $template->param(charges => $flags->{'CHARGES'}->{'amount'});
80     }
81     if ($data) {
82         $template->param(guarantees => 1);
83     }
84 output_html_with_http_headers $input, $cookie, $template->output;
85
86 } else {
87     MoveMemberToDeleted($member);
88     DelMember($member);
89     print $input->redirect("/cgi-bin/koha/members/members-home.pl");
90 }
91
92