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

(-)a/C4/Utils/DataTables/Members.pm (-40 / +40 lines)
Lines 9-20 use C4::Members::Attributes qw(SearchIdMatchingAttribute ); Link Here
9
sub search {
9
sub search {
10
    my ( $params ) = @_;
10
    my ( $params ) = @_;
11
    my $searchmember = $params->{searchmember};
11
    my $searchmember = $params->{searchmember};
12
    my $firstquery = $params->{firstquery};
12
    my $firstletter = $params->{firstletter};
13
    my $firstletter = $params->{firstletter};
13
    my $categorycode = $params->{categorycode};
14
    my $categorycode = $params->{categorycode};
14
    my $branchcode = $params->{branchcode};
15
    my $branchcode = $params->{branchcode};
15
    my $searchtype = $params->{searchtype} || 'contain';
16
    my $searchtype = $params->{searchtype} || 'contain';
16
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
17
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
17
    my $dt_params = $params->{dt_params};
18
    my $dt_params = $params->{dt_params};
19
    my $searchfiltering = $params->{search_filter};
18
20
19
    unless ( $searchmember ) {
21
    unless ( $searchmember ) {
20
        $searchmember = $dt_params->{sSearch} // '';
22
        $searchmember = $dt_params->{sSearch} // '';
Lines 55-100 sub search { Link Here
55
            };
57
            };
56
        }
58
        }
57
    }
59
    }
58
60
        my $select = "SELECT
59
    my $select = "SELECT
61
            borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
60
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
62
            borrowers.streetnumber, borrowers.streettype, borrowers.address,
61
        borrowers.streetnumber, borrowers.streettype, borrowers.address,
63
            borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
62
        borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
64
            borrowers.country, cardnumber, borrowers.dateexpiry,
63
        borrowers.country, cardnumber, borrowers.dateexpiry,
65
            borrowers.borrowernotes, borrowers.branchcode, borrowers.email,
64
        borrowers.borrowernotes, borrowers.branchcode, borrowers.email,
66
            borrowers.userid, borrowers.dateofbirth, borrowers.categorycode,
65
        borrowers.userid, borrowers.dateofbirth, borrowers.categorycode,
67
            categories.description AS category_description, categories.category_type,
66
        categories.description AS category_description, categories.category_type,
68
            branches.branchname";
67
        branches.branchname";
69
        my $from = "FROM borrowers
68
    my $from = "FROM borrowers
70
            LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
69
        LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
71
            LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
70
        LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
72
        my @where_args;
71
    my @where_args;
73
        my @where_strs;
72
    my @where_strs;
74
        if(defined $firstletter and $firstletter ne '') {
73
    if(defined $firstletter and $firstletter ne '') {
75
            push @where_strs, "borrowers.surname LIKE ?";
74
        push @where_strs, "borrowers.surname LIKE ?";
76
            push @where_args, "$firstletter%";
75
        push @where_args, "$firstletter%";
77
        }
76
    }
78
        if(defined $categorycode and $categorycode ne '') {
77
    if(defined $categorycode and $categorycode ne '') {
79
            push @where_strs, "borrowers.categorycode = ?";
78
        push @where_strs, "borrowers.categorycode = ?";
80
            push @where_args, $categorycode;
79
        push @where_args, $categorycode;
81
        }
80
    }
82
        if(@restricted_branchcodes ) {
81
    if(@restricted_branchcodes ) {
83
            push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
82
        push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
84
            push @where_args, @restricted_branchcodes;
83
        push @where_args, @restricted_branchcodes;
85
        }
84
    }
