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);
15 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
16 #use C4::Acquisitions;
18 use Koha
::Patron
::Categories
;
22 use Koha
::Patron
::Images
;
27 my $flagsrequired = { permissions
=> 1 };
28 my $member=$input->param('member');
29 my $patron = Koha
::Patrons
->find( $member );
31 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$member");
35 my $category_type = $patron->category->category_type;
36 my $bor = $patron->unblessed;
37 if( $category_type eq 'S' ) {
38 $flagsrequired->{'staffaccess'} = 1;
40 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
41 template_name
=> "members/member-flags.tt",
45 flagsrequired
=> $flagsrequired,
51 $member2{'borrowernumber'}=$member;
53 if ($input->param('newflags')) {
55 die "Wrong CSRF token"
56 unless Koha
::Token
->new->check_csrf({
57 session_id
=> scalar $input->cookie('CGISESSID'),
58 token
=> scalar $input->param('csrf_token'),
62 my $dbh=C4
::Context
->dbh();
64 my @perms = $input->multi_param('flag');
65 my %all_module_perms = ();
67 foreach my $perm (@perms) {
69 $all_module_perms{$perm} = 1;
71 my ($module, $sub_perm) = split /:/, $perm, 2;
72 push @
{ $sub_perms{$module} }, $sub_perm;
78 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
80 while (my ($bit, $flag) = $sth->fetchrow_array) {
81 if (exists $all_module_perms{$flag}) {
82 $module_flags += 2**$bit;
86 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
87 $sth->execute($module_flags, $member);
89 # deal with subpermissions
90 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
91 $sth->execute($member);
92 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
96 foreach my $module (keys %sub_perms) {
97 next if exists $all_module_perms{$module};
98 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
99 $sth->execute($member, $sub_perm, $module);
103 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
106 my $flags = C4
::Members
::patronflags
( $bor );
108 my $dbh = C4
::Context
->dbh();
109 # FIXME This needs to be improved to avoid doing the same query
110 my $sth = $dbh->prepare("select bit,flag from userflags");
112 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
113 if ( $bor->{flags
} && $bor->{flags
} & 2**$bit ) {
114 $accessflags->{$flag} = 1;
118 my $all_perms = get_all_subpermissions
();
119 my $user_perms = get_user_subpermissions
($bor->{'userid'});
120 $sth = $dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
124 while (my ($bit, $flag) = $sth->fetchrow) {
126 if ($accessflags->{$flag}) {
130 my %row = ( bit
=> $bit,
135 my @sub_perm_loop = ();
136 my $expand_parent = 0;
138 if (exists $all_perms->{$flag}) {
140 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
141 push @sub_perm_loop, {
142 id
=> "${flag}_$sub_perm",
143 perm
=> "$flag:$sub_perm",
150 if (exists $user_perms->{$flag}) {
152 # put selected ones first
153 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
154 push @sub_perm_loop, {
155 id
=> "${flag}_$sub_perm",
156 perm
=> "$flag:$sub_perm",
162 # then ones not selected
163 if (exists $all_perms->{$flag}) {
164 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
165 push @sub_perm_loop, {
166 id
=> "${flag}_$sub_perm",
167 perm
=> "$flag:$sub_perm",
170 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
174 $row{expand
} = $expand_parent;
175 if ($#sub_perm_loop > -1) {
176 $row{sub_perm_loop
} = \
@sub_perm_loop;
181 if ( $category_type eq 'C') {
182 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
183 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
184 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
187 $template->param( adultborrower
=> 1 ) if ( $category_type =~ /^(A|I)$/ );
188 $template->param( picture
=> 1 ) if $patron->image;
190 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
191 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
193 ExtendedPatronAttributes
=> 1,
194 extendedattributes
=> $attributes
199 borrowernumber
=> $bor->{'borrowernumber'},
200 cardnumber
=> $bor->{'cardnumber'},
201 surname
=> $bor->{'surname'},
202 firstname
=> $bor->{'firstname'},
203 othernames
=> $bor->{'othernames'},
204 categorycode
=> $bor->{'categorycode'},
205 category_type
=> $category_type,
206 categoryname
=> $bor->{'description'},
207 address
=> $bor->{address
},
208 address2
=> $bor->{'address2'},
209 streettype
=> $bor->{streettype
},
210 city
=> $bor->{'city'},
211 state => $bor->{'state'},
212 zipcode
=> $bor->{'zipcode'},
213 country
=> $bor->{'country'},
214 phone
=> $bor->{'phone'},
215 phonepro
=> $bor->{'phonepro'},
216 mobile
=> $bor->{'mobile'},
217 email
=> $bor->{'email'},
218 emailpro
=> $bor->{'emailpro'},
219 branchcode
=> $bor->{'branchcode'},
221 is_child
=> ( $category_type eq 'C' ),
222 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
224 Koha
::Token
->new->generate_csrf( { session_id
=> scalar $input->cookie('CGISESSID'), } ),
227 output_html_with_http_headers
$input, $cookie, $template->output;