Passing "adultborrower" variable to the template so that "Add Child" button can be...
[wip/koha-chris_n.git] / members / member-flags.pl
1 #!/usr/bin/perl
2
3 # script to edit a member's flags
4 # Written by Steve Tonnesen
5 # July 26, 2002 (my birthday!)
6
7 use strict;
8
9 use CGI;
10 use C4::Output;
11 use C4::Auth;
12 use C4::Context;
13 use C4::Members;
14 #use C4::Acquisitions;
15
16 use C4::Output;
17
18 my $input = new CGI;
19
20 my $flagsrequired = { permissions => 1 };
21 my $member=$input->param('member');
22 my $bor = GetMemberDetails( $member,'');
23 if(( $bor->{'category_type'} eq 'S' ) || ($bor->{'authflags'}->{'catalogue'} )) {
24         $flagsrequired->{'staffaccess'} = 1;
25 }
26 my ($template, $loggedinuser, $cookie)
27         = get_template_and_user({template_name => "members/member-flags.tmpl",
28                                 query => $input,
29                                 type => "intranet",
30                                 authnotrequired => 0,
31                                 flagsrequired => $flagsrequired,
32                                 debug => 1,
33                                 });
34
35
36 my %member2;
37 $member2{'borrowernumber'}=$member;
38
39 if ($input->param('newflags')) {
40     my $dbh=C4::Context->dbh();
41     my $flags=0;
42     foreach ($input->param) {
43         if (/flag-(\d+)/) {
44             my $flag=$1;
45             $flags=$flags+2**$flag;
46         }
47     }
48     my $sth=$dbh->prepare("update borrowers set flags=? where borrowernumber=?");
49     $sth->execute($flags, $member);
50     print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
51 } else {
52 #     my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
53     my $flags = $bor->{'flags'};
54     my $accessflags = $bor->{'authflags'};
55     my $dbh=C4::Context->dbh();
56     my $sth=$dbh->prepare("select bit,flag,flagdesc from userflags order by bit");
57     $sth->execute;
58     my @loop;
59     while (my ($bit, $flag, $flagdesc) = $sth->fetchrow) {
60         my $checked='';
61         if ($accessflags->{$flag}) {
62             $checked= 1;
63         }
64         my %row = ( bit => $bit,
65                  flag => $flag,
66                  checked => $checked,
67                  flagdesc => $flagdesc );
68         push @loop, \%row;
69     }
70
71         my $borrowercategory = GetBorrowercategory( $bor->{'categorycode'} );
72 my $category_type = $borrowercategory->{'category_type'};
73 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
74         
75     $template->param(borrowernumber => $member,
76                     borrowernumber => $bor->{'borrowernumber'},
77                 cardnumber => $bor->{'cardnumber'},
78                     surname => $bor->{'surname'},
79                     firstname => $bor->{'firstname'},
80                     categorycode => $bor->{'categorycode'},
81                     category_type => $bor->{'category_type'},
82                     category_description => $bor->{'description'},
83                     address => $bor->{'address'},
84                         address2 => $bor->{'address2'},
85                     city => $bor->{'city'},
86                         zipcode => $bor->{'zipcode'},
87                         phone => $bor->{'phone'},
88                         email => $bor->{'email'},
89                     branchcode => $bor->{'branchcode'},
90                         loop => \@loop,
91                         );
92
93     output_html_with_http_headers $input, $cookie, $template->output;
94
95 }