86
        my $searchfields = {
85
87
            standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid',
86
    my $searchfields = {
88
            surname => 'surname',
87
        standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid',
89
            email => 'email,emailpro,B_email',
88
        surname => 'surname',
90
            borrowernumber => 'borrowernumber',
89
        email => 'email,emailpro,B_email',
91
            userid => 'userid',
90
        borrowernumber => 'borrowernumber',
92
            phone => 'phone,phonepro,B_phone,altcontactphone,mobile',
91
        userid => 'userid',
93
            address => 'streettype,address,address2,city,state,zipcode,country',
92
        phone => 'phone,phonepro,B_phone,altcontactphone,mobile',
94
            dateofbirth => 'dateofbirth',
93
        address => 'streettype,address,address2,city,state,zipcode,country',
95
            sort1 => 'sort1',
94
        dateofbirth => 'dateofbirth',
96
            sort2 => 'sort2',
95
        sort1 => 'sort1',
97
        };
96
        sort2 => 'sort2',
97
    };
98
98
99
    # * is replaced with % for sql
99
    # * is replaced with % for sql
100
    $searchmember =~ s/\*/%/g;
100
    $searchmember =~ s/\*/%/g;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (-56 / +10 lines)
Lines 111-177 Link Here
111
        <input type="hidden" id="firstletter_filter" value="" />
111
        <input type="hidden" id="firstletter_filter" value="" />
112
        <fieldset class="brief">
112
        <fieldset class="brief">
113
          <h3>Filters</h3>
113
          <h3>Filters</h3>
114
          <p> Filter results by entering any value and all data values in the patron record(s) will be checked </p>
114
          <ol>
115
          <ol>
115
            <li>
116
            <li>
116
              <label for="searchmember_filter">Search:</label>
117
              <label for="searchmember_filter">Search:</label>
117
              <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
118
              <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
118
            </li>
119
            </li>
119
            <li>
120
            <li>
120
              <label for="searchfieldstype_filter">Search fields:</label>
121
              <select name="searchfieldstype" id="searchfieldstype_filter">
122
                [% IF searchfieldstype == "standard" %]
123
                  <option selected="selected" value='standard'>Standard</option>
124
                [% ELSE %]
125
                  <option value='standard'>Standard</option>
126
                [% END %]
127
                [% IF searchfieldstype == "surname" %]
128
                  <option selected="selected" value='surname'>Surname</option>
129
                [% ELSE %]
130
                  <option value='surname'>Surname</option>
131
                [% END %]
132
                [% IF searchfieldstype == "email" %]
133
                  <option selected="selected" value='email'>Email</option>
134
                [% ELSE %]
135
                  <option value='email'>Email</option>
136
                [% END %]
137
                [% IF searchfieldstype == "borrowernumber" %]
138
                  <option selected="selected" value='borrowernumber'>Borrower number</option>
139
                [% ELSE %]
140
                  <option value='borrowernumber'>Borrower number</option>
141
                [% END %]
142
                [% IF searchfieldstype == "userid" %]
143
                  <option selected="selected" value='userid'>Username</option>
144
                [% ELSE %]
145
                  <option value='userid'>Username</option>
146
                [% END %]
147
                [% IF searchfieldstype == "phone" %]
148
                  <option selected="selected" value='phone'>Phone number</option>
149
                [% ELSE %]
150
                  <option value='phone'>Phone number</option>
151
                [% END %]
152
                [% IF searchfieldstype == "address" %]
153
                  <option selected="selected" value='address'>Street address</option>
154
                [% ELSE %]
155
                  <option value='address'>Street address</option>
156
                [% END %]
157
                [% IF searchfieldstype == "dateofbirth" %]
158
                  <option selected="selected" value='dateofbirth'>Date of birth</option>
159
                [% ELSE %]
160
                  <option value='dateofbirth'>Date of birth</option>
161
                [% END %]
162
                [% IF searchfieldstype == "sort1" %]
163
                  <option selected="selected" value='sort1'>Sort field 1</option>
164
                [% ELSE %]
165
                  <option value='sort1'>Sort field 1</option>
166
                [% END %]
167
                [% IF searchfieldstype == "sort2" %]
168
                  <option selected="selected" value='sort2'>Sort field 2</option>
