3 # script to edit a member's flags
4 # Written by Steve Tonnesen
5 # July 26, 2002 (my birthday!)
11 use Digest
::MD5
qw(md5_base64);
12 use Encode
qw( encode );
14 use C4
::Auth
qw(:DEFAULT :EditPermissions);
18 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
19 #use C4::Acquisitions;
22 use Koha
::Patron
::Images
;
27 my $flagsrequired = { permissions
=> 1 };
28 my $member=$input->param('member');
29 my $bor = GetMemberDetails
( $member,'');
30 if( $bor->{'category_type'} eq 'S' ) {
31 $flagsrequired->{'staffaccess'} = 1;
33 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
34 template_name
=> "members/member-flags.tt",
38 flagsrequired
=> $flagsrequired,
44 $member2{'borrowernumber'}=$member;
46 if ($input->param('newflags')) {
48 die "Wrong CSRF token"
49 unless Koha
::Token
->new->check_csrf({
50 id
=> Encode
::encode
( 'UTF-8', C4
::Context
->userenv->{id
} ),
51 secret
=> md5_base64
( Encode
::encode
( 'UTF-8', C4
::Context
->config('pass') ) ),
52 token
=> scalar $input->param('csrf_token'),
56 my $dbh=C4
::Context
->dbh();
58 my @perms = $input->multi_param('flag');
59 my %all_module_perms = ();
61 foreach my $perm (@perms) {
63 $all_module_perms{$perm} = 1;
65 my ($module, $sub_perm) = split /:/, $perm, 2;
66 push @
{ $sub_perms{$module} }, $sub_perm;
72 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
74 while (my ($bit, $flag) = $sth->fetchrow_array) {
75 if (exists $all_module_perms{$flag}) {
76 $module_flags += 2**$bit;
80 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
81 $sth->execute($module_flags, $member);
83 # deal with subpermissions
84 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
85 $sth->execute($member);
86 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
90 foreach my $module (keys %sub_perms) {
91 next if exists $all_module_perms{$module};
92 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
93 $sth->execute($member, $sub_perm, $module);
97 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
99 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
100 my $flags = $bor->{'flags'};
101 my $accessflags = $bor->{'authflags'};
102 my $dbh=C4
::Context
->dbh();
103 my $all_perms = get_all_subpermissions
();
104 my $user_perms = get_user_subpermissions
($bor->{'userid'});
105 my $sth=$dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
108 while (my ($bit, $flag) = $sth->fetchrow) {
110 if ($accessflags->{$flag}) {
114 my %row = ( bit
=> $bit,
119 my @sub_perm_loop = ();
120 my $expand_parent = 0;
122 if (exists $all_perms->{$flag}) {
124 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
125 push @sub_perm_loop, {
126 id
=> "${flag}_$sub_perm",
127 perm
=> "$flag:$sub_perm",
134 if (exists $user_perms->{$flag}) {
136 # put selected ones first
137 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
138 push @sub_perm_loop, {
139 id
=> "${flag}_$sub_perm",
140 perm
=> "$flag:$sub_perm",
146 # then ones not selected
147 if (exists $all_perms->{$flag}) {
148 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
149 push @sub_perm_loop, {
150 id
=> "${flag}_$sub_perm",
151 perm
=> "$flag:$sub_perm",
154 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
158 $row{expand
} = $expand_parent;
159 if ($#sub_perm_loop > -1) {
160 $row{sub_perm_loop
} = \
@sub_perm_loop;
165 if ( $bor->{'category_type'} eq 'C') {
166 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
167 my $cnt = scalar(@
$catcodes);
168 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
169 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
172 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
173 my $patron_image = Koha
::Patron
::Images
->find($bor->{borrowernumber
});
174 $template->param( picture
=> 1 ) if $patron_image;
176 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
177 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
179 ExtendedPatronAttributes
=> 1,
180 extendedattributes
=> $attributes
185 borrowernumber
=> $bor->{'borrowernumber'},
186 cardnumber
=> $bor->{'cardnumber'},
187 surname
=> $bor->{'surname'},
188 firstname
=> $bor->{'firstname'},
189 othernames
=> $bor->{'othernames'},
190 categorycode
=> $bor->{'categorycode'},
191 category_type
=> $bor->{'category_type'},
192 categoryname
=> $bor->{'description'},
193 address
=> $bor->{address
},
194 address2
=> $bor->{'address2'},
195 streettype
=> $bor->{streettype
},
196 city
=> $bor->{'city'},
197 state => $bor->{'state'},
198 zipcode
=> $bor->{'zipcode'},
199 country
=> $bor->{'country'},
200 phone
=> $bor->{'phone'},
201 phonepro
=> $bor->{'phonepro'},
202 mobile
=> $bor->{'mobile'},
203 email
=> $bor->{'email'},
204 emailpro
=> $bor->{'emailpro'},
205 branchcode
=> $bor->{'branchcode'},
206 branchname
=> GetBranchName
($bor->{'branchcode'}),
208 is_child
=> ($bor->{'category_type'} eq 'C'),
209 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
210 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
211 csrf_token
=> Koha
::Token
->new->generate_csrf(
212 { id
=> Encode
::encode
( 'UTF-8', C4
::Context
->userenv->{id
} ),
213 secret
=> md5_base64
( Encode
::encode
( 'UTF-8', C4
::Context
->config('pass') ) ),
218 output_html_with_http_headers
$input, $cookie, $template->output;