Merge remote-tracking branch 'origin/new/bug_8636'
[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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
32 use C4::Context;
33 use C4::Auth;
34 use C4::Output;
35 use C4::Members;
36
37 # use Smart::Comments;
38
39 my $dbh   = C4::Context->dbh;
40 my $input = new CGI;
41
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "members/update-child.tmpl",
45         query           => $input,
46         type            => "intranet",
47         authnotrequired => 0,
48         flagsrequired   => { borrowers => 1 },
49         debug           => 1,
50     }
51 );
52
53 my $borrowernumber = $input->param('borrowernumber');
54 my $catcode        = $input->param('catcode');
55 my $cattype        = $input->param('cattype');
56 my $catcode_multi = $input->param('catcode_multi');
57 my $op             = $input->param('op');
58
59 if ( $op eq 'multi' ) {
60     my ( $catcodes, $labels ) =
61                 # FIXME - what are the possible upgrade paths?  C -> A , C -> S ...
62                 #   currently just allowing C -> A because of limitation of API.
63       GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
64     my @rows;
65     foreach my $k ( keys %$labels ) {
66         my $row;
67         $row->{catcode} = $k;
68         $row->{catdesc} = $labels->{$k};
69         my $borcat = GetBorrowercategory( $row->{catcode} );
70         $row->{cattype} = $borcat->{'category_type'};
71         push @rows, $row;
72     }
73     $template->param(
74         MULTI          => 1,
75         CATCODE_MULTI          => 1,
76         borrowernumber => $borrowernumber,
77         CAT_LOOP       => \@rows,
78     );
79     output_html_with_http_headers $input, $cookie, $template->output;
80 }
81
82 elsif ( $op eq 'update' ) {
83     my $member = GetMember('borrowernumber'=>$borrowernumber);
84     $member->{'guarantorid'}  = 0;
85     $member->{'categorycode'} = $catcode;
86     my $borcat = GetBorrowercategory($catcode);
87     $member->{'category_type'} = $borcat->{'category_type'};
88     $member->{'description'}   = $borcat->{'description'};
89     ModMember(%$member);
90
91     if (  $catcode_multi ) {
92         $template->param(
93                 SUCCESS        => 1,
94                 borrowernumber => $borrowernumber,
95                 );
96         output_html_with_http_headers $input, $cookie, $template->output;
97     } else {
98         print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
99     }
100 }
101