road to 1.3.2 :
[koha.git] / 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::Output;
33 use C4::Circulation::Circ2;
34 #use C4::Acquisitions;
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 $query="Select * from borrowers where guarantor='$member'";
60 my $sth=$dbh->prepare($query);
61 $sth->execute;
62 my $data=$sth->fetchrow_hashref;
63 $sth->finish;
64
65
66 if ($i > 0 || $flags->{'CHARGES'} ne '' || $data ne ''){
67   print $input->header;
68   print "<table border=1>";
69   if ($i > 0){
70       print "<TR><TD>Items on Issue</td><td align=right>$i</td></tr>";
71   }
72   if ($flags->{'CHARGES'} ne ''){
73       print "<TR><TD>Charges</td><td>$flags->{'CHARGES'}->{'message'}</tr>";
74   }
75   if ($data ne ''){
76       print "<TR><TD>Guarantees</td></tr>";
77   }
78   print "</table>";
79
80 } else {
81          delmember($member);
82          print $input->redirect("/members/");
83 }
84
85 sub delmember{
86   my ($member)=@_;
87   my $dbh = C4::Context->dbh;
88   my $query="Select * from borrowers where borrowernumber='$member'";
89   my $sth=$dbh->prepare($query);
90   $sth->execute;
91   my @data=$sth->fetchrow_array;
92   $sth->finish;
93   $query="Insert into deletedborrowers values (";
94   foreach my $temp (@data){
95     $query .= "'$temp',";
96   }
97   $query=~ s/\,$/\)/;
98   #  print $query;
99   # FIXME - Use $dbh->do()
100   $sth=$dbh->prepare($query);
101   $sth->execute;
102   $sth->finish;
103   # FIXME - Use $dbh->do()
104   $query = "Delete from borrowers where borrowernumber='$member'";
105   $sth=$dbh->prepare($query);
106   $sth->execute;
107   $sth->finish;
108   # FIXME - Use $dbh->do()
109   $query="Delete from reserves where borrowernumber='$member'";
110   $sth=$dbh->prepare($query);
111   $sth->execute;
112   $sth->finish;
113 }