View | Details | Raw Unified | Return to bug 9811
Collapse All | Expand All

(-)a/C4/Members.pm (-1 / +1 lines)
Lines 274-280 sub Search { Link Here
274
                else {
274
                else {
275
                    $filter = { '' => $filter, branchcode => $branch };
275
                    $filter = { '' => $filter, branchcode => $branch };
276
                }
276
                }
277
            }      
277
            }
278
        }
278
        }
279
    }
279
    }
280
280
(-)a/C4/Utils/DataTables/Members.pm (+211 lines)
Line 0 Link Here
1
package C4::Utils::DataTables::Members;
2
3
use C4::Branch qw/onlymine/;
4
use C4::Context;
5
use C4::Members qw/GetMemberIssuesAndFines/;
6
use C4::Utils::DataTables;
7
use Modern::Perl;
8
9
sub search {
10
    my ( $params ) = @_;
11
    my $searchmember = $params->{searchmember};
12
    my $firstletter = $params->{firstletter};
13
    my $categorycode = $params->{categorycode};
14
    my $branchcode = $params->{branchcode};
15
    my $searchtype = $params->{searchtype};
16
    my $searchfieldstype = $params->{searchfieldstype};
17
    my $dt_params = $params->{dt_params};
18
19
    my ($iTotalRecords, $iTotalDisplayRecords);
20
21
    # If branches are independant and user is not superlibrarian
22
    # The search has to be only on the user branch
23
    if ( C4::Branch::onlymine ) {
24
        my $userenv = C4::Context->userenv;
25
        $branchcode = $userenv->{'branch'};
26
27
    }
28
29
    my $dbh = C4::Context->dbh;
30
    my $select = "SELECT
31
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname, borrowers.address,
32
        borrowers.address2, borrowers.city, borrowers.zipcode, borrowers.country,
33
        CAST(borrowers.cardnumber AS UNSIGNED) AS cardnumber, borrowers.dateexpiry,
34
        borrowers.borrowernotes, borrowers.branchcode,
35
        categories.description AS category_description, categories.category_type,
36
        branches.branchname";
37
    my $from = "FROM borrowers
38
        LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
39
        LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
40
    my @where_args;
41
    my @where_strs;
42
    if(defined $firstletter and $firstletter ne '') {
43
        push @where_strs, "borrowers.surname LIKE ?";
44
        push @where_args, "$firstletter%";
45
    }
46
    if(defined $categorycode and $categorycode ne '') {
47
        push @where_strs, "borrowers.categorycode = ?";
48
        push @where_args, $categorycode;
49
    }
50
    if(defined $branchcode and $branchcode ne '') {
51
        push @where_strs, "borrowers.branchcode = ?";
52
        push @where_args, $branchcode;
53
    }
54
55
    # split on coma
56
    $searchmember =~ s/,/ /g if $searchmember;
57
    my @where_strs_or;
58
    my $searchfields = {
59
        standard => 'surname,firstname,othernames,cardnumber',
60
        email => 'email,emailpro,B_email',
61
        borrowernumber => 'borrowernumber',
62
        phone => 'phone,phonepro,B_phone,altcontactphone,mobile',
63
        address => 'streettype,address,address2,city,state,zipcode,country',
64
        dateofbirth => 'dateofbirth',
65
    };
66
    for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) {
67
        foreach my $term ( split / /, $searchmember) {
68
            next unless $term;
69
            $searchmember =~ s/\*/%/g; # * is replaced with % for sql
70
            $term .= '%' # end with anything
71
                if $term !~ /%$/;
72
            $term = "%$term" # begin with anythin unless start_with
73
                if $term !~ /^%/
74
                    and $searchtype eq "contain";
75
            push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?";
76
            push @where_args, $term;
77
        }
78
    }
79
    push @where_strs, '('. join (' OR ', @where_strs_or) . ')'
80
        if @where_strs_or;
81
82
    my $where;
83
    $where = " WHERE " . join (" AND ", @where_strs) if @where_strs;
84
    my $orderby = dt_build_orderby($dt_params);
85
86
    my $limit;
87
    # If iDisplayLength == -1, we want to display all patrons
88
    if ( $dt_params->{iDisplayLength} > -1 ) {
89
        # In order to avoid sql injection
90
        $dt_params->{iDisplayStart} =~ s/\D//g;
91
        $dt_params->{iDisplayLength} =~ s/\D//g;
92
        $dt_params->{iDisplayStart} //= 0;
93
        $dt_params->{iDisplayLength} //= 20;
94
        $limit = "LIMIT $dt_params->{iDisplayStart},$dt_params->{iDisplayLength}";
95
    }
96
97
    my $query = join(
98
        " ",
99
        ($select ? $select : ""),
100
        ($from ? $from : ""),
101
        ($where ? $where : ""),
102
        ($orderby ? $orderby : ""),
103
        ($limit ? $limit : "")
104
    );
105
    my $sth = $dbh->prepare($query);
106
    $sth->execute(@where_args);
107
    my $patrons = $sth->fetchall_arrayref({});
108
109
    # Get the iTotalDisplayRecords DataTable variable
110
    $query = "SELECT COUNT(borrowers.borrowernumber) " . $from . ($where ? $where : "");
111
    $sth = $dbh->prepare($query);
112
    $sth->execute(@where_args);
113
    ($iTotalDisplayRecords) = $sth->fetchrow_array;
114
115
    # Get the iTotalRecords DataTable variable
116
    $query = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
117
    $sth = $dbh->prepare($query);
118
    $sth->execute;
119
    ($iTotalRecords) = $sth->fetchrow_array;
120
121
    # Get some information on patrons
122
    foreach my $patron (@$patrons) {
123
        ($patron->{overdues}, $patron->{issues}, $patron->{fines}) =
124
            GetMemberIssuesAndFines($patron->{borrowernumber});
125
        if($patron->{dateexpiry} and $patron->{dateexpiry} ne '0000-00-00') {
126
            $patron->{dateexpiry} = C4::Dates->new($patron->{dateexpiry}, "iso")->output();
127
        } else {
128
            $patron->{dateexpiry} = '';
129
        }
130
        $patron->{fines} = sprintf("%.2f", $patron->{fines} || 0);
131
    }
132
133
    return {
134
        iTotalRecords => $iTotalRecords,
135
        iTotalDisplayRecords => $iTotalDisplayRecords,
136
        patrons => $patrons
137
    }
138
}
139
140
1;
141
__END__
142
143
=head1 NAME
144
145
C4::Utils::DataTables::Members - module for using DataTables with patrons
146
147
=head1 SYNOPSIS
148
149
This module provides (one for the moment) routines used by the patrons search
150
151
=head2 FUNCTIONS
152
153
=head3 search
154
155
    my $dt_infos = C4::Utils::DataTables::Members->search($params);
156
157
$params is a hashref with some keys:
158
159
=over 4
160
161
=item searchmember
162
163
  String to search in the borrowers sql table
164
165
=item firstletter
166
167
  Introduced to contain 1 letter but can contain more.
168
  The search will done on the borrowers.surname field
169
170
=item categorycode
171
172
  Search patrons with this categorycode
173
174
=item branchcode
175
176
  Search patrons with this branchcode
177
178
=item searchtype
179
180
  Can be 'contain' or 'start_with'. Used for the searchmember parameter.
181
182
=item searchfieldstype
183
184
  Can be 'standard', 'email', 'borrowernumber', 'phone', 'address' or 'dateofbirth'
185
186
=item dt_params
187
188
  Is the reference of C4::Utils::DataTables::dt_get_params($input);
189
190
=cut
191
192
=back
193
194
=head1 LICENSE
195
196
Copyright 2013 BibLibre
197
198
This file is part of Koha.
199
200
Koha is free software; you can redistribute it and/or modify it under the
201
terms of the GNU General Public License as published by the Free Software
202
Foundation; either version 2 of the License, or (at your option) any later
203
version.
204
205
Koha is distributed in the hope that it will be useful, but WITHOUT ANY
206
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
207
A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
208
209
You should have received a copy of the GNU General Public License along
210
with Koha; if not, write to the Free Software Foundation, Inc.,
211
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-61 / +82 lines)
Lines 5-77 Link Here
5
	<div id="patron_search" class="residentsearch">
5
	<div id="patron_search" class="residentsearch">
6
	<p class="tip">Enter patron card number or partial name:</p>
6
	<p class="tip">Enter patron card number or partial name:</p>
7
	<form action="/cgi-bin/koha/members/member.pl" method="post">
7
	<form action="/cgi-bin/koha/members/member.pl" method="post">
8
    <input id="searchmember" size="25" class="focus" name="member" type="text" value="[% member %]"/>
