Bug 15098: Itemtype description missing from facets for itypes in a search group
[koha.git] / members / member-flags.pl
blob1206f129b673faa25553c60ac4113e0d486e5a97
1 #!/usr/bin/perl
3 # script to edit a member's flags
4 # Written by Steve Tonnesen
5 # July 26, 2002 (my birthday!)
7 use strict;
8 use warnings;
10 use CGI qw ( -utf8 );
11 use C4::Output;
12 use C4::Auth qw(:DEFAULT :EditPermissions);
13 use C4::Context;
14 use C4::Members;
15 use C4::Branch;
16 use C4::Members::Attributes qw(GetBorrowerAttributes);
17 #use C4::Acquisitions;
19 use C4::Output;
21 my $input = new CGI;
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",
31 query => $input,
32 type => "intranet",
33 authnotrequired => 0,
34 flagsrequired => $flagsrequired,
35 debug => 1,
36 });
39 my %member2;
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 = ();
47 my %sub_perms = ();
48 foreach my $perm (@perms) {
49 if ($perm !~ /:/) {
50 $all_module_perms{$perm} = 1;
51 } else {
52 my ($module, $sub_perm) = split /:/, $perm, 2;
53 push @{ $sub_perms{$module} }, $sub_perm;
57 # construct flags
58 my $module_flags = 0;
59 my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
60 $sth->execute();
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)
74 SELECT ?, bit, ?
75 FROM userflags
76 WHERE flag = ?");
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");
85 } else {
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");
93 $sth->execute;
94 my @loop;
95 while (my ($bit, $flag) = $sth->fetchrow) {
96 my $checked='';
97 if ($accessflags->{$flag}) {
98 $checked= 1;
101 my %row = ( bit => $bit,
102 flag => $flag,
103 checked => $checked,
106 my @sub_perm_loop = ();
107 my $expand_parent = 0;
108 if ($checked) {
109 if (exists $all_perms->{$flag}) {
110 $expand_parent = 1;
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",
115 code => $sub_perm,
116 checked => 1
120 } else {
121 if (exists $user_perms->{$flag}) {
122 $expand_parent = 1;
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",
128 code => $sub_perm,
129 checked => 1
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",
139 code => $sub_perm,
140 checked => 0
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;
149 push @loop, \%row;
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'});
165 $template->param(
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'};
175 $template->param(
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'},
184 address => $address,
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'}),
197 loop => \@loop,
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;