169
                [% ELSE %]
170
                  <option value='sort2'>Sort field 2</option>
171
                [% END %]
172
              </select>
173
            </li>
174
            <li>
175
              <label for="searchtype_filter">Search type:</label>
121
              <label for="searchtype_filter">Search type:</label>
176
              <select name="searchtype" id="searchtype_filter">
122
              <select name="searchtype" id="searchtype_filter">
177
                [% IF searchtype == "start_with" %]
123
                [% IF searchtype == "start_with" %]
Lines 324-335 Link Here
324
                e.preventDefault();
270
                e.preventDefault();
325
                clearFilters(true);
271
                clearFilters(true);
326
            });
272
            });
327
            $("#searchform").on("submit", filter);
273
            $("#searchform").on("submit", function(e) {
274
                e.preventDefault();
275
                search = 1;
276
                dtMemberResults.fnDraw();
277
            });
328
        });
278
        });
329
279
330
        var dtMemberResults;
280
        var dtMemberResults;
331
        var search = 1;
281
        var search = 1;
332
        $(document).ready(function() {
282
        $(document).ready(function() {
283
            var first_query = document.getElementById("searchmember").value; 
333
            [% IF searchmember %]
284
            [% IF searchmember %]
334
                $("#searchmember_filter").val("[% searchmember | html %]");
285
                $("#searchmember_filter").val("[% searchmember | html %]");
335
            [% END %]
286
            [% END %]
Lines 390-395 Link Here
390
                        return;
341
                        return;
391
                    }
342
                    }
392
                    aoData.push({
343
                    aoData.push({
344
                        'name': 'first_query',
345
                        'value': $("#searchmember").val()
346
                    },{
393
                        'name': 'searchmember',
347
                        'name': 'searchmember',
394
                        'value': $("#searchmember_filter").val()
348
                        'value': $("#searchmember_filter").val()
395
                    },{
349
                    },{
(-)a/svc/members/search (-29 / +71 lines)
Lines 26-31 use C4::Utils::DataTables qw( dt_get_params ); Link Here
26
use C4::Utils::DataTables::Members qw( search );
26
use C4::Utils::DataTables::Members qw( search );
27
use Koha::DateUtils qw( output_pref dt_from_string );
27
use Koha::DateUtils qw( output_pref dt_from_string );
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Data::Dumper;
29
30
30
my $input = new CGI;
31
my $input = new CGI;
31
32
Lines 39-44 my ($template, $user, $cookie) = get_template_and_user({ Link Here
39
    flagsrequired   => { borrowers => 'edit_borrowers' }
40
    flagsrequired   => { borrowers => 'edit_borrowers' }
40
});
41
});
41
42
43
my $first_query = $input->param('first_query');
42
my $searchmember = $input->param('searchmember');
44
my $searchmember = $input->param('searchmember');
43
my $firstletter  = $input->param('firstletter');
45
my $firstletter  = $input->param('firstletter');
44
my $categorycode = $input->param('categorycode');
46
my $categorycode = $input->param('categorycode');
Lines 56-61 foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) { Link Here
56
    $dt_params{$_} =~ s/^dt_//;
58
    $dt_params{$_} =~ s/^dt_//;
57
}
59
}
58
60
61
warn $searchfieldstype;
62
warn $searchtype;
63
59
my $results;
64
my $results;
60
# If the user filled a term, maybe it's a cardnumber.
65
# If the user filled a term, maybe it's a cardnumber.
61
# This cannot be the case if a first letter is given.
66
# This cannot be the case if a first letter is given.
Lines 72-113 if ( $searchmember Link Here
72
    } if $member;
77
    } if $member;
73
}
78
}
74
79
80
warn $first_query;
81
warn $searchmember;
82
warn $searchfieldstype;
83
warn $searchtype;
84
75
# Perform the patrons search
85
# Perform the patrons search
76
$results = C4::Utils::DataTables::Members::search(
86
$results = C4::Utils::DataTables::Members::search(
77
    {
87
  {
78
        searchmember => $searchmember,
88
     searchmember => $first_query,
79
        firstletter => $firstletter,
89
     firstletter => $firstletter,
80
        categorycode => $categorycode,
90
     categorycode => $categorycode,
81
        branchcode => $branchcode,
91
     branchcode => $branchcode,
82
        searchtype => $searchtype,
92
     searchtype => $searchtype,
83
        searchfieldstype => $searchfieldstype,
93
     searchfieldstype => $searchfieldstype,
84
        dt_params => \%dt_params,
94
     dt_params => \%dt_params,
85
    }
95
  }
86
) unless $results;
96
) unless $results;
87
97
88
# It is not recommanded to use the has_permission param if you use the pagination
98
    # It is not recommanded to use the has_permission param if you use the pagination
