Merge remote branch 'kc/master' into new/bug_3013
[koha.git] / members / members-home.pl
1 #!/usr/bin/perl
2
3 # Parts Copyright Biblibre 2010
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA  02111-1307 USA
18
19 use strict;
20 use warnings;
21
22 use CGI;
23 use C4::Auth;
24 use C4::Output;
25 use C4::Context;
26 use C4::Members;
27 use C4::Branch;
28 use C4::Category;
29
30 my $query = new CGI;
31 my $branch = $query->param('branchcode');
32 my $template_name;
33
34 my ($template, $loggedinuser, $cookie)
35     = get_template_and_user({template_name => "members/member.tmpl",
36                  query => $query,
37                  type => "intranet",
38                  authnotrequired => 0,
39                  flagsrequired => {borrowers => 1},
40                  debug => 1,
41                  });
42
43 my $branches = GetBranches;
44 my @branchloop;
45 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
46   my $selected = 1 if $branches->{$_}->{branchcode} eq $branch;
47   my %row = ( value => $_,
48         selected => $selected,
49         branchname => $branches->{$_}->{branchname},
50       );
51   push @branchloop, \%row;
52 }
53
54 my @categories;
55 my $no_categories;
56 my $no_add = 0;
57 if(scalar(@branchloop) < 1){
58     $no_add = 1;
59     $template->param(no_branches => 1);
60
61 else {
62     $template->param(branchloop=>\@branchloop);
63 }
64
65 @categories=C4::Category->all;
66 if(scalar(@categories) < 1){ 
67     $no_categories = 1; 
68 }
69
70 if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
71     $no_add = 1;
72     $template->param(no_categories => 1);
73
74 else {
75     $template->param(categories=>\@categories);
76 }
77
78 $template->param( 
79         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
80         no_add => $no_add,
81             );
82 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
83 $template->param( letters => \@letters );
84
85 output_html_with_http_headers $query, $cookie, $template->output;