3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 script to update a child member to (usually) an adult member category
24 - if called with op=multi, will return all available non child categories, for selection.
25 - if called with op=update, script will update member record via Koha::Patron->store.
35 use Koha
::Patron
::Categories
;
38 # use Smart::Comments;
40 my $dbh = C4
::Context
->dbh;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
45 template_name
=> "members/update-child.tt",
49 flagsrequired
=> { borrowers
=> 'edit_borrowers' },
54 my $borrowernumber = $input->param('borrowernumber');
55 my $catcode = $input->param('catcode');
56 my $cattype = $input->param('cattype');
57 my $op = $input->param('op');
59 my $logged_in_user = Koha
::Patrons
->find( $loggedinuser );
61 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
62 if ( $op eq 'multi' ) {
63 # FIXME - what are the possible upgrade paths? C -> A , C -> S ...
64 # currently just allowing C -> A
67 borrowernumber
=> $borrowernumber,
68 patron_categories
=> $patron_categories,
70 output_html_with_http_headers
$input, $cookie, $template->output;
72 elsif ( $op eq 'update' ) {
73 my $patron = Koha
::Patrons
->find( $borrowernumber );
74 output_and_exit_if_error
( $input, $cookie, $template, { module
=> 'members', logged_in_user
=> $logged_in_user, current_patron
=> $patron } );
77 if ( $patron_categories->count == 1 ) {
78 $adult_category = $patron_categories->next;
80 $adult_category = $patron_categories->search({'me.categorycode' => $catcode })->next;
83 # Just in case someone is trying something bad
84 # But we should not hit that with a normal use of the interface
85 die "You are doing something wrong updating this child" unless $adult_category;
87 $_->delete() for $patron->guarantor_relationships();
89 $patron->categorycode($adult_category->categorycode);
92 # FIXME We should not need that
93 # We could redirect with a friendly message
94 if ( $patron_categories->count > 1 ) {
97 borrowernumber
=> $borrowernumber,
99 output_html_with_http_headers
$input, $cookie, $template->output;
102 print $input->redirect(
103 "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"