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 = 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')) {
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");
88 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
89 my $flags = $bor->{'flags'};
90 my $accessflags = $bor->{'authflags'};
91 my $dbh=C4
::Context
->dbh();
92 my $all_perms = get_all_subpermissions
();
93 my $user_perms = get_user_subpermissions
($bor->{'userid'});
94 my $sth=$dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit");
97 while (my ($bit, $flag) = $sth->fetchrow) {
99 if ($accessflags->{$flag}) {
103 my %row = ( bit
=> $bit,
108 my @sub_perm_loop = ();
109 my $expand_parent = 0;
111 if (exists $all_perms->{$flag}) {
113 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
114 push @sub_perm_loop, {
115 id
=> "${flag}_$sub_perm",
116 perm
=> "$flag:$sub_perm",
123 if (exists $user_perms->{$flag}) {
125 # put selected ones first
126 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
127 push @sub_perm_loop, {
128 id
=> "${flag}_$sub_perm",
129 perm
=> "$flag:$sub_perm",
135 # then ones not selected
136 if (exists $all_perms->{$flag}) {
137 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
138 push @sub_perm_loop, {
139 id
=> "${flag}_$sub_perm",
140 perm
=> "$flag:$sub_perm",
143 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
147 $row{expand
} = $expand_parent;
148 if ($#sub_perm_loop > -1) {
149 $row{sub_perm_loop
} = \
@sub_perm_loop;
154 if ( $bor->{'category_type'} eq 'C') {
155 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
156 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
157 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
160 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
161 my $patron_image = Koha
::Patron
::Images
->find($bor->{borrowernumber
});
162 $template->param( picture
=> 1 ) if $patron_image;
164 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
165 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
167 ExtendedPatronAttributes
=> 1,
168 extendedattributes
=> $attributes
173 borrowernumber
=> $bor->{'borrowernumber'},
174 cardnumber
=> $bor->{'cardnumber'},
175 surname
=> $bor->{'surname'},
176 firstname
=> $bor->{'firstname'},
177 othernames
=> $bor->{'othernames'},
178 categorycode
=> $bor->{'categorycode'},
179 category_type
=> $bor->{'category_type'},
180 categoryname
=> $bor->{'description'},
181 address
=> $bor->{address
},
182 address2
=> $bor->{'address2'},
183 streettype
=> $bor->{streettype
},
184 city
=> $bor->{'city'},
185 state => $bor->{'state'},
186 zipcode
=> $bor->{'zipcode'},
187 country
=> $bor->{'country'},
188 phone
=> $bor->{'phone'},
189 phonepro
=> $bor->{'phonepro'},
190 mobile
=> $bor->{'mobile'},
191 email
=> $bor->{'email'},
192 emailpro
=> $bor->{'emailpro'},
193 branchcode
=> $bor->{'branchcode'},
195 is_child
=> ($bor->{'category_type'} eq 'C'),
196 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
197 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
200 output_html_with_http_headers
$input, $cookie, $template->output;