Adding in permission blocks for staff members as per previous commits.
[koha.git] / members / deletemem.pl
1 #!/usr/bin/perl
2
3
4 #script to delete items
5 #written 2/5/00
6 #by chris@katipo.co.nz
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27
28 use CGI;
29 use C4::Context;
30 use C4::Output;
31 use C4::Auth;
32 use C4::Members;
33
34
35 my $input = new CGI;
36
37 my $flagsrequired;
38 $flagsrequired->{borrowers}=1;
39 if( $bor->{'category_type'} eq 'S' )  {
40     $flagsrequired->{'staffaccess'} = 1;
41 }  
42 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
43
44
45
46 #print $input->header;
47 my $member=$input->param('member');
48 my %member2;
49 $member2{'borrowernumber'}=$member;
50 my ($countissues,$issues)=GetPendingIssues($member);
51
52 my ($bor)=GetMemberDetails($member,'');
53 my $flags=$bor->{flags};
54
55 my $userenv = C4::Context->userenv;
56 if(C4::Auth::haspermission(undef,$userenv->{'id'},{'staffaccess'=>1})) {
57   print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
58         exit 1;
59 }
60
61 if (C4::Context->preference("IndependantBranches")) {
62         unless ($userenv->{flags} == 1){
63                 unless ($userenv->{'branch'} eq $bor->{'branchcode'}){
64 #                       warn "user ".$userenv->{'branch'} ."borrower :". $bor->{'branchcode'};
65                         print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
66                         exit 1;
67                 }
68         }
69 }
70 my $dbh = C4::Context->dbh;
71 my $sth=$dbh->prepare("Select * from borrowers where guarantorid=?");
72 $sth->execute($member);
73 my $data=$sth->fetchrow_hashref;
74 $sth->finish;
75 if ($countissues > 0 or $flags->{'CHARGES'}  or $data->{'borrowernumber'}){
76
77         my ($template, $borrowernumber, $cookie)
78                 = get_template_and_user({template_name => "members/deletemem.tmpl",
79                                         query => $input,
80                                         type => "intranet",
81                                         authnotrequired => 0,
82                                         flagsrequired => {borrowers => 1},
83                                         debug => 1,
84                                         });
85         #   print $input->header;
86         $template->param(borrowernumber => $member);
87         if ($countissues >0) {
88                 $template->param(ItemsOnIssues => $countissues);
89         }
90         if ($flags->{'CHARGES'} ne '') {
91                 $template->param(charges => $flags->{'CHARGES'}->{'amount'});
92         }
93         if ($data ne '') {
94                 $template->param(guarantees => 1);
95         }
96 output_html_with_http_headers $input, $cookie, $template->output;
97
98 } else {
99         MoveMemberToDeleted($member);
100         DelMember($member);
101         print $input->redirect("/cgi-bin/koha/members/members-home.pl");
102 }
103
104