pay.pl: bug fix , add variable declaration
[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->{borrowers}=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 warn "user num".$member;
50 $env{'nottodayissues'}=1;
51 my %member2;
52 $member2{'borrowernumber'}=$member;
53 my $issues=currentissues(\%env,\%member2);
54 my $i=0;
55 foreach (sort keys %$issues) {
56         $i++;
57 }
58 my ($bor,$flags)=getpatroninformation(\%env, $member,'');
59 if (C4::Context->preference("IndependantBranches")) {
60         my $userenv = C4::Context->userenv;
61         unless ($userenv->{flags} == 1){
62                 unless ($userenv->{'branch'} eq $bor->{'branchcode'}){
63 #                       warn "user ".$userenv->{'branch'} ."borrower :". $bor->{'branchcode'};
64                         print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$member");
65                         exit 1;
66                 }
67         }
68 }
69 my $dbh = C4::Context->dbh;
70 my $sth=$dbh->prepare("Select * from borrowers where guarantorid=?");
71 $sth->execute($member);
72 my $data=$sth->fetchrow_hashref;
73 $sth->finish;
74
75 if ($i > 0 || $flags->{'CHARGES'} ne '' || $data ne ''){
76         my ($template, $borrowernumber, $cookie)
77                 = get_template_and_user({template_name => "members/deletemem.tmpl",
78                                         query => $input,
79                                         type => "intranet",
80                                         authnotrequired => 0,
81                                         flagsrequired => {borrower => 1},
82                                         debug => 1,
83                                         });
84         #   print $input->header;
85         $template->param(bornum => $member);
86         if ($i >0) {
87                 $template->param(ItemsOnIssues => $i);
88         }
89         if ($flags->{'CHARGES'} ne '') {
90                 $template->param(charges => $flags->{'CHARGES'}->{'message'});
91         }
92         if ($data ne '') {
93                 $template->param(guarantees => 1);
94         }
95 #       print "<table border=1>";
96 #       if ($i > 0){
97 #               print "<TR><TD>Items on Issue</td><td align=right>$i</td></tr>";
98 #       }
99 #       if ($flags->{'CHARGES'} ne ''){
100 #               print "<TR><TD>Charges</td><td>$flags->{'CHARGES'}->{'message'}</tr>";
101 #       }
102 #       if ($data ne ''){
103 #               print "<TR><TD>Guarantees</td></tr>";
104 #       }
105 #       print "</table>";
106 output_html_with_http_headers $input, $cookie, $template->output;
107
108 } else {
109         delmember($member);
110         print $input->redirect("/cgi-bin/koha/members/members-home.pl");
111 }
112
113 sub delmember{
114         my ($member)=@_;
115         my $dbh = C4::Context->dbh;
116         my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
117         $sth->execute($member);
118         my @data=$sth->fetchrow_array;
119         $sth->finish;
120         $sth=$dbh->prepare("Insert into deletedborrowers values (".("?,"x(scalar(@data)-1))."?)");
121         $sth->execute(@data);
122         $sth->finish;
123         $sth=$dbh->prepare("Delete from borrowers where borrowernumber=?");
124         $sth->execute($member);
125         $sth->finish;
126         $sth=$dbh->prepare("Delete from reserves where borrowernumber=?");
127         $sth->execute($member);
128         $sth->finish;
129 }