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