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) = get_template_and_user
({
30 template_name
=> "members/member-flags.tt",
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 FROM userflags ORDER BY bit");
95 while (my ($bit, $flag) = $sth->fetchrow) {
97 if ($accessflags->{$flag}) {
101 my %row = ( bit
=> $bit,
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",
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",
133 # then ones not selected
134 if (exists $all_perms->{$flag}) {
135 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
136 push @sub_perm_loop, {
137 id
=> "${flag}_$sub_perm",
138 perm
=> "$flag:$sub_perm",
141 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
145 $row{expand
} = $expand_parent;
146 if ($#sub_perm_loop > -1) {
147 $row{sub_perm_loop
} = \
@sub_perm_loop;
152 if ( $bor->{'category_type'} eq 'C') {
153 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
154 my $cnt = scalar(@
$catcodes);
155 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
156 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
159 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
160 my ($picture, $dberror) = GetPatronImage
($bor->{'borrowernumber'});
161 $template->param( picture
=> 1 ) if $picture;
163 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
164 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
166 ExtendedPatronAttributes
=> 1,
167 extendedattributes
=> $attributes
171 # Computes full borrower address
172 my $roadtype = C4
::Koha
::GetAuthorisedValueByCode
( 'ROADTYPE', $bor->{streettype
} );
173 my $address = $bor->{'streetnumber'} . " $roadtype " . $bor->{'address'};
176 borrowernumber
=> $bor->{'borrowernumber'},
177 cardnumber
=> $bor->{'cardnumber'},
178 surname
=> $bor->{'surname'},
179 firstname
=> $bor->{'firstname'},
180 othernames
=> $bor->{'othernames'},
181 categorycode
=> $bor->{'categorycode'},
182 category_type
=> $bor->{'category_type'},
183 categoryname
=> $bor->{'description'},
185 address2
=> $bor->{'address2'},
186 city
=> $bor->{'city'},
187 state => $bor->{'state'},
188 zipcode
=> $bor->{'zipcode'},
189 country
=> $bor->{'country'},
190 phone
=> $bor->{'phone'},
191 phonepro
=> $bor->{'phonepro'},
192 mobile
=> $bor->{'mobile'},
193 email
=> $bor->{'email'},
194 emailpro
=> $bor->{'emailpro'},
195 branchcode
=> $bor->{'branchcode'},
196 branchname
=> GetBranchName
($bor->{'branchcode'}),
198 is_child
=> ($bor->{'category_type'} eq 'C'),
199 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
200 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
203 output_html_with_http_headers
$input, $cookie, $template->output;