8
    <input id="searchmember" size="25" class="focus" name="searchmember" type="text" value="[% searchmember %]"/>
9
	<span class="filteraction" id="filteraction_off"> <a href="#" onclick="$('#filters').toggle();$('.filteraction').toggle();">[-]</a></span>
9
	<span class="filteraction" id="filteraction_off"> <a href="#" onclick="$('#filters').toggle();$('.filteraction').toggle();">[-]</a></span>
10
	<span class="filteraction" id="filteraction_on"> <a href="#" onclick="$('#filters').toggle();$('.filteraction').toggle();">[+]</a></span>
10
	<span class="filteraction" id="filteraction_on"> <a href="#" onclick="$('#filters').toggle();$('.filteraction').toggle();">[+]</a></span>
11
11
12
    <input value="Search" class="submit" type="submit" />
12
      <label for="searchfieldstype">Search fields:</label>
13
      <select name="searchfieldstype" id="searchfieldstype">
14
        [% IF searchfieldstype == "standard" %]
15
          <option selected="selected" value='standard'>Standard</option>
16
        [% ELSE %]
17
          <option value='standard'>Standard</option>
18
        [% END %]
19
        [% IF searchfieldstype == "email" %]
20
          <option selected="selected" value='email'>Email</option>
21
        [% ELSE %]
22
          <option value='email'>Email</option>
23
        [% END %]
24
        [% IF searchfieldstype == "borrowernumber" %]
25
          <option selected="selected" value='borrowernumber'>Borrower number</option>
26
        [% ELSE %]
27
          <option value='borrowernumber'>Borrower number</option>
28
        [% END %]
29
        [% IF searchfieldstype == "phone" %]
30
          <option selected="selected" value='phone'>Phone number</option>
31
        [% ELSE %]
32
          <option value='phone'>Phone number</option>
33
        [% END %]
34
        [% IF searchfieldstype == "address" %]
35
          <option selected="selected" value='address'>Street Address</option>
36
        [% ELSE %]
37
          <option value='address'>Street Address</option>
38
        [% END %]
39
        [% IF searchfieldstype == "dateofbirth" %]
40
          <option selected="selected" value='dateofbirth'>Date of birth</option>
41
        [% ELSE %]
42
          <option value='dateofbirth'>Date of birth</option>
43
        [% END %]
44
      </select>
45
46
      <script type="text/javascript">
47
          [% SET dateformat = Koha.Preference('dateformat') %]
48
          $("#searchfieldstype").change(function() {
49
              if ( $(this).val() == 'dateofbirth' ) {
50
                  [% IF dateformat == 'us' %]
51
                      [% SET format = 'MM/DD/YYYY' %]
52
                  [% ELSIF dateformat == 'iso' %]
53
                      [% SET format = 'YYYY-MM-DD' %]
54
                  [% ELSIF dateformat == 'metric' %]
55
                      [% SET format = 'DD/MM/YYYY' %]
56
                  [% END %]
13
57
14
  <div id="filters">
58
                  $('#searchmember').qtip({
15
      <p><label for="searchfields">Search fields:</label>
59
                      content: 'Dates of birth should be entered in the format "[% format %]"',
16
            <select name="searchfields" id="searchfields">
60
                      style: {
17
                <option selected="selected" value=''>Standard</option>
61
                          tip: 'topLeft'
18
                <option value='email,emailpro,B_email,'>Email</option>
62
                      }
19
                <option value='borrowernumber'>Borrower number</option>
63
                  })
20
                <option value='phone,phonepro,B_phone,altcontactphone,mobile'>Phone number</option>
64
              } else {
21
                <option value='streettype,address,address2,city,state,zipcode,country'>Street Address</option>
65
                  $('#searchmember').qtip('destroy');
22
                <option value='dateofbirth'>Date of birth</option>
66
              }
23
            </select>
67
          });
24
            <script type="text/javascript">
68
      </script>
25
                [% SET dateformat = Koha.Preference('dateformat') %]
26
                $("#searchfields").change(function() {
27
                    if ( $(this).val() == 'dateofbirth' ) {
28
                        [% IF dateformat == 'us' %]
29
                            [% SET format = 'MM/DD/YYYY' %]
30
                        [% ELSIF dateformat == 'iso' %]
31
                            [% SET format = 'YYYY-MM-DD' %]
32
                        [% ELSIF dateformat == 'metric' %]
33
                            [% SET format = 'DD/MM/YYYY' %]
34
                        [% END %]
35
69
36
                        $('#searchmember').qtip({
70
      <label for="searchtype">Search type:</label>
37
                            content: 'Dates of birth should be entered in the format "[% format %]"',
71
      <select name="searchtype" id="searchtype">
38
                            style: {
72
          <option selected="selected" value='start_with'>Starts with</option>
39
                                tip: 'topLeft'
73
          <option value='contain'>Contains</option>
40
                            }
74
      </select>
41
                        })
42
                    } else {
43
                        $('#searchmember').qtip('destroy');
44
                    }
45
                });
46
            </script>
47
        </p>
48
        <p><label for="searchtype">Search type:</label>
49
                <select name="searchtype" id="searchtype">
50
                    <option selected="selected" value=''>Starts with</option>
51
                    <option value='contain'>Contains</option>
52
                </select></p>
53
75
54
      <p><label for="searchorderby">Order by:</label>
76
    <input value="Search" class="submit" type="submit" />
55
            <select name="orderby" id="searchorderby">
77
    [% IF ( branchloop ) %]
56
            <option value="">Surname, Firstname</option>
78
    <p id="filters"> <label for="branchcode">Library: </label>
57
            <option value="cardnumber,0">Cardnumber</option>
79
    <select name="branchcode" id="branchcode">
58
            </select></p>
80
        [% IF branchloop.size != 1 %]
59
        [% IF ( branchloop ) %] <p><label for="branchcode">Library: </label><select name="branchcode" id="branchcode">
81
          <option value="">Any</option>
60
                <option value="">Any</option>[% FOREACH branchloo IN branchloop %]
82
        [% END %]
61
                [% IF ( branchloo.selected ) %]
83
        [% FOREACH branchloo IN branchloop %]
62
                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]
84
        [% IF ( branchloo.selected ) %]
63
                <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
85
        <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]
64
              [% END %]</select></p>
86
        <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
65
      [% END %]
87
      [% END %]</select>
66
      [% IF ( categories ) %]
88
                 <label for="categorycode">Category: </label><select name="categorycode" id="categorycode">
67
        <p><label for="categorycode">Category: </label><select name="categorycode" id="categorycode">
89
        <option value="">Any</option>[% FOREACH categorie IN categories %]
68
                <option value="">Any</option>[% FOREACH categorie IN categories %]
90
        [% IF ( categorie.selected ) %]
69
                [% IF ( categorie.selected ) %]
91
        <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>[% ELSE %]
70
                <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>[% ELSE %]
92
        <option value="[% categorie.categorycode %]">[% categorie.description %]</option>[% END %]
71
                <option value="[% categorie.categorycode %]">[% categorie.description %]</option>[% END %]
93
      [% END %]</select>
72
                [% END %]</select></p>
94
    </p>
73
      [% END %]
95
    [% END %]
74
  </div>
75
</form>
96
</form>
76
	</div>
97
	</div>
77
98
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-title.inc (-22 / +22 lines)
Lines 1-23 Link Here
1
[% IF ( borrower.borrowernumber ) %]
1
[%- IF ( borrower.borrowernumber ) %]
2
    [% IF borrower.category_type == 'I' %]
2
    [%- IF borrower.category_type == 'I' %]
3
        [% borrower.surname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %]
3
        [%- borrower.surname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %]
4
    [% ELSE %]
4
    [%- ELSE %]
5
        [% IF invert_name %]
5
        [%- IF invert_name %]
6
            [% borrower.surname %], [% borrower.firstname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %]
6
            [%- borrower.surname %], [% borrower.firstname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %]
7
        [% ELSE %]
7
        [%- ELSE %]
8
            [% borrower.firstname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %] [% borrower.surname %]
8
            [%- borrower.firstname %] [% IF borrower.othernames %] ([% borrower.othernames %]) [% END %] [% borrower.surname %]
9
        [% END %]
9
        [%- END -%]
10
    [% END %]
10
    [%- END -%]
11
    ([% borrower.cardnumber %])
11
    ([% borrower.cardnumber %])
12
[% ELSIF ( borrowernumber ) %]
12
[%- ELSIF ( borrowernumber ) %]
13
    [% IF category_type == 'I' %]
13
    [%- IF category_type == 'I' %]
14
        [% surname %] [% IF othernames %] ([% othernames %]) [% END %]
