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;
20 use Koha
::Patron
::Images
;
24 my $flagsrequired = { permissions
=> 1 };
25 my $member=$input->param('member');
26 my $bor = GetMemberDetails
( $member,'');
27 if( $bor->{'category_type'} eq 'S' ) {
28 $flagsrequired->{'staffaccess'} = 1;
30 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
31 template_name
=> "members/member-flags.tt",
35 flagsrequired
=> $flagsrequired,
41 $member2{'borrowernumber'}=$member;
43 if ($input->param('newflags')) {
44 my $dbh=C4
::Context
->dbh();
46 my @perms = $input->multi_param('flag');
47 my %all_module_perms = ();
49 foreach my $perm (@perms) {
51 $all_module_perms{$perm} = 1;
53 my ($module, $sub_perm) = split /:/, $perm, 2;
54 push @
{ $sub_perms{$module} }, $sub_perm;
60 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
62 while (my ($bit, $flag) = $sth->fetchrow_array) {
63 if (exists $all_module_perms{$flag}) {
64 $module_flags += 2**$bit;
68 $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
69 $sth->execute($module_flags, $member);
71 # deal with subpermissions
72 $sth = $dbh->prepare("DELETE FROM user_permissions WHERE borrowernumber = ?");
73 $sth->execute($member);
74 $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code)
78 foreach my $module (keys %sub_perms) {
79 next if exists $all_module_perms{$module};
80 foreach my $sub_perm (@
{ $sub_perms{$module} }) {
81 $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 FROM userflags ORDER BY bit");
96 while (my ($bit, $flag) = $sth->fetchrow) {
98 if ($accessflags->{$flag}) {
102 my %row = ( bit
=> $bit,
107 my @sub_perm_loop = ();
108 my $expand_parent = 0;
110 if (exists $all_perms->{$flag}) {
112 foreach my $sub_perm (sort keys %{ $all_perms->{$flag} }) {
113 push @sub_perm_loop, {
114 id
=> "${flag}_$sub_perm",
115 perm
=> "$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",
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",
142 } unless exists $user_perms->{$flag} and exists $user_perms->{$flag}->{$sub_perm};
146 $row{expand
} = $expand_parent;
147 if ($#sub_perm_loop > -1) {
148 $row{sub_perm_loop
} = \
@sub_perm_loop;
153 if ( $bor->{'category_type'} eq 'C') {
154 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
155 my $cnt = scalar(@
$catcodes);
156 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
157 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 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'},
194 branchname
=> GetBranchName
($bor->{'branchcode'}),
196 is_child
=> ($bor->{'category_type'} eq 'C'),
197 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
198 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
201 output_html_with_http_headers
$input, $cookie, $template->output;