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
;
21 use Koha
::Patron
::Images
;
26 my $flagsrequired = { permissions
=> 1 };
27 my $member=$input->param('member');
28 my $bor = GetMember
( borrowernumber
=> $member );
29 if( $bor->{'category_type'} eq 'S' ) {
30 $flagsrequired->{'staffaccess'} = 1;
32 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
33 template_name
=> "members/member-flags.tt",
37 flagsrequired
=> $flagsrequired,
43 $member2{'borrowernumber'}=$member;
45 if ($input->param('newflags')) {
47 die "Wrong CSRF token"
48 unless Koha
::Token
->new->check_csrf({
49 session_id
=> scalar $input->cookie('CGISESSID'),
50 token
=> scalar $input->param('csrf_token'),
54 my $dbh=C4
::Context
->dbh();
56 my @perms = $input->multi_param('flag');
57 my %all_module_perms = ();
59 foreach my $perm (@perms) {
61 $all_module_perms{$perm} = 1;
63 my ($module, $sub_perm) = split /:/, $perm, 2;
64 push @
{ $sub_perms{$module} }, $sub_perm;
70 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
72 while (my ($bit, $flag) = $sth->fetchrow_array) {
73 if (exists $all_module_perms{$flag}) {
74 $module_flags += 2**$bit;
78 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
79 $sth->execute($module_flags, $member);
81 # deal with subpermissions
82 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
83 $sth->execute($member);
84 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
88 foreach my $module (keys %sub_perms) {
89 next if exists $all_module_perms{$module};
90 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
91 $sth->execute($member, $sub_perm, $module);
95 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
98 my $flags = C4
::Members
::patronflags
( $bor );
100 my $dbh = C4
::Context
->dbh();
101 # FIXME This needs to be improved to avoid doing the same query
102 my $sth = $dbh->prepare("select bit,flag from userflags");
104 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
105 if ( $bor->{flags
} && $bor->{flags
} & 2**$bit ) {
106 $accessflags->{$flag} = 1;
110 my $all_perms = get_all_subpermissions
();
111 my $user_perms = get_user_subpermissions
($bor->{'userid'});
112 $sth = $dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
116 while (my ($bit, $flag) = $sth->fetchrow) {
118 if ($accessflags->{$flag}) {
122 my %row = ( bit
=> $bit,
127 my @sub_perm_loop = ();
128 my $expand_parent = 0;
130 if (exists $all_perms->{$flag}) {
132 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
133 push @sub_perm_loop, {
134 id
=> "${flag}_$sub_perm",
135 perm
=> "$flag:$sub_perm",
142 if (exists $user_perms->{$flag}) {
144 # put selected ones first
145 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
146 push @sub_perm_loop, {
147 id
=> "${flag}_$sub_perm",
148 perm
=> "$flag:$sub_perm",
154 # then ones not selected
155 if (exists $all_perms->{$flag}) {
156 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
157 push @sub_perm_loop, {
158 id
=> "${flag}_$sub_perm",
159 perm
=> "$flag:$sub_perm",
162 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
166 $row{expand
} = $expand_parent;
167 if ($#sub_perm_loop > -1) {
168 $row{sub_perm_loop
} = \
@sub_perm_loop;
173 if ( $bor->{'category_type'} eq 'C') {
174 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
175 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
176 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
179 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' || $bor->{'category_type'} eq 'I' );
180 my $patron_image = Koha
::Patron
::Images
->find($bor->{borrowernumber
});
181 $template->param( picture
=> 1 ) if $patron_image;
183 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
184 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
186 ExtendedPatronAttributes
=> 1,
187 extendedattributes
=> $attributes
192 borrowernumber
=> $bor->{'borrowernumber'},
193 cardnumber
=> $bor->{'cardnumber'},
194 surname
=> $bor->{'surname'},
195 firstname
=> $bor->{'firstname'},
196 othernames
=> $bor->{'othernames'},
197 categorycode
=> $bor->{'categorycode'},
198 category_type
=> $bor->{'category_type'},
199 categoryname
=> $bor->{'description'},
200 address
=> $bor->{address
},
201 address2
=> $bor->{'address2'},
202 streettype
=> $bor->{streettype
},
203 city
=> $bor->{'city'},
204 state => $bor->{'state'},
205 zipcode
=> $bor->{'zipcode'},
206 country
=> $bor->{'country'},
207 phone
=> $bor->{'phone'},
208 phonepro
=> $bor->{'phonepro'},
209 mobile
=> $bor->{'mobile'},
210 email
=> $bor->{'email'},
211 emailpro
=> $bor->{'emailpro'},
212 branchcode
=> $bor->{'branchcode'},
214 is_child
=> ($bor->{'category_type'} eq 'C'),
215 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
216 csrf_token
=> Koha
::Token
->new->generate_csrf( { session_id
=> scalar $input->cookie('CGISESSID'), } ),
219 output_html_with_http_headers
$input, $cookie, $template->output;