14
        [%- surname %] [% IF othernames %] ([% othernames %]) [% END %]
15
    [% ELSE %]
15
    [%- ELSE %]
16
        [% IF invert_name %]
16
        [%- IF invert_name %]
17
            [% surname %], [% firstname %] [% IF othernames %] ([% othernames %]) [% END %]
17
            [%- surname %], [% firstname %] [% IF othernames %] ([% othernames %]) [% END %]
18
        [% ELSE %]
18
        [%- ELSE %]
19
            [% firstname %] [% IF othernames %] ([% othernames %]) [% END %] [% surname %]
19
            [%- firstname %] [% IF othernames %] ([% othernames %]) [% END %] [% surname %]
20
        [% END %]
20
        [%- END %]
21
    [% END %]
21
    [%- END -%]
22
    ([% cardnumber %])
22
    ([% cardnumber -%])
23
[% END %]
23
[%- END -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js (-1 / +1 lines)
Lines 23-29 var dataTablesDefaults = { Link Here
23
        "sSearch"           : window.MSG_DT_SEARCH || "Search:",
23
        "sSearch"           : window.MSG_DT_SEARCH || "Search:",
24
        "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
24
        "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
25
    },
25
    },
26
    "sDom": '<"top pager"ilpf>t<"bottom pager"ip>'
26
    "sDom": '<"top pager"ilpf>tr<"bottom pager"ip>'
27
};
27
};
28
28
29
29
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (-176 / +415 lines)
Lines 1-7 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Patrons [% IF ( searching ) %]&rsaquo; Search results[% END %]</title>
2
<title>Koha &rsaquo; Patrons [% IF ( searching ) %]&rsaquo; Search results[% END %]</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
4
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
5
[% INCLUDE 'datatables.inc' %]
5
<script type="text/javascript">
6
<script type="text/javascript">
6
//<![CDATA[
7
//<![CDATA[
7
$(document).ready(function() {
8
$(document).ready(function() {
Lines 21-27 $(document).ready(function() { Link Here
21
            $('#new_patron_list').hide();
22
            $('#new_patron_list').hide();
22
            $('#add_to_patron_list_submit').attr('disabled', 'disabled');
23
            $('#add_to_patron_list_submit').attr('disabled', 'disabled');
23
        }
24
        }
24
25
    });
25
    });
26
26
27
    $('#new_patron_list').on('input', function() {
27
    $('#new_patron_list').on('input', function() {
Lines 31-73 $(document).ready(function() { Link Here
31
            $('#add_to_patron_list_submit').attr('disabled', 'disabled');
31
            $('#add_to_patron_list_submit').attr('disabled', 'disabled');
32
        }
32
        }
33
    });
33
    });
34
35
    $("#patron_list_dialog").hide();
36
    $("#add_to_patron_list_submit").on('click', function(e){
37
        if ( $('#add_to_patron_list').val() == 'new' ) {
38
            if ( $('#new_patron_list').val() ) {
39
                $("#add_to_patron_list option").each(function() {
40
                    if ( $(this).text() == $('#new_patron_list').val() ) {
41
                        alert( _("You already have a list with that name!") );
42
                        return false;
43
                    }
44
                });
45
            } else {
46
                alert( _("You must give your new patron list a name!") );
47
                return false;
48
            }
49
        }
50
51
        if ( $("#memberresultst input:checkbox:checked").length == 0 ) {
52
            alert( _("You have not selected any patrons to add to a list!") );
53
            return false;
54
        }
55
56
        var borrowernumbers = [];
57
        $("#memberresultst").find("input:checkbox:checked").each(function(){
58
            borrowernumbers.push($(this).val());
59
        });
60
        var data = {
61
            add_to_patron_list: encodeURIComponent($("#add_to_patron_list").val()),
62
            new_patron_list: encodeURIComponent($("#new_patron_list").val()),
63
            borrowernumbers: borrowernumbers
64
        };
65
        $.ajax({
66
            data: data,
67
            type: 'POST',
68
            url: '/cgi-bin/koha/svc/members/add_to_list',
69
            success: function(data) {
70
                $("#patron_list_dialog").show();
71
                $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
72
                $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
73
                $("#patron_list_dialog > a").html(data.patron_list.name);
74
            },
75
            error: function() {
76
                alert("an error occurred");
77
            }
78
        });
79
        return true;
80
    });
34
});
81
});
35
82
36
function CheckForm() {
83
var dtMemberResults;
37
    if ( $('#add_to_patron_list').val() == 'new' ) {
84
var search = 1;
38
        if ( $('#new_patron_list').val() ) {
85
$(document).ready(function() {
39
            var exists = false;
86
    [% IF searchmember %]
40
            $("#add_to_patron_list option").each(function() {
87
        $("#searchmember_filter").val("[% searchmember %]");
41
                if ( $(this).text() == $('#new_patron_list').val() ) {
88
    [% END %]
42
                    exists = true;
89
    [% IF searchfieldstype %]
43
                    return false;
90
        $("searchfieldstype_filter").val("[% searchfieldstype %]");
91
    [% END %]
92
    [% IF searchtype %]
93
        $("#searchtype_filter").val("[% searchtype %]");
94
    [% END %]
95
    [% IF categorycode %]
96
        $("#categorycode_filter").val("[% categorycode %]");
97
    [% END %]
98
    [% IF branchcode %]
99
        $("#branchcode_filter").val("[% branchcode %]");
100
    [% END %]
101
102
    [% IF view != "show_results" %]
103
        $("#searchresults").hide();
104
        search = 0;
105
    [% END %]
106
107
    // Build the aLengthMenu
108
    var aLengthMenu = [
109
        [%PatronsPerPage %], 10, 20, 50, 100, -1
110
    ];
111
    jQuery.unique(aLengthMenu);
112
    aLengthMenu.sort(function( a, b ){
113
        // Put "All" at the end
114
        if ( a == -1 ) {
115
            return 1;
116
        } else if ( b == -1 ) {
117
            return -1;
118
        }
119
        return parseInt(a) < parseInt(b) ? -1 : 1;}
120
    );
121
    var aLengthMenuLabel = [];
122
    $(aLengthMenu).each(function(){
123
        if ( this == -1 ) {
124
            // Label for -1 is "All"
125
            aLengthMenuLabel.push("All");
126
        } else {
127
            aLengthMenuLabel.push(this);
128
        }
129
    });
130
131
    // Apply DataTables on the results table
132
    dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
133
        'bServerSide': true,
134
        'sAjaxSource': "/cgi-bin/koha/svc/members/search",
135
        'fnServerData': function(sSource, aoData, fnCallback) {
136
            if ( ! search ) {
137
                return;
138
            }
139
            aoData.push({
140
                'name': 'searchmember',
141
                'value': $("#searchmember_filter").val()
142
            },{
143
                'name': 'firstletter',
144
                'value': $("#firstletter_filter").val()
145
            },{
146
                'name': 'searchfieldstype',
147
                'value': $("#searchfieldstype_filter").val()
148
            },{
149
                'name': 'searchtype',
150
                'value': $("#searchtype_filter").val()
151
            },{
152
                'name': 'categorycode',
153
                'value': $("#categorycode_filter").val()
154
            },{
155
                'name': 'branchcode',
156
                'value': $("#branchcode_filter").val()
157
            },{
158
                'name': 'name_sorton',
159
                'value': 'borrowers.surname borrowers.firstname'
160
            },{
161
                'name': 'category_sorton',
162
                'value': 'categories.description',
163
            },{
164
                'name': 'branch_sorton',
165
                'value': 'branches.branchname'
166
            },{
167
                'name': 'template_path',
168
                'value': 'members/tables/members_results.tt',
169
            });
170
            $.ajax({
171
                'dataType': 'json',
172
                'type': 'POST',
173
                'url': sSource,
174
                'data': aoData,
175
                'success': function(json){
176
                    // redirect if there is only 1 result.
177
                    if ( json.aaData.length == 1 ) {
178
                        var borrowernumber = json.aaData[0].borrowernumber;
179
                        document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
180
                        return false;
181
                    }
182
                    fnCallback(json);
44
                }
183
                }
45
            });
184
            });
185
        },
186
        'aoColumns':[
187
            [% IF CAN_user_tools_manage_patron_lists %]
188
              { 'mDataProp': 'dt_borrowernumber' },
189
            [% END %]
190
            { 'mDataProp': 'dt_cardnumber' },
191
            { 'mDataProp': 'dt_name' },
192
            { 'mDataProp': 'dt_category' },
193
            { 'mDataProp': 'dt_branch' },
194
            { 'mDataProp': 'dt_dateexpiry' },
195
            { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
196
            { 'mDataProp': 'dt_fines', 'bSortable': false },
197
            { 'mDataProp': 'dt_borrowernotes' },
198
            { 'mDataProp': 'dt_action', 'bSortable': false }
199
        ],
200
        'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
201
            /* Center text for 6th column */
202
            $("td:eq(5)", nRow).css("text-align", "center");
46
203
47
            if ( exists ) {
204
            return nRow;
48
                alert( _("You already have a list with that name!") );
205
        },
49
                return false;
206
        'bFilter': false,
50
            }
207
        'bAutoWidth': false,
208
        [% IF orderby_cardnumber_0 %]
209
            'aaSorting': [[0, 'asc']],
210
        [% ELSE %]
211
            'aaSorting': [[1, 'asc']],
212
        [% END %]
213
        "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
214
        'sPaginationType': 'full_numbers',
215
        "iDisplayLength": [% PatronsPerPage %],
216
    }));
217
    update_searched();
218
});
219
220
// Update the string "Results found ..."
221
function update_searched(){
222
    var searched = "";
223
    searched += "on " + $("#searchfieldstype_filter").find("option:selected").text().toLowerCase() + " fields";
224
    if ( $("#searchmember_filter").val() ) {
225
        if ( $("#searchtype_filter").val() == 'start_with' ) {
226
            searched += _(" starting with ");
51
        } else {
227
        } else {
52
            alert( _("You must give your new patron list a name!") );
228
            searched += _(" containing ");
53
            return false;
54
        }
229
        }
230
        searched += $("#searchmember_filter").val();
231
    }
