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