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);
16 #use C4::Acquisitions;
22 my $flagsrequired = { permissions
=> 1 };
23 my $member=$input->param('member');
24 my $bor = GetMemberDetails
( $member,'');
25 if( $bor->{'category_type'} eq 'S' ) {
26 $flagsrequired->{'staffaccess'} = 1;
28 my ($template, $loggedinuser, $cookie)
29 = get_template_and_user
({template_name
=> "members/member-flags.tmpl",
33 flagsrequired
=> $flagsrequired,
39 $member2{'borrowernumber'}=$member;
41 if ($input->param('newflags')) {
42 my $dbh=C4
::Context
->dbh();
44 my @perms = $input->param('flag');
45 my %all_module_perms = ();
47 foreach my $perm (@perms) {
49 $all_module_perms{$perm} = 1;
51 my ($module, $sub_perm) = split /:/, $perm, 2;
52 push @
{ $sub_perms{$module} }, $sub_perm;
58 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
60 while (my ($bit, $flag) = $sth->fetchrow_array) {
61 if (exists $all_module_perms{$flag}) {
62 $module_flags += 2**$bit;
66 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
67 $sth->execute($module_flags, $member);
69 if (C4
::Context
->preference('GranularPermissions')) {
70 # deal with subpermissions
71 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
72 $sth->execute($member);
73 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
77 foreach my $module (keys %sub_perms) {
78 next if exists $all_module_perms{$module};
79 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
80 $sth->execute($member, $sub_perm, $module);
85 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
87 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
88 my $flags = $bor->{'flags'};
89 my $accessflags = $bor->{'authflags'};
90 my $dbh=C4
::Context
->dbh();
91 my $all_perms = get_all_subpermissions
();
92 my $user_perms = get_user_subpermissions
($bor->{'userid'});
93 my $sth=$dbh->prepare("SELECT bit,flag,flagdesc FROM userflags ORDER BY bit");
96 while (my ($bit, $flag, $flagdesc) = $sth->fetchrow) {
98 if ($accessflags->{$flag}) {
102 my %row = ( bit
=> $bit,
105 flagdesc
=> $flagdesc );
107 if (C4
::Context
->preference('GranularPermissions')) {
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",
118 description
=> $all_perms->{$flag}->{$sub_perm},
124 if (exists $user_perms->{$flag}) {
126 # put selected ones first
127 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
128 push @sub_perm_loop, {
129 id
=> "${flag}_$sub_perm",
130 perm
=> "$flag:$sub_perm",
132 description
=> $all_perms->{$flag}->{$sub_perm},
137 # then ones not selected
138 if (exists $all_perms->{$flag}) {
139 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
140 push @sub_perm_loop, {
141 id
=> "${flag}_$sub_perm",
142 perm
=> "$flag:$sub_perm",
144 description
=> $all_perms->{$flag}->{$sub_perm},
146 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
150 $row{expand
} = $expand_parent;
151 if ($#sub_perm_loop > -1) {
152 $row{sub_perm_loop
} = \
@sub_perm_loop;
158 if ( $bor->{'category_type'} eq 'C') {
159 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
160 my $cnt = scalar(@
$catcodes);
161 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
162 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
165 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
166 my ($picture, $dberror) = GetPatronImage
($bor->{'cardnumber'});
167 $template->param( picture
=> 1 ) if $picture;
170 borrowernumber
=> $bor->{'borrowernumber'},
171 cardnumber
=> $bor->{'cardnumber'},
172 surname
=> $bor->{'surname'},
173 firstname
=> $bor->{'firstname'},
174 categorycode
=> $bor->{'categorycode'},
175 category_type
=> $bor->{'category_type'},
176 categoryname
=> $bor->{'description'},
177 address
=> $bor->{'address'},
178 address2
=> $bor->{'address2'},
179 city
=> $bor->{'city'},
180 zipcode
=> $bor->{'zipcode'},
181 country
=> $bor->{'country'},
182 phone
=> $bor->{'phone'},
183 email
=> $bor->{'email'},
184 branchcode
=> $bor->{'branchcode'},
185 branchname
=> GetBranchName
($bor->{'branchcode'}),
187 is_child
=> ($bor->{'category_type'} eq 'C'),
190 output_html_with_http_headers
$input, $cookie, $template->output;