Fixing and refining toolbars, including fixes for Bug 1509.
[wip/koha-chris_n.git] / members / member-flags.pl
1 #!/usr/bin/perl
2
3 # script to edit a member's flags
4 # Written by Steve Tonnesen
5 # July 26, 2002 (my birthday!)
6
7 use strict;
8
9 use CGI;
10 use C4::Output;
11 use C4::Auth;
12 use C4::Context;
13 use C4::Members;
14 #use C4::Acquisitions;
15
16 use C4::Output;
17
18 my $input = new CGI;
19
20 my $flagsrequired;
21 $flagsrequired->{borrowers}=1;
22 $flagsrequired->{permissions}=1;
23
24 my ($template, $loggedinuser, $cookie)
25         = get_template_and_user({template_name => "members/member-flags.tmpl",
26                                 query => $input,
27                                 type => "intranet",
28                                 authnotrequired => 0,
29                                 flagsrequired => {permissions => 1},
30                                 debug => 1,
31                                 });
32
33
34
35
36 my $member=$input->param('member');
37 my %member2;
38 $member2{'borrowernumber'}=$member;
39
40 if ($input->param('newflags')) {
41     my $dbh=C4::Context->dbh();
42     my $flags=0;
43     foreach ($input->param) {
44         if (/flag-(\d+)/) {
45             my $flag=$1;
46             $flags=$flags+2**$flag;
47         }
48     }
49     my $sth=$dbh->prepare("update borrowers set flags=? where borrowernumber=?");
50     $sth->execute($flags, $member);
51     print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
52 } else {
53 #     my ($bor,$flags,$accessflags)=GetMemberDetails($member,'');
54     my $bor = GetMemberDetails( $member,'');
55     my $flags = $bor->{'flags'};
56     my $accessflags = $bor->{'authflags'};
57     my $dbh=C4::Context->dbh();
58     my $sth=$dbh->prepare("select bit,flag,flagdesc from userflags order by bit");
59     $sth->execute;
60     my @loop;
61     while (my ($bit, $flag, $flagdesc) = $sth->fetchrow) {
62         my $checked='';
63         if ($accessflags->{$flag}) {
64             $checked= 1;
65         }
66         my %row = ( bit => $bit,
67                  flag => $flag,
68                  checked => $checked,
69                  flagdesc => $flagdesc );
70         push @loop, \%row;
71     }
72
73     $template->param(borrowernumber => $member,
74                         surname => $bor->{'surname'},
75                         firstname => $bor->{'firstname'},
76                         loop => \@loop,
77                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
78                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
79                 IntranetNav => C4::Context->preference("IntranetNav"),
80                         );
81
82     output_html_with_http_headers $input, $cookie, $template->output;
83
84 }