Adding IndependantBranches Filter + adding some ordering on member list display.
Signed-off-by: Chris Cormack <crc@liblime.com>
This commit is contained in:
parent
ba569c3cfa
commit
ebb9890ccb
2 changed files with 33 additions and 13 deletions
|
@ -122,7 +122,7 @@ push @EXPORT, qw(
|
||||||
|
|
||||||
=item SearchMember
|
=item SearchMember
|
||||||
|
|
||||||
($count, $borrowers) = &SearchMember($searchstring, $type,$category_type);
|
($count, $borrowers) = &SearchMember($searchstring, $type,$category_type,$filter,$showallbranches);
|
||||||
|
|
||||||
Looks up patrons (borrowers) by name.
|
Looks up patrons (borrowers) by name.
|
||||||
|
|
||||||
|
@ -137,6 +137,10 @@ C<$searchstring> is a space-separated list of search terms. Each term
|
||||||
must match the beginning a borrower's surname, first name, or other
|
must match the beginning a borrower's surname, first name, or other
|
||||||
name.
|
name.
|
||||||
|
|
||||||
|
C<$filter> is assumed to be a list of elements to filter results on
|
||||||
|
|
||||||
|
C<$showallbranches> is used in IndependantBranches Context to display all branches results.
|
||||||
|
|
||||||
C<&SearchMember> returns a two-element list. C<$borrowers> is a
|
C<&SearchMember> returns a two-element list. C<$borrowers> is a
|
||||||
reference-to-array; each element is a reference-to-hash, whose keys
|
reference-to-array; each element is a reference-to-hash, whose keys
|
||||||
are the fields of the C<borrowers> table in the Koha database.
|
are the fields of the C<borrowers> table in the Koha database.
|
||||||
|
@ -148,7 +152,7 @@ C<$count> is the number of elements in C<$borrowers>.
|
||||||
#used by member enquiries from the intranet
|
#used by member enquiries from the intranet
|
||||||
#called by member.pl
|
#called by member.pl
|
||||||
sub SearchMember {
|
sub SearchMember {
|
||||||
my ($searchstring, $orderby, $type,$category_type ) = @_;
|
my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
my $query = "";
|
my $query = "";
|
||||||
my $count;
|
my $count;
|
||||||
|
@ -158,10 +162,18 @@ sub SearchMember {
|
||||||
if ( $type eq "simple" ) # simple search for one letter only
|
if ( $type eq "simple" ) # simple search for one letter only
|
||||||
{
|
{
|
||||||
$query =
|
$query =
|
||||||
"SELECT * FROM borrowers
|
"SELECT *
|
||||||
|
FROM borrowers
|
||||||
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
|
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
|
||||||
($category_type?" AND category_type = ".$dbh->quote($category_type):"").
|
($category_type?" AND category_type = ".$dbh->quote($category_type):"");
|
||||||
" WHERE surname LIKE ? OR cardnumber like ? ORDER BY $orderby";
|
$query .=
|
||||||
|
" WHERE (surname LIKE ? OR cardnumber like ?) ";
|
||||||
|
if (C4::Context->preference("IndependantBranches") && !$showallbranches){
|
||||||
|
if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
|
||||||
|
$query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query.=" ORDER BY $orderby";
|
||||||
@bind = ("$searchstring%","$searchstring");
|
@bind = ("$searchstring%","$searchstring");
|
||||||
}
|
}
|
||||||
else # advanced search looking in surname, firstname and othernames
|
else # advanced search looking in surname, firstname and othernames
|
||||||
|
@ -170,7 +182,13 @@ sub SearchMember {
|
||||||
$count = @data;
|
$count = @data;
|
||||||
$query = "SELECT * FROM borrowers
|
$query = "SELECT * FROM borrowers
|
||||||
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
|
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
|
||||||
WHERE ((surname LIKE ? OR surname LIKE ?
|
WHERE ";
|
||||||
|
if (C4::Context->preference("IndependantBranches") && !$showallbranches){
|
||||||
|
if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
|
||||||
|
$query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query.="((surname LIKE ? OR surname LIKE ?
|
||||||
OR firstname LIKE ? OR firstname LIKE ?
|
OR firstname LIKE ? OR firstname LIKE ?
|
||||||
OR othernames LIKE ? OR othernames LIKE ?)
|
OR othernames LIKE ? OR othernames LIKE ?)
|
||||||
".
|
".
|
||||||
|
@ -198,7 +216,7 @@ sub SearchMember {
|
||||||
|
|
||||||
my $sth = $dbh->prepare($query);
|
my $sth = $dbh->prepare($query);
|
||||||
|
|
||||||
# warn "Q $orderby : $query";
|
# warn "Q $orderby : $query";
|
||||||
$sth->execute(@bind);
|
$sth->execute(@bind);
|
||||||
my @results;
|
my @results;
|
||||||
my $data = $sth->fetchall_arrayref({});
|
my $data = $sth->fetchall_arrayref({});
|
||||||
|
|
|
@ -58,9 +58,10 @@
|
||||||
<div class="searchresults">
|
<div class="searchresults">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Card</th>
|
<th><a href="member.pl?member=<!--TMPL_VAR Name="member" -->&orderby=cardnumber">Card</a></th>
|
||||||
<th>Name</th>
|
<th><a href="member.pl?member=<!--TMPL_VAR Name="member" -->&orderby=surname">Name</a></th>
|
||||||
<th>Cat</th>
|
<th><a href="member.pl?member=<!--TMPL_VAR Name="member" -->&orderby=borrowers.categorycode">Cat</a></th>
|
||||||
|
<th><a href="member.pl?member=<!--TMPL_VAR Name="member" -->&orderby=branchcode">Branch</a></th>
|
||||||
<th>OD/Issues</th>
|
<th>OD/Issues</th>
|
||||||
<th>Fines</th>
|
<th>Fines</th>
|
||||||
<th>Notes</th>
|
<th>Notes</th>
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
<!-- TMPL_VAR NAME="streetaddress" --> <!-- TMPL_VAR NAME="city" -->
|
<!-- TMPL_VAR NAME="streetaddress" --> <!-- TMPL_VAR NAME="city" -->
|
||||||
</td>
|
</td>
|
||||||
<td><!-- TMPL_VAR NAME="category_description" --> (<!-- TMPL_VAR name="category_type" -->)</td>
|
<td><!-- TMPL_VAR NAME="category_description" --> (<!-- TMPL_VAR name="category_type" -->)</td>
|
||||||
|
<td><!-- TMPL_VAR NAME="branchcode" --></td>
|
||||||
<td><!-- TMPL_VAR NAME="odissue" --></td>
|
<td><!-- TMPL_VAR NAME="odissue" --></td>
|
||||||
<td><!-- TMPL_VAR NAME="fines" --></td>
|
<td><!-- TMPL_VAR NAME="fines" --></td>
|
||||||
<td><!-- TMPL_VAR NAME="borrowernotes" --></td>
|
<td><!-- TMPL_VAR NAME="borrowernotes" --></td>
|
||||||
|
|
Loading…
Reference in a new issue