3 #script to delete items
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
33 use Koha
::Patron
::Categories
;
37 my ($template, $loggedinuser, $cookie)
38 = get_template_and_user
({template_name
=> "members/deletemem.tt",
42 flagsrequired
=> {borrowers
=> 'edit_borrowers'},
46 #print $input->header;
47 my $member = $input->param('member');
49 #Do not delete yourself...
50 if ( $loggedinuser == $member ) {
51 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_YOURSELF");
52 exit 0; # Exit without error
55 my $logged_in_user = Koha
::Patrons
->find( $loggedinuser ) or die "Not logged in";
56 my $patron = Koha
::Patrons
->find( $member );
57 output_and_exit_if_error
( $input, $cookie, $template, { module
=> 'members', logged_in_user
=> $logged_in_user, current_patron
=> $patron } );
59 my $charges = $patron->account->non_issues_charges;
60 my $countissues = $patron->checkouts->count;
61 my $userenv = C4
::Context
->userenv;
63 if ($patron->category->category_type eq "S") {
64 unless(C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) {
65 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_STAFF");
66 exit 0; # Exit without error
69 unless(C4
::Auth
::haspermission
($userenv->{'id'},{'borrowers'=>'edit_borrowers'})) {
70 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE");
71 exit 0; # Exit without error
75 if (C4
::Context
->preference("IndependentBranches")) {
76 my $userenv = C4
::Context
->userenv;
77 if ( !C4
::Context
->IsSuperLibrarian() && $patron->branchcode){
78 unless ($userenv->{branch
} eq $patron->branchcode){
79 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_OTHERLIBRARY");
80 exit 0; # Exit without error
85 my $op = $input->param('op') || 'delete_confirm';
86 my $dbh = C4
::Context
->dbh;
87 my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member);
88 if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor ) {
93 if ($countissues >0) {
94 $template->param(ItemsOnIssues
=> $countissues);
97 $template->param(charges
=> $charges);
100 $template->param(guarantees
=> 1);
103 # This is silly written but reflect the same conditions as above
104 if ( not $countissues > 0 and not $charges and not $is_guarantor ) {
106 op
=> 'delete_confirm',
107 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> scalar $input->cookie('CGISESSID') }),
110 } elsif ( $op eq 'delete_confirmed' ) {
112 die "Wrong CSRF token"
113 unless Koha
::Token
->new->check_csrf( {
114 session_id
=> $input->cookie('CGISESSID'),
115 token
=> scalar $input->param('csrf_token'),
117 my $patron = Koha
::Patrons
->find( $member );
118 $patron->move_to_deleted;
120 # TODO Tell the user everything went ok
121 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
122 exit 0; # Exit without error
125 output_html_with_http_headers
$input, $cookie, $template->output;