Bug 19258: Prevent warn when reversing a payment
[koha.git] / members / update-child.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 =head1 updatechild.pl
21
22     script to update a child member to (usually) an adult member category
23
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  ModMember().
26
27 =cut
28
29 use strict;
30 #use warnings; FIXME - Bug 2505
31 use CGI qw ( -utf8 );
32 use C4::Context;
33 use C4::Auth;
34 use C4::Output;
35 use C4::Members;
36 use Koha::Patrons;
37 use Koha::Patron::Categories;
38
39 # use Smart::Comments;
40
41 my $dbh   = C4::Context->dbh;
42 my $input = new CGI;
43
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45     {
46         template_name   => "members/update-child.tt",
47         query           => $input,
48         type            => "intranet",
49         authnotrequired => 0,
50         flagsrequired   => { borrowers => 1 },
51         debug           => 1,
52     }
53 );
54
55 my $borrowernumber = $input->param('borrowernumber');
56 my $catcode        = $input->param('catcode');
57 my $cattype        = $input->param('cattype');
58 my $catcode_multi = $input->param('catcode_multi');
59 my $op             = $input->param('op');
60
61 if ( $op eq 'multi' ) {
62     # FIXME - what are the possible upgrade paths?  C -> A , C -> S ...
63     #   currently just allowing C -> A
64     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
65     $template->param(
66         MULTI             => 1,
67         CATCODE_MULTI     => 1,
68         borrowernumber    => $borrowernumber,
69         patron_categories => $patron_categories,
70     );
71     output_html_with_http_headers $input, $cookie, $template->output;
72 }
73
74 elsif ( $op eq 'update' ) {
75     my $patron = Koha::Patrons->find( $borrowernumber );
76     unless ( $patron ) {
77         print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
78         exit;
79     }
80     my $member = $patron->unblessed;
81     $member->{'guarantorid'}  = 0;
82     $member->{'categorycode'} = $catcode;
83     my $borcat = Koha::Patron::Categories->find($catcode);
84     $member->{'category_type'} = $borcat->category_type;
85     $member->{'description'}   = $borcat->description;
86     delete $member->{password};
87     ModMember(%$member);
88
89     if (  $catcode_multi ) {
90         $template->param(
91                 SUCCESS        => 1,
92                 borrowernumber => $borrowernumber,
93                 );
94         output_html_with_http_headers $input, $cookie, $template->output;
95     } else {
96         print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
97     }
98 }
99