232
    if ( $("#firstletter_filter").val() ) {
233
        searched += _(" begin with ") + $("#firstletter_filter").val();
234
    }
235
    if ( $("#categorycode_filter").val() ) {
236
        searched += _(" with category ") + $("#categorycode_filter").find("option:selected").text();
55
    }
237
    }
238
    if ( $("#branchcode_filter").val() ) {
239
        searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
240
    }
241
    $("#searchpattern").text("for patron " + searched);
242
}
56
243
57
    if ( $('#add_to_patron_list_which').val() == 'all' ) {
244
// Redraw the table
58
        return confirm( _("Are you sure you want to add the entire set of patron results to this list ( including results on other pages )?") );
245
function filter() {
59
    } else {
246
    $("#firstletter_filter").val('');
60
         if ( $("#add-patrons-to-list-form input:checkbox:checked").length == 0 ) {
247
    update_searched();
61
             alert( _("You have not selected any patrons to add to a list!") );
248
    search = 1;
62
             return false;
249
    $("#searchresults").show();
63
         }
250
    dtMemberResults.fnDraw();
251
    return false;
252
}
253
254
// User has clicked on the Clear button
255
function clearFilters(redraw) {
256
    $("#searchform select").val('');
257
    $("#firstletter_filter").val('');
258
    $("#searchmember_filter").val('');
259
    if(redraw) {
260
        search = 1;
261
        $("#searchresults").show();
262
        dtMemberResults.fnDraw();
64
    }
263
    }
264
}
65
265
66
    return true;
266
// User has clicked on a letter
267
function filterByFirstLetterSurname(letter) {
268
    clearFilters(false);
269
    $("#firstletter_filter").val(letter);
270
    update_searched();
271
    search = 1;
272
    $("#searchresults").show();
273
    dtMemberResults.fnDraw();
67
}
274
}
68
//]]>
275
//]]>
69
</script>
276
</script>
70
71
</head>
277
</head>
72
<body id="pat_member" class="pat">
278
<body id="pat_member" class="pat">
73
[% INCLUDE 'header.inc' %]
279
[% INCLUDE 'header.inc' %]
Lines 75-235 function CheckForm() { Link Here
75
281
76
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; [% IF ( searching ) %]<a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Search results[% ELSE %]Patrons[% END %]</div>
282
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; [% IF ( searching ) %]<a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Search results[% ELSE %]Patrons[% END %]</div>
77
283
78
<div id="doc2" class="yui-t7">
284
<div id="doc3" class="yui-t2">
285
  <div id="bd">
286
    <div id="yui-main">
287
      <div class="yui-b">
288
        <div class="yui-g">
289
          [% IF CAN_user_tools_manage_patron_lists %]
290
            <div id="patron_list_dialog" class="dialog alert">
291
              Added <span class="patrons-length"></span> patrons to <a></a>.
292
            </div>
293
          [% END %]
79
294
80
   <div id="bd">
295
          [% INCLUDE 'patron-toolbar.inc' %]
81
		<div id="yui-main">
296
          [% IF ( no_add ) %]
82
		    <div class="yui-b">
297
            <div class="dialog alert">
83
				<div class="yui-g">
298
              <h3>Cannot add patron</h3>
299
              [% IF ( no_branches ) %]
300
                <p>There are <strong>no libraries defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/branches.pl">add a library</a>.[% ELSE %]An administrator must define at least one library.[% END %]</p>
301
              [% END %]
302
              [% IF ( no_categories ) %]
303
                <p>There are <strong>no patron categories defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/categorie.pl">add a patron category</a>.[% ELSE %]An administrator must define at least one patron category.[% END %]</p>
304
              [% END %]
305
            </div>
306
          [% END %]
307
          <div class="browse">
308
            Browse by last name:
309
            [% FOREACH letter IN alphabet.split(' ') %]
310
              <a style="cursor:pointer" onclick="filterByFirstLetterSurname('[% letter %]');">[% letter %]</a>
311
            [% END %]
312
          </div>
84
313
85
                [% IF patron_list %]
314
          [% IF ( CAN_user_borrowers && pending_borrower_modifications ) %]
86
                    <div class="dialog alert">
315
            <div class="pending-info" id="patron_updates_pending">
87
                        Added [% patrons_added_to_list.size %] patrons to <a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% patron_list.patron_list_id %]">[% patron_list.name %]</a>.
316
              <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
88
                    </div>
317
              <span class="holdcount"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications %]</a></span>
89
                [% END %]
318
            </div>
319
          [% END %]
320
321
          <div id="searchresults">
322
            <div id="searchheader">
323
              <h3>Results found <span id="searchpattern">[% IF searchmember %] for '[% searchmember %]'[% END %]</span></h3>
324
            </div>
325
            [% IF CAN_user_tools_manage_patron_lists %]
326
              <div id="searchheader">
327
                  <div>
328
                      <a href="javascript:void(0)" onclick="$('.selection').prop('checked', true)">Select all</a>
329
                      |
330
                      <a href="javascript:void(0)" onclick="$('.selection').prop('checked', false)">Clear all</a>
331
                      |
332
                      <span>
333
                          Add selected patrons
334
                          <label for="add_to_patron_list">to:</label>
335
                          <select id="add_to_patron_list" name="add_to_patron_list">
336
                              <option value=""></option>
337
                              [% IF patron_lists %]
338
                                  <optgroup label="Patron lists:">
339
                                      [% FOREACH pl IN patron_lists %]
340
                                          <option value="[% pl.patron_list_id %]">[% pl.name %]</option>
341
                                      [% END %]
342
                                  </optgroup>
343
                              [% END %]
344
345
                              <option value="new">[ New list ]</option>
346
                          </select>
90
347
91
				[% INCLUDE 'patron-toolbar.inc' %]
348
                          <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
92
93
	[% IF ( no_add ) %]<div class="dialog alert"><h3>Cannot add patron</h3>
94
		[% IF ( no_branches ) %]<p>There are <strong>no libraries defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/branches.pl">add a library</a>.[% ELSE %]An administrator must define at least one library.[% END %]</p>[% END %]
95
		[% IF ( no_categories ) %]<p>There are <strong>no patron categories defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/categorie.pl">add a patron category</a>.[% ELSE %]An administrator must define at least one patron category.[% END %]</p>[% END %]</div>
96
	[% END %]
97
98
						<div class="browse">
99
							Browse by last name:
100
                            [% FOREACH letter IN alphabet.split(' ') %]
101
                                <a href="/cgi-bin/koha/members/member.pl?quicksearch=1&amp;surname=[% letter %]">[% letter %]</a>
102
							[% END %]
103
						</div>
104
105
                    [% IF ( CAN_user_borrowers && pending_borrower_modifications ) %]
106
                        <div class="pending-info" id="patron_updates_pending">
107
                            <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
108
                            <span class="holdcount"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications %]</a></span>
109
                        </div>
110
                    [% END %]
111
112
                    [% IF ( resultsloop ) %]
113
                    [% IF (CAN_user_tools_manage_patron_lists) %]
114
                    <form id="add-patrons-to-list-form" method="post" action="member.pl" onsubmit="return CheckForm()">
