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 # deal with subpermissions
70 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
71 $sth->execute($member);
72 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
76 foreach my $module (keys %sub_perms) {
77 next if exists $all_module_perms{$module};
78 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
79 $sth->execute($member, $sub_perm, $module);
83 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
85 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
86 my $flags = $bor->{'flags'};
87 my $accessflags = $bor->{'authflags'};
88 my $dbh=C4
::Context
->dbh();
89 my $all_perms = get_all_subpermissions
();
90 my $user_perms = get_user_subpermissions
($bor->{'userid'});
91 my $sth=$dbh->prepare("SELECT bit,flag,flagdesc FROM userflags ORDER BY bit");
94 while (my ($bit, $flag, $flagdesc) = $sth->fetchrow) {
96 if ($accessflags->{$flag}) {
100 my %row = ( bit
=> $bit,
103 flagdesc
=> $flagdesc );
105 my @sub_perm_loop = ();
106 my $expand_parent = 0;
108 if (exists $all_perms->{$flag}) {
110 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
111 push @sub_perm_loop, {
112 id
=> "${flag}_$sub_perm",
113 perm
=> "$flag:$sub_perm",
115 description
=> $all_perms->{$flag}->{$sub_perm},
121 if (exists $user_perms->{$flag}) {
123 # put selected ones first
124 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
125 push @sub_perm_loop, {
126 id
=> "${flag}_$sub_perm",
127 perm
=> "$flag:$sub_perm",
129 description
=> $all_perms->{$flag}->{$sub_perm},
134 # then ones not selected
135 if (exists $all_perms->{$flag}) {
136 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
137 push @sub_perm_loop, {
138 id
=> "${flag}_$sub_perm",
139 perm
=> "$flag:$sub_perm",
141 description
=> $all_perms->{$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 ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
156 my $cnt = scalar(@
$catcodes);
157 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
158 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
161 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
162 my ($picture, $dberror) = GetPatronImage
($bor->{'cardnumber'});
163 $template->param( picture
=> 1 ) if $picture;
166 borrowernumber
=> $bor->{'borrowernumber'},
167 cardnumber
=> $bor->{'cardnumber'},
168 surname
=> $bor->{'surname'},
169 firstname
=> $bor->{'firstname'},
170 categorycode
=> $bor->{'categorycode'},
171 category_type
=> $bor->{'category_type'},
172 categoryname
=> $bor->{'description'},
173 address
=> $bor->{'address'},
174 address2
=> $bor->{'address2'},
175 city
=> $bor->{'city'},
176 state => $bor->{'state'},
177 zipcode
=> $bor->{'zipcode'},
178 country
=> $bor->{'country'},
179 phone
=> $bor->{'phone'},
180 email
=> $bor->{'email'},
181 branchcode
=> $bor->{'branchcode'},
182 branchname
=> GetBranchName
($bor->{'branchcode'}),
184 is_child
=> ($bor->{'category_type'} eq 'C'),
187 output_html_with_http_headers
$input, $cookie, $template->output;