package Koha::Template::Plugin::Branches;
# Copyright ByWater Solutions 2012
+# Copyright BibLibre 2014
# This file is part of Koha.
#
return $b->{branchurl};
}
+sub all {
+ my ( $self, $params ) = @_;
+ my $selected = $params->{selected};
+ my $dbh = C4::Context->dbh;
+ my @params;
+ my $query = q|
+ SELECT branchcode, branchname
+ FROM branches
+ |;
+ if ( C4::Branch::onlymine
+ and C4::Context->userenv
+ and C4::Context->userenv->{branch} )
+ {
+ $query .= q| WHERE branchcode = ? |;
+ push @params, C4::Context->userenv->{branch};
+ }
+ $query .= q| ORDER BY branchname|;
+ my $branches = $dbh->selectall_arrayref( $query, { Slice => {} }, @params );
+
+ if ( $selected ) {
+ for my $branch ( @$branches ) {
+ if ( $branch->{branchcode} eq $selected ) {
+ $branch->{selected} = 1;
+ }
+ }
+ }
+ return $branches;
+}
+
1;
--- /dev/null
+package Koha::Template::Plugin::Categories;
+
+# Copyright 2013-2014 BibLibre
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Template::Plugin;
+use base qw( Template::Plugin );
+
+use C4::Category;
+
+sub all {
+ my ( $self, $params ) = @_;
+ my $selected = $params->{selected};
+
+ my @categories = C4::Category->all;
+ if ( $selected ) {
+ for my $category ( @categories ) {
+ if ( $category->{categorycode} eq $selected ) {
+ $category->{selected} = 1;
+ }
+ }
+ }
+ return @categories;
+}
+
+1;
+
+=head1 NAME
+
+Koha::Template::Plugin::Categories - TT Plugin for categories
+
+=head1 SYNOPSIS
+
+[% USE Categories %]
+
+[% Categories.all() %]
+
+=head1 ROUTINES
+
+=head2 all
+
+In a template, you can get the all categories with
+the following TT code: [% Categories.all() %]
+
+=head1 AUTHOR
+
+Jonathan Druart <jonathan.druart@biblibre.com>
+
+=cut
[% USE Koha %]
+[% USE Branches %]
+[% USE Categories %]
<div class="gradient">
<h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Patrons Resident Search Box -->
<div id="header_search">
</select>
</p>
+ <p>
+ <label for="branchcode">Library: </label>
+ [% SET branches = Branches.all( selected => branchcode ) %]
+ <select name="branchcode" id="branchcode">
+ [% IF branches.size != 1 %]
+ <option value="">Any</option>
+ [% END %]
+ [% FOREACH b IN branches %]
+ [% IF b.selected %]
+ <option value="[% b.branchcode %]" selected="selected">[% b.branchname %]</option>
+ [% ELSE %]
+ <option value="[% b.branchcode %]">[% b.branchname %]</option>
+ [% END %]
+ [% END %]
+ </select>
+ </p>
- [% IF ( branchloop ) %]
- <p> <label for="branchcode">Library: </label>
- <select name="branchcode" id="branchcode">
- [% IF branchloop.size != 1 %]
- <option value="">Any</option>
- [% END %]
- [% FOREACH branchloo IN branchloop %]
- [% IF ( branchloo.selected ) %]
- <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]
- <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
- [% END %]</select>
- [% END %]
- [% IF ( categories ) %]
- <p>
- <label for="categorycode">Category: </label><select name="categorycode" id="categorycode">
- <option value="">Any</option>[% FOREACH categorie IN categories %]
- [% IF ( categorie.selected ) %]
- <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>[% ELSE %]
- <option value="[% categorie.categorycode %]">[% categorie.description %]</option>[% END %]
- [% END %]</select>
- </p>
- [% END %]
+ <p>
+ <label for="categorycode">Category: </label>
+ [% SET categories = Categories.all( selected => categorycode ) %]
+ <select name="categorycode" id="categorycode">
+ <option value="">Any</option>
+ [% FOREACH categorie IN categories %]
+ [% IF ( categorie.selected ) %]
+ <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>
+ [% ELSE %]
+ <option value="[% categorie.categorycode %]">[% categorie.description %]</option>
+ [% END %]
+ [% END %]
+ </select>
+ </p>
</div>
</form>
</div>
[% USE Koha %]
[% USE ColumnsSettings %]
+[% USE Branches %]
+[% USE Categories %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha › Patrons [% IF ( searching ) %]› Search results[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
</li>
<li>
<label for="categorycode_filter">Category:</label>
+ [% SET categories = Categories.all( selected => categorycode ) %]
<select id="categorycode_filter">
<option value="">Any</option>
[% FOREACH cat IN categories %]
[% IF cat.selected %]
- <option selected="selected" value="[% cat.categorycode %]">[% cat.description | html_entity %]</option>
+ <option selected="selected" value="[% cat.categorycode %]">[% cat.description %]</option>
[% ELSE %]
- <option value="[% cat.categorycode %]">[% cat.description | html_entity %]</option>
+ <option value="[% cat.categorycode %]">[% cat.description %]</option>
[% END %]
[% END %]
</select>
</li>
<li>
<label for="branchcode_filter">Library:</label>
+ [% SET branches = Branches.all( selected => branchcode ) %]
<select id="branchcode_filter">
- [% IF branchloop.size != 1 %]
+ [% IF branches.size != 1 %]
<option value="">Any</option>
[% END %]
- [% FOREACH b IN branchloop %]
+ [% FOREACH b IN branches %]
[% IF b.selected %]
<option selected="selected" value="[% b.branchcode %]">[% b.branchname %]</option>
[% ELSE %]
$searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
}
-my $branches = C4::Branch::GetBranches;
-my @branches_loop;
-if ( C4::Branch::onlymine ) {
- my $userenv = C4::Context->userenv;
- my $branch = C4::Branch::GetBranchDetail( $userenv->{'branch'} );
- push @branches_loop, {
- value => $branch->{branchcode},
- branchcode => $branch->{branchcode},
- branchname => $branch->{branchname},
- selected => 1
- }
-} else {
- foreach ( sort { lc($branches->{$a}->{branchname}) cmp lc($branches->{$b}->{branchname}) } keys %$branches ) {
- my $selected = 0;
- $selected = 1 if($patron->{branchcode} and $patron->{branchcode} eq $_);
- push @branches_loop, {
- value => $_,
- branchcode => $_,
- branchname => $branches->{$_}->{branchname},
- selected => $selected
- };
- }
-}
-
-my @categories = C4::Category->all;
-if ( $patron->{categorycode} ) {
- foreach my $category ( grep { $_->{categorycode} eq $patron->{categorycode} } @categories ) {
- $category->{selected} = 1;
- }
-}
-
$template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
my $view = $input->request_method() eq "GET" ? "show_form" : "show_results";
$template->param(
patron_lists => [ GetPatronLists() ],
searchmember => $searchmember,
- branchloop => \@branches_loop,
- categories => \@categories,
branchcode => $patron->{branchcode},
categorycode => $patron->{categorycode},
searchtype => $input->param('searchtype') || 'start_with',