115
                    [% END %]
116
                        <div id="searchheader">
117
                            <h3>Results [% from %] to [% to %] of [% numresults %] found for [% IF ( member ) %]'<span class="ex">[% member %]</span>'[% END %][% IF ( surname ) %]'<span class="ex">[% surname %]</span>'[% END %]</h3>
118
119
                            [% IF (CAN_user_tools_manage_patron_lists) %]
120
                            <div>
121
                                <a href="javascript:void(0)" onclick="$('.selection').prop('checked', true)">Select all</a>
122
                                |
123
                                <a href="javascript:void(0)" onclick="$('.selection').prop('checked', false)">Clear all</a>
124
                                |
125
                                <span>
126
                                    <label for="add_to_patron_list_which">Add:</label>
127
                                    <select id="add_to_patron_list_which" name="add_to_patron_list_which">
128
                                        <option value="selected">Selected patrons</option>
129
                                        <option value="all">All resultant patrons</option>
130
                                    </select>
131
132
                                    <label for="add_to_patron_list">to:</label>
133
                                    <select id="add_to_patron_list" name="add_to_patron_list">
134
                                        <option value=""></option>
135
                                        [% IF patron_lists %]
136
                                            <optgroup label="Patron lists:">
137
                                                [% FOREACH pl IN patron_lists %]
138
                                                    <option value="[% pl.patron_list_id %]">[% pl.name %]</option>
139
                                                [% END %]
140
                                            </optgroup>
141
                                        [% END %]
142
143
                                        <option value="new">[ New list ]</option>
144
                                    </select>
145
146
                                    <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
147
148
                                    [% FOREACH key IN search_parameters.keys %]
149
                                        <input type="hidden" name="[% key %]" value="[% search_parameters.$key %]" />
150
                                    [% END %]
151
152
                                    <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
153
                                </span>
154
                            </div>
155
                            [% END %]
156
                        </div>
157
						<div class="searchresults">
158
159
							<table id="memberresultst">
160
							<thead>
161
							<tr>
162
                            [% IF (CAN_user_tools_manage_patron_lists) %]
163
                            <th>&nbsp</th>
164
                            [% END %]
165
							<th>Card</th>
166
							<th>Name</th>
167
							<th>Cat</th>
168
							<th>Library</th>
169
							<th>Expires on</th>
170
							<th>OD/Checkouts</th>
171
							<th>Fines</th>
172
							<th>Circ note</th>
173
							<th>&nbsp;</th>
174
							</tr>
175
							</thead>
176
							<tbody>
177
							[% FOREACH resultsloo IN resultsloop %]
178
							[% IF ( resultsloo.overdue ) %]
179
							<tr class="problem">
180
							[% ELSE %]
181
							[% UNLESS ( loop.odd ) %]
182
							<tr class="highlight">
183
							[% ELSE %]
184
							<tr>
185
							[% END %]
186
							[% END %]
187
                            [% IF (CAN_user_tools_manage_patron_lists) %]
188
                            <td><input type="checkbox" class="selection" name="borrowernumber" value="[% resultsloo.borrowernumber %]" /></td>
189
                            [% END %]
190
							<td>[% resultsloo.cardnumber %]</td>
191
                            <td style="white-space: nowrap;">
192
                            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% resultsloo.borrowernumber %]">
193
                            [% INCLUDE 'patron-title.inc' borrowernumber = resultsloo.borrowernumber category_type = resultsloo.category_type firstname = resultsloo.firstname surname = resultsloo.surname othernames = resultsloo.othernames cardnumber = resultsloo.cardnumber invert_name = 1%]
194
                            </a> <br />
195
                            [% IF ( resultsloo.streetnumber ) %][% resultsloo.streetnumber %] [% END %][% resultsloo.address %][% IF ( resultsloo.address2 ) %]<br />[% resultsloo.address2 %][% END %][% IF ( resultsloo.city ) %]<br />[% resultsloo.city %][% IF ( resultsloo.state ) %],[% END %][% END %][% IF ( resultsloo.state ) %] [% resultsloo.state %][% END %] [% IF ( resultsloo.zipcode ) %]  [% resultsloo.zipcode %][% END %][% IF ( resultsloo.country ) %], [% resultsloo.country %][% END %]</td>
196
							<td>[% resultsloo.category_description %] ([% resultsloo.category_type %])</td>
197
							<td>[% resultsloo.branchname %]</td>
198
							<td>[% resultsloo.dateexpiry %]</td>
199
							<td>[% IF ( resultsloo.overdues ) %]<span class="overdue"><strong>[% resultsloo.overdues %]</strong></span>[% ELSE %][% resultsloo.overdues %][% END %]/[% resultsloo.issues %]</td>
200
							<td>[% IF ( resultsloo.fines < 0 ) %]<span class="credit">[% resultsloo.fines %]</span> [% ELSIF resultsloo.fines > 0 %] <span class="debit"><strong>[% resultsloo.fines %]</strong></span> [% ELSE %] [% resultsloo.fines %] [% END %]</td>
201
							<td>[% resultsloo.borrowernotes %]</td>
202
							<td>[% IF ( resultsloo.category_type ) %]
203
									<a href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% resultsloo.borrowernumber %]&amp;category_type=[% resultsloo.category_type %]">Edit</a>
204
						[% ELSE %] <!-- try with categorycode if no category_type -->
205
							[% IF ( resultsloo.categorycode ) %]
206
									<a href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% resultsloo.borrowernumber %]&amp;categorycode=[% resultsloo.categorycode %]">Edit</a>
207
							[% ELSE %] <!-- if no categorycode, set category_type to A by default -->
208
									<a href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% resultsloo.borrowernumber %]&amp;category_type=A">Edit</a>
209
							[% END %]
210
						[% END %]</td>
211
							</tr>
212
							[% END %]
213
							</tbody>
214
							</table>
215
							<div class="pages">[% IF ( multipage ) %][% paginationbar %][% END %]</div>
216
						</div>
217
                    [% IF (CAN_user_tools_manage_patron_lists) %]
218
                    </form>
219
                    [% END %]
220
                    [% ELSE %]
221
                        [% IF ( searching ) %]
222
                            <div class="dialog alert">No results found</div>
223
                        [% END %]
224
                    [% END %]
225
226
					</div>
227
				</div>
228
229
				<div class="yui-g">
230
				[% INCLUDE 'members-menu.inc' %]
231
			</div>
232
349
350
                          <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
351
                      </span>
352
                  </div>
353
              </div>
354
            [% END %]
355
356
            <table id="memberresultst">
357
              <thead>
358
                <tr>
359
                  <th>&nbsp;</th>
360
                  <th>Card</th>
361
                  <th>Name</th>
362
                  <th>Category</th>
363
                  <th>Library</th>
364
                  <th>Expires on</th>
365
                  <th>OD/Checkouts</th>
366
                  <th>Fines</th>
367
                  <th>Circ note</th>
368
                  <th>&nbsp;</th>
369
                </tr>
370
              </thead>
371
              <tbody></tbody>
372
            </table>
373
          </div>
374
        </div>
375
      </div>
376
    </div>
377
    <div class="yui-b">
378
      <form onsubmit="return filter();" id="searchform">
379
        <input type="hidden" id="firstletter_filter" value="" />
380
        <fieldset class="brief">
381
          <h3>Filters</h3>
382
          <ol>
383
            <li>
384
              <label for="searchmember_filter">Search:</label>
385
              <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
386
            </li>
387
            <li>
388
              <label for="searchfieldstype_filter">Search fields:</label>
389
              <select name="searchfieldstype" id="searchfieldstype_filter">
390
                [% IF searchfieldstype == "standard" %]
391
                  <option selected="selected" value='standard'>Standard</option>
392
                [% ELSE %]
393
                  <option value='standard'>Standard</option>
394
                [% END %]
395
                [% IF searchfieldstype == "email" %]
396
                  <option selected="selected" value='email'>Email</option>
397
                [% ELSE %]
398
                  <option value='email'>Email</option>
399
                [% END %]
400
                [% IF searchfieldstype == "borrowernumber" %]
401
                  <option selected="selected" value='borrowernumber'>Borrower number</option>
402
                [% ELSE %]
403
                  <option value='borrowernumber'>Borrower number</option>
404
                [% END %]
405
                [% IF searchfieldstype == "phone" %]
406
                  <option selected="selected" value='phone'>Phone number</option>
407
                [% ELSE %]
408
                  <option value='phone'>Phone number</option>
409
                [% END %]
410
                [% IF searchfieldstype == "address" %]
411
                  <option selected="selected" value='address'>Street address</option>
412
                [% ELSE %]
