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
::Members
::Attributes
qw(GetBorrowerAttributes);
17 #use C4::Acquisitions;
23 my $flagsrequired = { permissions
=> 1 };
24 my $member=$input->param('member');
25 my $bor = GetMemberDetails
( $member,'');
26 if( $bor->{'category_type'} eq 'S' ) {
27 $flagsrequired->{'staffaccess'} = 1;
29 my ($template, $loggedinuser, $cookie)
30 = get_template_and_user
({template_name
=> "members/member-flags.tmpl",
34 flagsrequired
=> $flagsrequired,
40 $member2{'borrowernumber'}=$member;
42 if ($input->param('newflags')) {
43 my $dbh=C4
::Context
->dbh();
45 my @perms = $input->param('flag');
46 my %all_module_perms = ();
48 foreach my $perm (@perms) {
50 $all_module_perms{$perm} = 1;
52 my ($module, $sub_perm) = split /:/, $perm, 2;
53 push @
{ $sub_perms{$module} }, $sub_perm;
59 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
61 while (my ($bit, $flag) = $sth->fetchrow_array) {
62 if (exists $all_module_perms{$flag}) {
63 $module_flags += 2**$bit;
67 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
68 $sth->execute($module_flags, $member);
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);
84 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
86 # my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
87 my $flags = $bor->{'flags'};
88 my $accessflags = $bor->{'authflags'};
89 my $dbh=C4
::Context
->dbh();
90 my $all_perms = get_all_subpermissions
();
91 my $user_perms = get_user_subpermissions
($bor->{'userid'});
92 my $sth=$dbh->prepare("SELECT bit,flag,flagdesc FROM userflags ORDER BY bit");
95 while (my ($bit, $flag, $flagdesc) = $sth->fetchrow) {
97 if ($accessflags->{$flag}) {
101 my %row = ( bit
=> $bit,
104 flagdesc
=> $flagdesc );
106 my @sub_perm_loop = ();
107 my $expand_parent = 0;
109 if (exists $all_perms->{$flag}) {
111 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
112 push @sub_perm_loop, {
113 id
=> "${flag}_$sub_perm",
114 perm
=> "$flag:$sub_perm",
116 description
=> $all_perms->{$flag}->{$sub_perm},
122 if (exists $user_perms->{$flag}) {
124 # put selected ones first
125 foreach my $sub_perm (sort keys %{ $user_perms->{$flag} }) {
126 push @sub_perm_loop, {
127 id
=> "${flag}_$sub_perm",
128 perm
=> "$flag:$sub_perm",
130 description
=> $all_perms->{$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",
142 description
=> $all_perms->{$flag}->{$sub_perm},
144 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
148 $row{expand
} = $expand_parent;
149 if ($#sub_perm_loop > -1) {
150 $row{sub_perm_loop
} = \
@sub_perm_loop;
155 if ( $bor->{'category_type'} eq 'C') {
156 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
157 my $cnt = scalar(@
$catcodes);
158 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
159 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
162 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
163 my ($picture, $dberror) = GetPatronImage
($bor->{'borrowernumber'});
164 $template->param( picture
=> 1 ) if $picture;
166 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
167 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
169 ExtendedPatronAttributes
=> 1,
170 extendedattributes
=> $attributes
175 borrowernumber
=> $bor->{'borrowernumber'},
176 cardnumber
=> $bor->{'cardnumber'},
177 surname
=> $bor->{'surname'},
178 firstname
=> $bor->{'firstname'},
179 categorycode
=> $bor->{'categorycode'},
180 category_type
=> $bor->{'category_type'},
181 categoryname
=> $bor->{'description'},
182 address
=> $bor->{'address'},
183 address2
=> $bor->{'address2'},
184 city
=> $bor->{'city'},
185 state => $bor->{'state'},
186 zipcode
=> $bor->{'zipcode'},
187 country
=> $bor->{'country'},
188 phone
=> $bor->{'phone'},
189 email
=> $bor->{'email'},
190 branchcode
=> $bor->{'branchcode'},
191 branchname
=> GetBranchName
($bor->{'branchcode'}),
193 is_child
=> ($bor->{'category_type'} eq 'C'),
194 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
195 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
198 output_html_with_http_headers
$input, $cookie, $template->output;