Bug 9811: Patron search improvement
[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
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 use Koha::Borrower::Modifications;
30
31 my $query = new CGI;
32 my $branch = $query->param('branchcode');
33
34 $branch = q{} unless defined $branch;
35
36 my ($template, $loggedinuser, $cookie)
37     = get_template_and_user({template_name => "members/member.tmpl",
38                  query => $query,
39                  type => "intranet",
40                  authnotrequired => 0,
41                  flagsrequired => {borrowers => 1},
42                  debug => 1,
43                  });
44
45 my $branches = GetBranches;
46 my @branchloop;
47 if ( C4::Branch::onlymine ) {
48     my $userenv = C4::Context->userenv;
49     my $branch = C4::Branch::GetBranchDetail( $userenv->{'branch'} );
50     push @branchloop, {
51         value => $branch->{branchcode},
52         branchcode => $branch->{branchcode},
53         branchname => $branch->{branchname},
54         selected => 1
55     }
56 } else {
57     foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) {
58         push @branchloop, {
59             value      => $_,
60             selected   => ($branches->{$_}->{branchcode} eq $branch),
61             branchname => $branches->{$_}->{branchname},
62         };
63     }
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){ 
79     $no_categories = 1; 
80 }
81
82 if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
83     $no_add = 1;
84     $template->param(no_categories => 1);
85
86 else {
87     $template->param(categories=>\@categories);
88 }
89
90
91 my $pending_borrower_modifications =
92   Koha::Borrower::Modifications->GetPendingModificationsCount( $branch );
93
94 $template->param( 
95         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
96         no_add => $no_add,
97         pending_borrower_modifications => $pending_borrower_modifications,
98             );
99
100 $template->param(
101     alphabet => C4::Context->preference('alphabet') || join (' ', 'A' .. 'Z'),
102     PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
103 );
104
105 output_html_with_http_headers $query, $cookie, $template->output;