413
                  <option value='address'>Street address</option>
414
                [% END %]
415
                [% IF searchfieldstype == "dateofbirth" %]
416
                  <option selected="selected" value='dateofbirth'>Date of birth</option>
417
                [% ELSE %]
418
                  <option value='dateofbirth'>Date of birth</option>
419
                [% END %]
420
              </select>
421
            </li>
422
            <li>
423
              <label for="searchtype_filter">Search type:</label>
424
              <select name="searchtype" id="searchtype_filter">
425
                <option value='start_with'>Starts with</option>
426
                [% IF searchtype == "contain" %]
427
                  <option value="contain" selected="selected">Contains</option>
428
                [% ELSE %]
429
                  <option value="contain" selected="selected">Contains</option>
430
                [% END %]
431
              </select>
432
            </li>
433
            <li>
434
              <label for="categorycode_filter">Category:</label>
435
              <select id="categorycode_filter">
436
                <option value="">Any</option>
437
                [% FOREACH cat IN categories %]
438
                  [% IF cat.selected %]
439
                    <option selected="selected" value="[% cat.categorycode %]">[% cat.description %]</option>
440
                  [% ELSE %]
441
                    <option value="[% cat.categorycode %]">[% cat.description %]</option>
442
                  [% END %]
443
                [% END %]
444
              </select>
445
            </li>
446
            <li>
447
              <label for="branchcode_filter">Branch:</label>
448
              <select id="branchcode_filter">
449
                [% IF branchloop.size != 1 %]
450
                  <option value="">Any</option>
451
                [% END %]
452
                [% FOREACH b IN branchloop %]
453
                  [% IF b.selected %]
454
                    <option selected="selected" value="[% b.branchcode %]">[% b.branchname %]</option>
455
                  [% ELSE %]
456
                    <option value="[% b.branchcode %]">[% b.branchname %]</option>
457
                  [% END %]
458
                [% END %]
459
              </select>
460
            </li>
461
          </ol>
462
          <fieldset class="action">
463
            <input type="submit" value="Search" />
464
            <input type="button" value="Clear" onclick="clearFilters(true);" />
465
          </fieldset>
466
        </fieldset>
467
      </form>
233
    </div>
468
    </div>
469
  </div>
470
  <div class="yui-g">
471
    [% INCLUDE 'members-menu.inc' %]
472
  </div>
