Added a FIXME comment.
[koha.git] / 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
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26
27 use CGI;
28 use C4::Context;
29 use C4::Search;
30 use C4::Output;
31 use C4::Circulation::Circ2;
32 #use C4::Acquisitions;
33
34 my $input = new CGI;
35 #print $input->header;
36 my $member=$input->param('member');
37 my %env;
38 $env{'nottodayissues'}=1;
39  my %member2;
40  $member2{'borrowernumber'}=$member;
41  my $issues=currentissues(\%env,\%member2);
42  my $i=0;
43  foreach (sort keys %$issues) {
44   $i++;
45  }
46   my ($bor,$flags)=getpatroninformation(\%env, $member,'');
47 my $dbh = C4::Context->dbh;
48 my $query="Select * from borrowers where guarantor='$member'";
49 my $sth=$dbh->prepare($query);
50 $sth->execute;
51 my $data=$sth->fetchrow_hashref;
52 $sth->finish;
53       
54
55 if ($i > 0 || $flags->{'CHARGES'} ne '' || $data ne ''){ 
56   print $input->header;
57   print "<table border=1>";
58   if ($i > 0){
59       print "<TR><TD>Items on Issue</td><td align=right>$i</td></tr>";
60   }
61   if ($flags->{'CHARGES'} ne ''){
62       print "<TR><TD>Charges</td><td>$flags->{'CHARGES'}->{'message'}</tr>";
63   }
64   if ($data ne ''){
65       print "<TR><TD>Guarantees</td></tr>";
66   }
67   print "</table>";
68
69 } else {
70          delmember($member);
71          print $input->redirect("/members/");
72 }
73
74 sub delmember{
75   my ($member)=@_;
76   my $dbh = C4::Context->dbh;
77   my $query="Select * from borrowers where borrowernumber='$member'";
78   my $sth=$dbh->prepare($query);
79   $sth->execute;
80   my @data=$sth->fetchrow_array;
81   $sth->finish;
82   $query="Insert into deletedborrowers values (";
83   foreach my $temp (@data){
84     $query=$query."'$temp',";           # FIXME - .=
85   }
86   $query=~ s/\,$/\)/;
87   #  print $query;
88   # FIXME - Use $dbh->do()
89   $sth=$dbh->prepare($query);
90   $sth->execute;
91   $sth->finish;
92   # FIXME - Use $dbh->do()
93   $query = "Delete from borrowers where borrowernumber='$member'";
94   $sth=$dbh->prepare($query);
95   $sth->execute;
96   $sth->finish;
97   # FIXME - Use $dbh->do()
98   $query="Delete from reserves where borrowernumber='$member'";
99   $sth=$dbh->prepare($query);
100   $sth->execute;
101   $sth->finish;
102 }