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
;
25 my $flagsrequired = { permissions
=> 1 };
26 my $member=$input->param('member');
27 my $bor = GetMember
( borrowernumber
=> $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')) {
45 my $dbh=C4
::Context
->dbh();
47 my @perms = $input->multi_param('flag');
48 my %all_module_perms = ();
50 foreach my $perm (@perms) {
52 $all_module_perms{$perm} = 1;
54 my ($module, $sub_perm) = split /:/, $perm, 2;
55 push @
{ $sub_perms{$module} }, $sub_perm;
61 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
63 while (my ($bit, $flag) = $sth->fetchrow_array) {
64 if (exists $all_module_perms{$flag}) {
65 $module_flags += 2**$bit;
69 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
70 $sth->execute($module_flags, $member);
72 # deal with subpermissions
73 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
74 $sth->execute($member);
75 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
79 foreach my $module (keys %sub_perms) {
80 next if exists $all_module_perms{$module};
81 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
82 $sth->execute($member, $sub_perm, $module);
86 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
89 my $flags = C4
::Members
::patronflags
( $bor );
91 my $dbh = C4
::Context
->dbh();
92 # FIXME This needs to be improved to avoid doing the same query
93 my $sth = $dbh->prepare("select bit,flag from userflags");
95 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
96 if ( $bor->{flags
} && $bor->{flags
} & 2**$bit ) {
97 $accessflags->{$flag} = 1;
101 my $all_perms = get_all_subpermissions
();
102 my $user_perms = get_user_subpermissions
($bor->{'userid'});
103 $sth = $dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
107 while (my ($bit, $flag) = $sth->fetchrow) {
109 if ($accessflags->{$flag}) {
113 my %row = ( bit
=> $bit,
118 my @sub_perm_loop = ();
119 my $expand_parent = 0;
121 if (exists $all_perms->{$flag}) {
123 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
124 push @sub_perm_loop, {
125 id
=> "${flag}_$sub_perm",
126 perm
=> "$flag:$sub_perm",
133 if (exists $user_perms->{$flag}) {
135 # put selected ones first
136 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
137 push @sub_perm_loop, {
138 id
=> "${flag}_$sub_perm",
139 perm
=> "$flag:$sub_perm",
145 # then ones not selected
146 if (exists $all_perms->{$flag}) {
147 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
148 push @sub_perm_loop, {
149 id
=> "${flag}_$sub_perm",
150 perm
=> "$flag:$sub_perm",
153 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
157 $row{expand
} = $expand_parent;
158 if ($#sub_perm_loop > -1) {
159 $row{sub_perm_loop
} = \
@sub_perm_loop;
164 if ( $bor->{'category_type'} eq 'C') {
165 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
166 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
167 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
170 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
171 my $patron_image = Koha
::Patron
::Images
->find($bor->{borrowernumber
});
172 $template->param( picture
=> 1 ) if $patron_image;
174 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
175 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
177 ExtendedPatronAttributes
=> 1,
178 extendedattributes
=> $attributes
183 borrowernumber
=> $bor->{'borrowernumber'},
184 cardnumber
=> $bor->{'cardnumber'},
185 surname
=> $bor->{'surname'},
186 firstname
=> $bor->{'firstname'},
187 othernames
=> $bor->{'othernames'},
188 categorycode
=> $bor->{'categorycode'},
189 category_type
=> $bor->{'category_type'},
190 categoryname
=> $bor->{'description'},
191 address
=> $bor->{address
},
192 address2
=> $bor->{'address2'},
193 streettype
=> $bor->{streettype
},
194 city
=> $bor->{'city'},
195 state => $bor->{'state'},
196 zipcode
=> $bor->{'zipcode'},
197 country
=> $bor->{'country'},
198 phone
=> $bor->{'phone'},
199 phonepro
=> $bor->{'phonepro'},
200 mobile
=> $bor->{'mobile'},
201 email
=> $bor->{'email'},
202 emailpro
=> $bor->{'emailpro'},
203 branchcode
=> $bor->{'branchcode'},
205 is_child
=> ($bor->{'category_type'} eq 'C'),
206 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
207 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
210 output_html_with_http_headers
$input, $cookie, $template->output;