3 # script to edit a member's flags
4 # Written by Steve Tonnesen
5 # July 26, 2002 (my birthday!)
12 use C4::Auth qw(:DEFAULT :EditPermissions);
16 use C4::Members::Attributes qw(GetBorrowerAttributes);
17 #use C4::Acquisitions;
20 use Koha::Patron::Images;
25 my $flagsrequired = { permissions => 1 };
26 my $member=$input->param('member');
27 my $bor = GetMemberDetails( $member,'');
28 if( $bor->{'category_type'} eq 'S' ) {
29 $flagsrequired->{'staffaccess'} = 1;
31 my ($template, $loggedinuser, $cookie) = get_template_and_user({
32 template_name => "members/member-flags.tt",
36 flagsrequired => $flagsrequired,
42 $member2{'borrowernumber'}=$member;
44 if ($input->param('newflags')) {
46 die "Wrong CSRF token"
47 unless Koha::Token->new->check_csrf({
48 session_id => scalar $input->cookie('CGISESSID'),
49 token => scalar $input->param('csrf_token'),
53 my $dbh=C4::Context->dbh();
55 my @perms = $input->multi_param('flag');
56 my %all_module_perms = ();
58 foreach my $perm (@perms) {
60 $all_module_perms{$perm} = 1;
62 my ($module, $sub_perm) = split /:/, $perm, 2;
63 push @{ $sub_perms{$module} }, $sub_perm;
69 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
71 while (my ($bit, $flag) = $sth->fetchrow_array) {
72 if (exists $all_module_perms{$flag}) {
73 $module_flags += 2**$bit;
77 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
78 $sth->execute($module_flags, $member);
80 # deal with subpermissions
81 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
82 $sth->execute($member);
83 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
87 foreach my $module (keys %sub_perms) {
88 next if exists $all_module_perms{$module};
89 foreach my $sub_perm (@{ $sub_perms{$module} }) {
90 $sth->execute($member, $sub_perm, $module);
94 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
96 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
97 my $flags = $bor->{'flags'};
98 my $accessflags = $bor->{'authflags'};
99 my $dbh=C4::Context->dbh();
100 my $all_perms = get_all_subpermissions();
101 my $user_perms = get_user_subpermissions($bor->{'userid'});
102 my $sth=$dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
105 while (my ($bit, $flag) = $sth->fetchrow) {
107 if ($accessflags->{$flag}) {
111 my %row = ( bit => $bit,
116 my @sub_perm_loop = ();
117 my $expand_parent = 0;
119 if (exists $all_perms->{$flag}) {
121 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
122 push @sub_perm_loop, {
123 id => "${flag}_$sub_perm",
124 perm => "$flag:$sub_perm",
131 if (exists $user_perms->{$flag}) {
133 # put selected ones first
134 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
135 push @sub_perm_loop, {
136 id => "${flag}_$sub_perm",
137 perm => "$flag:$sub_perm",
143 # then ones not selected
144 if (exists $all_perms->{$flag}) {
145 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
146 push @sub_perm_loop, {
147 id => "${flag}_$sub_perm",
148 perm => "$flag:$sub_perm",
151 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
155 $row{expand} = $expand_parent;
156 if ($#sub_perm_loop > -1) {
157 $row{sub_perm_loop} = \@sub_perm_loop;
162 if ( $bor->{'category_type'} eq 'C') {
163 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
164 my $cnt = scalar(@$catcodes);
165 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
166 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
169 $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
170 my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber});
171 $template->param( picture => 1 ) if $patron_image;
173 if (C4::Context->preference('ExtendedPatronAttributes')) {
174 my $attributes = GetBorrowerAttributes($bor->{'borrowernumber'});
176 ExtendedPatronAttributes => 1,
177 extendedattributes => $attributes
182 borrowernumber => $bor->{'borrowernumber'},
183 cardnumber => $bor->{'cardnumber'},
184 surname => $bor->{'surname'},
185 firstname => $bor->{'firstname'},
186 othernames => $bor->{'othernames'},
187 categorycode => $bor->{'categorycode'},
188 category_type => $bor->{'category_type'},
189 categoryname => $bor->{'description'},
190 address => $bor->{address},
191 address2 => $bor->{'address2'},
192 streettype => $bor->{streettype},
193 city => $bor->{'city'},
194 state => $bor->{'state'},
195 zipcode => $bor->{'zipcode'},
196 country => $bor->{'country'},
197 phone => $bor->{'phone'},
198 phonepro => $bor->{'phonepro'},
199 mobile => $bor->{'mobile'},
200 email => $bor->{'email'},
201 emailpro => $bor->{'emailpro'},
202 branchcode => $bor->{'branchcode'},
203 branchname => GetBranchName($bor->{'branchcode'}),
205 is_child => ($bor->{'category_type'} eq 'C'),
206 RoutingSerials => C4::Context->preference('RoutingSerials'),
207 csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID'), } ),
210 output_html_with_http_headers $input, $cookie, $template->output;