Merge commit 'pianohacker-koha/prefs-submit' into master
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 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 CGI;
31 use C4::Context;
32 use C4::Auth;
33 use C4::Output;
34 use C4::Members;
35
36 # use Smart::Comments;
37
38 my $dbh   = C4::Context->dbh;
39 my $input = new CGI;
40
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42     {
43         template_name   => "members/update-child.tmpl",
44         query           => $input,
45         type            => "intranet",
46         authnotrequired => 0,
47         flagsrequired   => { borrowers => 1 },
48         debug           => 1,
49     }
50 );
51
52 my $borrowernumber = $input->param('borrowernumber');
53 my $catcode        = $input->param('catcode');
54 my $cattype        = $input->param('cattype');
55 my $catcode_multi = $input->param('catcode_multi');
56 my $op             = $input->param('op');
57
58 if ( $op eq 'multi' ) {
59     my ( $catcodes, $labels ) =
60                 # FIXME - what are the possible upgrade paths?  C -> A , C -> S ...
61                 #   currently just allowing C -> A because of limitation of API.
62       GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
63     my @rows;
64     foreach my $k ( keys %$labels ) {
65         my $row;
66         $row->{catcode} = $k;
67         $row->{catdesc} = $labels->{$k};
68         my $borcat = GetBorrowercategory( $row->{catcode} );
69         $row->{cattype} = $borcat->{'category_type'};
70         push @rows, $row;
71     }
72     $template->param(
73         MULTI          => 1,
74         CATCODE_MULTI          => 1,
75         borrowernumber => $borrowernumber,
76         CAT_LOOP       => \@rows,
77     );
78     output_html_with_http_headers $input, $cookie, $template->output;
79 }
80
81 elsif ( $op eq 'update' ) {
82     my $member = GetMember('borrowernumber'=>$borrowernumber);
83     $member->{'guarantorid'}  = '0';
84     $member->{'categorycode'} = $catcode;
85     my $borcat = GetBorrowercategory($catcode);
86     $member->{'category_type'} = $borcat->{'category_type'};
87     $member->{'description'}   = $borcat->{'description'};
88     ModMember(%$member);
89
90     if (  $catcode_multi ) {
91         $template->param(
92                 SUCCESS        => 1,
93                 borrowernumber => $borrowernumber,
94                 );
95         output_html_with_http_headers $input, $cookie, $template->output;
96     } else {
97         print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
98     }
99 }
100