89
# The filter is done AFTER requested the data
99
    # The filter is done AFTER requested the data
90
if ($has_permission) {
100
    if ($has_permission) {
91
    my ( $permission, $subpermission ) = split /\./, $has_permission;
101
        my ( $permission, $subpermission ) = split /\./, $has_permission;
92
    my @patrons_with_permission;
102
        my @patrons_with_permission;
93
    for my $patron ( @{ $results->{patrons} } ) {
103
        for my $patron ( @{ $results->{patrons} } ) {
94
        my $perms = haspermission( $patron->{userid} );
104
            my $perms = haspermission( $patron->{userid} );
95
        if (   $perms->{superlibrarian} == 1
105
            if (   $perms->{superlibrarian} == 1
96
            or $perms->{$permission} == 1 )
106
                or $perms->{$permission} == 1 )
97
        {
107
            {
98
            push @patrons_with_permission, $patron;
108
                push @patrons_with_permission, $patron;
99
            next;
109
                next;
110
            }
111
112
            if ($subpermission) {
113
                my $subperms = get_user_subpermissions( $patron->{userid} );
114
                push @patrons_with_permission, $patron
115
                if $subperms->{$permission}->{$subpermission};
116
            }
100
        }
117
        }
118
        $results->{patrons} = \@patrons_with_permission;
119
        $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
120
    }
101
121
102
        if ($subpermission) {
122
    if ($searchmember) {
103
            my $subperms = get_user_subpermissions( $patron->{userid} );
123
        my @filtered_patron_list;
104
            push @patrons_with_permission, $patron
124
        my $count;
105
              if $subperms->{$permission}->{$subpermission};
125
        for my $patron ( @{ $results->{patrons} } ) {
126
            my $match;
127
            for my $value (values $patron) {
128
                my $lc_patron_value = lc $value;
129
                my $lc_searchmember = lc $searchmember;
130
    warn $lc_patron_value;
131
               warn $lc_searchmember;
132
                if ($searchtype eq "start_with") {
133
                    #Find a match starting with the start of a value in the patron record
134
                    warn "hello";
135
                    if (index($lc_patron_value, $lc_searchmember) == 0) {
136
                        warn $lc_patron_value;
137
                        warn $lc_searchmember;
138
                        $match = 1;
139
                    }
140
                } else { 
141
                    if (($lc_patron_value) =~ /($lc_searchmember)/) {
142
                        $match = 1;
143
                    }
144
                }
145
            }
146
            if ($match) {
147
                push @filtered_patron_list, $patron;
148
                next;
149
            }
106
        }
150
        }
151
        $results->{patrons} = \@filtered_patron_list;
152
        $results->{iTotalDisplayRecords} = scalar( @filtered_patron_list );
107
    }
153
    }
108
    $results->{patrons} = \@patrons_with_permission;
109
    $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
110
}
111
154
112
$template->param(
155
$template->param(
113
    sEcho => $sEcho,
156
    sEcho => $sEcho,
114
- 

Return to bug 20346