Moving error messages out of script and into template, fix for Bug 538
[koha.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::Search;
32 use C4::Interface::CGI::Output;
33 use C4::Output;
34 use C4::Circulation::Circ2;
35 use C4::Auth;
36
37
38 my $input = new CGI;
39
40 my $flagsrequired;
41 $flagsrequired->{borrower}=1;
42 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
43
44
45
46 #print $input->header;
47 my $member=$input->param('member');
48 my %env;
49 $env{'nottodayissues'}=1;
50 my %member2;
51 $member2{'borrowernumber'}=$member;
52 my $issues=currentissues(\%env,\%member2);
53 my $i=0;
54 foreach (sort keys %$issues) {
55         $i++;
56 }
57 my ($bor,$flags)=getpatroninformation(\%env, $member,'');
58 my $dbh = C4::Context->dbh;
59 my $sth=$dbh->prepare("Select * from borrowers where guarantor=?");
60 $sth->execute($member);
61 my $data=$sth->fetchrow_hashref;
62 $sth->finish;
63
64
65 if ($i > 0 || $flags->{'CHARGES'} ne '' || $data ne ''){
66         my ($template, $borrowernumber, $cookie)
67                 = get_template_and_user({template_name => "members/deletemem.tmpl",
68                                         query => $input,
69                                         type => "intranet",
70                                         authnotrequired => 0,
71                                         flagsrequired => {circulate => 1},
72                                         debug => 1,
73                                         });
74         #   print $input->header;
75         $template->param(bornum => $member);
76         if ($i >0) {
77                 $template->param(ItemsOnIssues => $i);
78         }
79         if ($flags->{'CHARGES'} ne '') {
80                 $template->param(charges => $flags->{'CHARGES'}->{'message'});
81         }
82         if ($data ne '') {
83                 $template->param(guarantees => 1);
84         }
85 #       print "<table border=1>";
86 #       if ($i > 0){
87 #               print "<TR><TD>Items on Issue</td><td align=right>$i</td></tr>";
88 #       }
89 #       if ($flags->{'CHARGES'} ne ''){
90 #               print "<TR><TD>Charges</td><td>$flags->{'CHARGES'}->{'message'}</tr>";
91 #       }
92 #       if ($data ne ''){
93 #               print "<TR><TD>Guarantees</td></tr>";
94 #       }
95 #       print "</table>";
96 output_html_with_http_headers $input, $cookie, $template->output;
97
98 } else {
99         delmember($member);
100         print $input->redirect("/cgi-bin/koha/members/members-home.pl");
101 }
102
103 sub delmember{
104         my ($member)=@_;
105         my $dbh = C4::Context->dbh;
106         my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
107         $sth->execute($member);
108         my @data=$sth->fetchrow_array;
109         $sth->finish;
110         $sth=$dbh->prepare("Insert into deletedborrowers values (".("?,"x(scalar(@data)-1))."?)");
111         $sth->execute(@data);
112         $sth->finish;
113         $sth=$dbh->prepare("Delete from borrowers where borrowernumber=?");
114         $sth->execute($member);
115         $sth->finish;
116         $sth=$dbh->prepare("Delete from reserves where borrowernumber=?");
117         $sth->execute($member);
118         $sth->finish;
119 }