234
</div>
473
</div>
235
[% INCLUDE 'intranet-bottom.inc' %]
474
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt (+35 lines)
Line 0 Link Here
1
{
2
    "sEcho": [% sEcho %],
3
    "iTotalRecords": [% iTotalRecords %],
4
    "iTotalDisplayRecords": [% iTotalDisplayRecords %],
5
    "aaData": [
6
        [% FOREACH data IN aaData %]
7
            {
8
                [% IF CAN_user_tools_manage_patron_lists %]
9
                "dt_borrowernumber":
10
                    "<input type='checkbox' class='selection' name='borrowernumber' value='[% data.borrowernumber %]' />",
11
                [% END %]
12
                "dt_cardnumber":
13
                    "[% data.cardnumber %]",
14
                "dt_name":
15
                    "<span style='white-space:nowrap'><a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=[% data.borrowernumber %]'>[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames cardnumber = data.cardnumber invert_name = 1%]</a><br />[% IF ( data.streetnumber ) %][% data.streetnumber %] [% END %][% data.address %][% IF ( data.address2 ) %]<br />[% data.address2 %][% END %][% IF ( data.city ) %]<br />[% data.city %][% IF ( data.state ) %],[% END %][% END %][% IF ( data.state ) %] [% data.state %][% END %] [% IF ( data.zipcode ) %]  [% data.zipcode %][% END %][% IF ( data.country ) %], [% data.country %][% END %]</span>",
16
                "dt_category":
17
                    "[% data.category_description |html %]([% data.category_type |html %])",
18
                "dt_branch":
19
                    "[% data.branchname |html %]",
20
                "dt_dateexpiry":
21
                    "[% data.dateexpiry %]",
22
                "dt_od_checkouts":
23
                    "[% IF data.overdues %]<span class='overdue'><strong>[% data.overdues %]</strong></span>[% ELSE %][% data.overdues %][% END %] / [% data.issues %]",
24
                "dt_fines":
25
                    "[% IF data.fines < 0 %]<span class='credit'>[% data.fines |html %]</span> [% ELSIF data.fines > 0 %] <span class='debit'><strong>[% data.fines |html %]</strong></span> [% ELSE %] [% data.fines |html%] [% END %]</td>",
26
                "dt_borrowernotes":
27
                    "[% data.borrowernotes |html |html_line_break |collapse %]",
28
                "dt_action":
29
                    "[% IF data.category_type %]<a href='/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% data.borrowernumber %]&amp;category_type=[% data.category_type %]'>Edit</a>[% ELSE %][% IF data.categorycode %]<a href='/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% data.borrowernumber %]&amp;categorycode=[% data.categorycode %]'>Edit</a>[% ELSE %]<a href='/cgi-bin/koha/members/memberentry.pl?op=modify&amp;destination=circ&amp;borrowernumber=[% data.borrowernumber %]&amp;category_type=A'>Edit</a>[% END %][% END %]",
30
                "borrowernumber":
31
                    "[% data.borrowernumber %]"
32
            }[% UNLESS loop.last %],[% END %]
33
        [% END %]
34
    ]
35
}
(-)a/members/member.pl (-168 / +46 lines)
Lines 6-12 Link Here
6
6
7
7
8
# Copyright 2000-2002 Katipo Communications
8
# Copyright 2000-2002 Katipo Communications
9
# Copyright 2010 BibLibre
9
# Copyright 2013 BibLibre
10
#
10
#
11
# This file is part of Koha.
11
# This file is part of Koha.
12
#
12
#
Lines 27-33 use Modern::Perl; Link Here
27
use C4::Auth;
27
use C4::Auth;
28
use C4::Output;
28
use C4::Output;
29
use CGI;
29
use CGI;
30
use C4::Members;
31
use C4::Branch;
30
use C4::Branch;
32
use C4::Category;
31
use C4::Category;
33
use Koha::DateUtils;
32
use Koha::DateUtils;
Lines 35-43 use File::Basename; Link Here
35
use Koha::List::Patron;
34
use Koha::List::Patron;
36
35
37
my $input = new CGI;
36
my $input = new CGI;
38
my $quicksearch = $input->param('quicksearch') || '';
39
my $startfrom = $input->param('startfrom') || 1;
40
my $resultsperpage = $input->param('resultsperpage') || C4::Context->preference("PatronsPerPage") || 20;
41
37
42
my ($template, $loggedinuser, $cookie)
38
my ($template, $loggedinuser, $cookie)
43
    = get_template_and_user({template_name => "members/member.tmpl",
39
    = get_template_and_user({template_name => "members/member.tmpl",
Lines 49-237 my ($template, $loggedinuser, $cookie) Link Here
49
45
50
my $theme = $input->param('theme') || "default";
46
my $theme = $input->param('theme') || "default";
51
47
52
my $add_to_patron_list       = $input->param('add_to_patron_list');
53
my $add_to_patron_list_which = $input->param('add_to_patron_list_which');
54
my $new_patron_list          = $input->param('new_patron_list');
55
my @borrowernumbers          = $input->param('borrowernumber');
56
$input->delete(
57
    'add_to_patron_list', 'add_to_patron_list_which',
58
    'new_patron_list',    'borrowernumber',
59
);
60
61
my $patron = $input->Vars;
48
my $patron = $input->Vars;
62
foreach (keys %$patron){
49
foreach (keys %$patron){
63
	delete $$patron{$_} unless($$patron{$_});
50
    delete $patron->{$_} unless($patron->{$_});
64
}
65
my @categories=C4::Category->all;
66
67
my $branches = GetBranches;
68
my @branchloop;
69
70
foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
71
  my $selected;
72
  $selected = 1 if $patron->{branchcode} && $branches->{$_}->{branchcode} eq $patron->{branchcode};
73
  my %row = ( value => $_,
74
        selected => $selected,
75
        branchname => $branches->{$_}->{branchname},
76
      );
77
  push @branchloop, \%row;
78
}
79
80
my %categories_dislay;
81
82
foreach my $category (@categories){
83
	my $hash={
84
			category_description=>$$category{description},
85
			category_type=>$$category{category_type}
86
			 };
87
	$categories_dislay{$$category{categorycode}} = $hash;
88
}
51
}
89
my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
90
$template->param( 
91
        "AddPatronLists_$AddPatronLists" => "1",
92
            );
93
if ($AddPatronLists=~/code/){
94
    $categories[0]->{'first'}=1;
95
}  
96
97
my $member=$input->param('member') || '';
98
my $orderbyparams=$input->param('orderby') || '';
99
my @orderby;
100
if ($orderbyparams){
101
	my @orderbyelt=split(/,/,$orderbyparams);
102
	push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
103
}
104
else {
105
	@orderby = ({surname=>0},{firstname=>0});
106
}
107
108
$member =~ s/,//g;   #remove any commas from search string
109
$member =~ s/\*/%/g;
110
111
my $from = ( $startfrom - 1 ) * $resultsperpage;
112
my $to   = $from + $resultsperpage;
113
114
my ($count,$results);
115
if ($member || keys %$patron) {
116
    my $searchfields = $input->param('searchfields') || '';
117
    my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
118
52
119
    if ( $searchfields eq "dateofbirth" ) {
53
my $searchmember = $input->param('searchmember');
120
        $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1});
121
    }
122
54
123
    my $searchtype = $input->param('searchtype');
55
my $searchfieldstype = $input->param('searchfieldstype') || 'standard';
124
    my $search_scope =
125
        $quicksearch ? "field_start_with"
126
      : $searchtype  ? $searchtype
127
      :                "start_with";
128
56
129
    ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
57
if ( $searchfieldstype eq "dateofbirth" ) {
58
    $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
130
}
59
}
131
60
132
if ($add_to_patron_list) {
61
my $branches = C4::Branch::GetBranches;
133
    my $patron_list;
62
my @branches_loop;
134
63
if ( C4::Branch::onlymine ) {
135
    if ( $add_to_patron_list eq 'new' ) {
64
    my $userenv = C4::Context->userenv;
136
        $patron_list = AddPatronList( { name => $new_patron_list } );
65
    my $branch = C4::Branch::GetBranchDetail( $userenv->{'branch'} );
137
    }
66
    push @branches_loop, {
138
    else {
67
        value => $branch->{branchcode},
139
        $patron_list =
68
        branchcode => $branch->{branchcode},
140
          [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
69
        branchname => $branch->{branchname},
70
        selected => 1
141
    }
71
    }
142
72
} else {
143
    if ( $add_to_patron_list_which eq 'all' ) {
73
    foreach ( sort { lc($branches->{$a}->{branchname}) cmp lc($branches->{$b}->{branchname}) } keys %$branches ) {
144
        @borrowernumbers = map { $_->{borrowernumber} } @$results;
74
        my $selected = 0;
75
        $selected = 1 if($patron->{branchcode} and $patron->{branchcode} eq $_);
76
        push @branches_loop, {
77
            value => $_,
78
            branchcode => $_,
79
            branchname => $branches->{$_}->{branchname},
80
            selected => $selected
81
        };
145
    }
82
    }
146
147
    my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
148
149
    $template->param(
150
        patron_list           => $patron_list,
151
        patrons_added_to_list => \@patrons_added_to_list,
152
      )
153
}
83
}
154
84
155
if ($results) {
85
my @categories = C4::Category->all;
156
	for my $field ('categorycode','branchcode'){
86
if ( $patron->{categorycode} ) {
157
		next unless ($patron->{$field});
87
    foreach my $category ( grep { $_->{categorycode} eq $patron->{categorycode} } @categories ) {
158
		@$results = grep { $_->{$field} eq $patron->{$field} } @$results; 
88
        $category->{selected} = 1;
159
	}
89
    }
160
    $count = scalar(@$results);
161
} else {
162
    $count = 0;
163
}
90
}
164
91
165
if($count == 1){
92
$template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
166
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
167
    exit;
168
}
169
93
170
my @resultsdata;
94
my $orderby = $input->param('orderby') // '';
171
$to=($count>$to?$to:$count);
95
if(defined $orderby and $orderby ne '') {
172
my $index=$from;
96
    $orderby =~ s/[, ]/_/g;
173
foreach my $borrower(@$results[$from..$to-1]){
174
  #find out stats
175
  my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
176
  $fines ||= 0;
177
  $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
178
179
  my %row = (
180
    count => $index++,
181
    %$borrower,
182
    (defined $categories_dislay{ $borrower->{categorycode} }?   %{ $categories_dislay{ $borrower->{categorycode} } }:()),
183
    overdues => $od,
184
    issues => $issue,
185
    odissue => "$od/$issue",
186
    fines =>  sprintf("%.2f",$fines),
187
    branchname => $branches->{$borrower->{branchcode}}->{branchname},
188
    );
189
  push(@resultsdata, \%row);
190
}
97
}
191
98
192
if ($$patron{categorycode}){
99
my $view = $input->request_method() eq "GET" ? "show_form" : "show_results";
193
	foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
194
		$$category{selected}=1;
195
	}
196
}
197
my %parameters=
198
        (  %$patron
199
		, 'orderby'			=> $orderbyparams 
200
		, 'resultsperpage'	=> $resultsperpage 
201
        , 'type'=> 'intranet'); 
202
my $base_url =
203
    'member.pl?&amp;'
204
  . join(
205
    '&amp;',
206
    map { "$_=$parameters{$_}" } (keys %parameters)
207
  );
208
209
my @letters = map { {letter => $_} } ( 'A' .. 'Z');
210
100
211
$template->param(
101
$template->param(
212
    %$patron,
213
    letters       => \@letters,
214
    paginationbar => pagination_bar(
215
        $base_url,
216
        int( $count / $resultsperpage ) + ( $count % $resultsperpage ? 1 : 0 ),
217
        $startfrom,
218
        'startfrom'
219
    ),
220
    startfrom    => $startfrom,
221
    from         => ( $startfrom - 1 ) * $resultsperpage + 1,
222
    to           => $to,
223
    multipage    => ( $count != $to || $startfrom != 1 ),
224
    advsearch    => ( $$patron{categorycode} || $$patron{branchcode} ),
225
    branchloop   => \@branchloop,
226
    categories   => \@categories,
227
    searching    => "1",
228
    actionname   => basename($0),
229
    numresults   => $count,
230
    resultsloop  => \@resultsdata,
231
    results_per_page => $resultsperpage,
232
    member => $member,
233
    search_parameters => \%parameters,
234
    patron_lists => [ GetPatronLists() ],
102
    patron_lists => [ GetPatronLists() ],
103
    searchmember        => $searchmember,
104
    branchloop          => \@branches_loop,
105
    categories          => \@categories,
106
    branchcode          => $patron->{branchcode},
107
    categorycode        => $patron->{categorycode},
108
    searchtype          => $input->param('searchtype') || 'start_with',
109
    searchfieldstype    => $searchfieldstype,
110
    "orderby_$orderby"  => 1,
111
    PatronsPerPage      => C4::Context->preference("PatronsPerPage") || 20,
112
    view                => $view,
235
);
113
);
236
114
237
output_html_with_http_headers $input, $cookie, $template->output;
115
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/members-home.pl (-6 / +21 lines)
Lines 45-56 my ($template, $loggedinuser, $cookie) Link Here
45
45
46
my $branches = GetBranches;
46
my $branches = GetBranches;
47
my @branchloop;
47
my @branchloop;
48
foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) {
48
if ( C4::Branch::onlymine ) {
49
    my $userenv = C4::Context->userenv;
50
    my $branch = C4::Branch::GetBranchDetail( $userenv->{'branch'} );
49
    push @branchloop, {
51
    push @branchloop, {
50
        value      => $_,
52
        value => $branch->{branchcode},
51
        selected   => ($branches->{$_}->{branchcode} eq $branch),
53
        branchcode => $branch->{branchcode},
52
        branchname => $branches->{$_}->{branchname},
54
        branchname => $branch->{branchname},
53
    };
55
        selected => 1
56
    }
57
} else {
58
    foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) {
59
        push @branchloop, {
60
            value      => $_,
61
            selected   => ($branches->{$_}->{branchcode} eq $branch),
62
            branchname => $branches->{$_}->{branchname},
63
        };
64
    }
54
}
65
}
55
66
56
my @categories;
67
my @categories;
Lines 86-91 $template->param( Link Here
86
        no_add => $no_add,
97
        no_add => $no_add,
87
        pending_borrower_modifications => $pending_borrower_modifications,
98
        pending_borrower_modifications => $pending_borrower_modifications,
88
            );
99
            );
