3 # Copyright 2013 BibLibre
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_with_http_headers );
25 use C4::Utils::DataTables qw( dt_get_params );
26 use C4::Utils::DataTables::Members qw( search );
30 exit unless $input->param('template_path');
32 my ($template, $user, $cookie) = get_template_and_user({
33 template_name => $input->param('template_path'),
37 flagsrequired => { borrowers => 1 }
40 my $searchmember = $input->param('searchmember');
41 my $firstletter = $input->param('firstletter');
42 my $categorycode = $input->param('categorycode');
43 my $branchcode = $input->param('branchcode');
44 my $searchtype = $input->param('searchtype');
45 my $searchfieldstype = $input->param('searchfieldstype');
47 # variable information for DataTables (id)
48 my $sEcho = $input->param('sEcho');
50 my %dt_params = dt_get_params($input);
51 foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) {
52 $dt_params{$_} =~ s/^dt_//;
55 # Perform the patrons search
56 my $results = C4::Utils::DataTables::Members::search(
58 searchmember => $searchmember,
59 firstletter => $firstletter,
60 categorycode => $categorycode,
61 branchcode => $branchcode,
62 searchtype => $searchtype,
63 searchfieldstype => $searchfieldstype,
64 dt_params => \%dt_params,
71 iTotalRecords => $results->{iTotalRecords},
72 iTotalDisplayRecords => $results->{iTotalDisplayRecords},
73 aaData => $results->{patrons}
76 output_with_http_headers $input, $cookie, $template->output, 'json';
82 search - a search script for finding patrons
86 This script provides a service for template for patron search using DataTables
88 =head2 Performing a search
90 Call this script from a DataTables table my $searchmember = $input->param('searchmember');
91 All following params are optional:
92 searchmember => the search terms
93 firstletter => search patrons with surname begins with this pattern (currently only used for 1 letter)
94 categorycode and branchcode => search patrons belong to a given categorycode or a branchcode
95 searchtype: can be 'contain' or 'start_with'
96 searchfieldstype: Can be 'standard', 'email', 'borrowernumber', 'phone' or 'address'
104 Copyright 2013 BibLibre
106 This file is part of Koha.
108 Koha is free software; you can redistribute it and/or modify it under the
109 terms of the GNU General Public License as published by the Free Software
110 Foundation; either version 2 of the License, or (at your option) any later
113 Koha is distributed in the hope that it will be useful, but WITHOUT ANY
114 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
115 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
117 You should have received a copy of the GNU General Public License along
118 with Koha; if not, write to the Free Software Foundation, Inc.,
119 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.