89
$template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
100
101
$template->param(
102
    alphabet => C4::Context->preference('alphabet') || join (' ', 'A' .. 'Z'),
103
    PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
104
);
90
105
91
output_html_with_http_headers $query, $cookie, $template->output;
106
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/members/moremember.pl (-10 / +9 lines)
Lines 53-60 use C4::Form::MessagingPreferences; Link Here
53
use List::MoreUtils qw/uniq/;
53
use List::MoreUtils qw/uniq/;
54
use C4::Members::Attributes qw(GetBorrowerAttributes);
54
use C4::Members::Attributes qw(GetBorrowerAttributes);
55
55
56
#use Smart::Comments;
57
#use Data::Dumper;
58
use DateTime;
56
use DateTime;
59
use Koha::DateUtils;
57
use Koha::DateUtils;
60
58
Lines 82-102 my $template_name; Link Here
82
my $quickslip = 0;
80
my $quickslip = 0;
83
81
84
my $flagsrequired;
82
my $flagsrequired;
85
if ($print eq "page") {
83
if (defined $print and $print eq "page") {
86
    $template_name = "members/moremember-print.tmpl";
84
    $template_name = "members/moremember-print.tmpl";
87
    # circ staff who process checkouts but can't edit
85
    # circ staff who process checkouts but can't edit
88
    # patrons still need to be able to access print view
86
    # patrons still need to be able to access print view
89
    $flagsrequired = { circulate => "circulate_remaining_permissions" };
87
    $flagsrequired = { circulate => "circulate_remaining_permissions" };
90
} elsif ($print eq "slip") {
88
} elsif (defined $print and $print eq "slip") {
91
    $template_name = "members/moremember-receipt.tmpl";
89
    $template_name = "members/moremember-receipt.tmpl";
92
    # circ staff who process checkouts but can't edit
90
    # circ staff who process checkouts but can't edit
93
    # patrons still need to be able to print receipts
91
    # patrons still need to be able to print receipts
94
    $flagsrequired =  { circulate => "circulate_remaining_permissions" };
92
    $flagsrequired =  { circulate => "circulate_remaining_permissions" };
95
} elsif ($print eq "qslip") {
93
} elsif (defined $print and $print eq "qslip") {
96
    $template_name = "members/moremember-receipt.tmpl";
94
    $template_name = "members/moremember-receipt.tmpl";
97
    $quickslip = 1;
95
    $quickslip = 1;
98
    $flagsrequired =  { circulate => "circulate_remaining_permissions" };
96
    $flagsrequired =  { circulate => "circulate_remaining_permissions" };
99
} elsif ($print eq "brief") {
97
} elsif (defined $print and $print eq "brief") {
100
    $template_name = "members/moremember-brief.tmpl";
98
    $template_name = "members/moremember-brief.tmpl";
101
    $flagsrequired = { borrowers => 1 };
99
    $flagsrequired = { borrowers => 1 };
102
} else {
100
} else {
Lines 157-163 if ($debar) { Link Here
157
}
155
}
158
156
159
$data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
157
$data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
160
$data->{ "sex_".$data->{'sex'}."_p" } = 1;
158
$data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex};
161
159
162
my $catcode;
160
my $catcode;
163
if ( $category_type eq 'C') {
161
if ( $category_type eq 'C') {
Lines 281-293 if ($borrowernumber) { Link Here
281
        $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
279
        $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
282
        $getreserv{itemtype}  = $itemtypeinfo->{'description'};
280
        $getreserv{itemtype}  = $itemtypeinfo->{'description'};
283
281
284
        # 		check if we have a waitin status for reservations
282
        # check if we have a waitin status for reservations
285
        if ( $num_res->{'found'} eq 'W' ) {
283
        if ( defined $num_res->{found} and $num_res->{'found'} eq 'W' ) {
286
            $getreserv{color}   = 'reserved';
284
            $getreserv{color}   = 'reserved';
287
            $getreserv{waiting} = 1;
285
            $getreserv{waiting} = 1;
288
        }
286
        }
289
287
290
        # 		check transfers with the itemnumber foud in th reservation loop
288
        # check transfers with the itemnumber foud in th reservation loop
291
        if ($transfertwhen) {
289
        if ($transfertwhen) {
292
            $getreserv{color}      = 'transfered';
290
            $getreserv{color}      = 'transfered';
293
            $getreserv{transfered} = 1;
291
            $getreserv{transfered} = 1;
Lines 430-435 $template->param( Link Here
430
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
428
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
431
    SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
429
    SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
432
    RoutingSerials => C4::Context->preference('RoutingSerials'),
430
    RoutingSerials => C4::Context->preference('RoutingSerials'),
431
    PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
433
);
432
);
434
$template->param( $error => 1 ) if $error;
433
$template->param( $error => 1 ) if $error;
435
434
(-)a/svc/members/add_to_list (+63 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 BibLibre
4
#
5
# This file is part of Koha
6
#
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
10
# version.
11
#
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.
15
#
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.
19
20
use Modern::Perl;
21
use CGI;
22
23
use C4::Auth qw( check_cookie_auth );
24
use JSON qw( to_json );
25
use Koha::List::Patron;
26
27
my $input = new CGI;
28
29
my ( $auth_status, $sessionID ) = check_cookie_auth(
30
    $input->cookie('CGISESSID'),
31
    { tools => 'manage_patron_lists' },
32
);
33
34
exit 0 if $auth_status ne "ok";
35
my $add_to_patron_list       = $input->param('add_to_patron_list');
36
my $new_patron_list          = $input->param('new_patron_list');
37
my @borrowernumbers          = $input->param('borrowernumbers[]');
38
39
my $response;
40
if ($add_to_patron_list) {
41
    my $patron_list = [];
42
43
    if ( $add_to_patron_list eq 'new' ) {
44
        $patron_list = AddPatronList( { name => $new_patron_list } );
45
    }
46
    else {
47
        $patron_list =
48
          [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
49
    }
50
51
    my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
52
53
    $response->{patron_list} = { patron_list_id => $patron_list->patron_list_id, name => $patron_list->name };
54
    $response->{patrons_added_to_list} = scalar( @patrons_added_to_list );
55
}
56
57
binmode STDOUT, ":encoding(UTF-8)";
58
print $input->header(
59
    -type => 'application/json',
60
    -charset => 'UTF-8'
61
);
62
63
print to_json( $response );
(-)a/svc/members/search (+119 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 BibLibre
4
#
5
# This file is part of Koha
6
#
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
10
# version.
11
#
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.
15
#
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.
19
20
use Modern::Perl;
21
use CGI;
22
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 );
27
28
my $input = new CGI;
29
30
exit unless $input->param('template_path');
31
32
my ($template, $user, $cookie) = get_template_and_user({
33
    template_name   => $input->param('template_path'),
34
    query           => $input,
35
    type            => "intranet",
36
    authnotrequired => 0,
37
    flagsrequired   => { borrowers => 1 }
38
});
39
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');
46
47
# variable information for DataTables (id)
48
my $sEcho = $input->param('sEcho');
49
50
my %dt_params = dt_get_params($input);
51
foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) {
52
    $dt_params{$_} =~ s/^dt_//;
53
}
54
55
# Perform the patrons search
56
my $results = C4::Utils::DataTables::Members::search(
57
    {
58
        searchmember => $searchmember,
59
        firstletter => $firstletter,
60
        categorycode => $categorycode,
61
        branchcode => $branchcode,
62
        searchtype => $searchtype,
63
        searchfieldstype => $searchfieldstype,
64
        dt_params => \%dt_params,
65
66
    }
67
);
68
69
$template->param(
70
    sEcho => $sEcho,
71
    iTotalRecords => $results->{iTotalRecords},
72
    iTotalDisplayRecords => $results->{iTotalDisplayRecords},
73
    aaData => $results->{patrons}
74
);
75
76
output_with_http_headers $input, $cookie, $template->output, 'json';
77
78
__END__
79
80
=head1 NAME
81
82
search - a search script for finding patrons
83
84
=head1 SYNOPSIS
85
86
This script provides a service for template for patron search using DataTables
87
88
=head2 Performing a search
89
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'
97
98
=cut
99
100
=back
101
102
=head1 LICENSE
103
104
Copyright 2013 BibLibre
105
106
This file is part of Koha.
107
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
111
version.
112
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.
116
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.
(-)a/t/DataTables/Members.t (-1 / +14 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Test::More tests => 4;
3
4
use_ok( "C4::Utils::DataTables::Members" );
5
6
my $patrons = C4::Utils::DataTables::Members::search({
7
    searchmember => "Doe",
8
    searchfieldstype => 'standard',
9
    searchtype => 'contains'
10
});
11
12
isnt( $patrons->{iTotalDisplayRecords}, undef, "The iTotalDisplayRecords key is defined");
13
isnt( $patrons->{iTotalRecords}, undef, "The iTotalRecords key is defined");
14
is( ref $patrons->{patrons}, 'ARRAY', "The patrons key is an arrayref");

Return to bug 9811