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 (-57 / +24 lines)
Lines 109-175 Link Here
109
    <div class="yui-b">
109
    <div class="yui-b">
110
      <form method="get" id="searchform">
110
      <form method="get" id="searchform">
111
        <input type="hidden" id="firstletter_filter" value="" />
111
        <input type="hidden" id="firstletter_filter" value="" />
112
        <input type="hidden" id="date_format" value="[% dateformat%]"/>
112
        <fieldset class="brief">
113
        <fieldset class="brief">
113
          <h3>Filters</h3>
114
          <h3>Filters</h3>
115
          <p> Filter results by entering any value and all data values in the patron record(s) will be checked </p>
114
          <ol>
116
          <ol>
115
            <li>
117
            <li>
116
              <label for="searchmember_filter">Search:</label>
118
              <label for="searchmember_filter">Search:</label>
117
              <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
119
              <input type="text" id="searchmember_filter" onmouseover="tooltip_display()" value="[% searchmember %]"/>
118
            </li>
119
            <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>
120
            </li>
174
            <li>
121
            <li>
175
              <label for="searchtype_filter">Search type:</label>
122
              <label for="searchtype_filter">Search type:</label>
Lines 324-335 Link Here
324
                e.preventDefault();
271
                e.preventDefault();
325
                clearFilters(true);
272
                clearFilters(true);
326
            });
273
            });
327
            $("#searchform").on("submit", filter);
274
            $("#searchform").on("submit", function(e) {
275
                e.preventDefault();
276
                search = 1;
277
                dtMemberResults.fnDraw();
278
            });
328
        });
279
        });
329
280
330
        var dtMemberResults;
281
        var dtMemberResults;
331
        var search = 1;
282
        var search = 1;
332
        $(document).ready(function() {
283
        $(document).ready(function() {
284
            var first_query = document.getElementById("searchmember").value; 
333
            [% IF searchmember %]
285
            [% IF searchmember %]
334
                $("#searchmember_filter").val("[% searchmember | html %]");
286
                $("#searchmember_filter").val("[% searchmember | html %]");
335
            [% END %]
287
            [% END %]
Lines 390-395 Link Here
390
                        return;
342
                        return;
391
                    }
343
                    }
392
                    aoData.push({
344
                    aoData.push({
345
                        'name': 'first_query',
346
                        'value': $("#searchmember").val()
347
                    },{
393
                        'name': 'searchmember',
348
                        'name': 'searchmember',
394
                        'value': $("#searchmember_filter").val()
349
                        'value': $("#searchmember_filter").val()
395
                    },{
350
                    },{
Lines 475-480 Link Here
475
            update_searched();
430
            update_searched();
476
        });
431
        });
477
432
433
        function tooltip_display() {
434
                var dateformat= document.getElementById("date_format").value;
435
                if ( dateformat == 'us') {
436
                    $('#searchmember_filter').attr("title","Please enter date inputs in the format mm/dd/yyyy").tooltip('show');
437
                } else if ( dateformat  == "metric") {
438
                    $('#searchmember_filter').attr("title","Please enter date inputs in the format dd/mm/yyyy").tooltip('show');
439
                } else if ( dateformat  == "iso") {
440
                    $('#searchmember_filter').attr("title","Please enter date inputs in the format yyyy-mm-dd").tooltip('show');
441
                } else if ( dateformat == "dmydot") {
442
                    $('#searchmember_filter').attr("title","Please enter date inputs in the format dd.mm.yyyy").tooltip('show');
443
                }
444
        }
478
        // Update the string "Results found ..."
445
        // Update the string "Results found ..."
479
        function update_searched(){
446
        function update_searched(){
480
            var searched = $("#searchfieldstype_filter").find("option:selected").text();
447
            var searched = $("#searchfieldstype_filter").find("option:selected").text();
(-)a/svc/members/search (-30 / +88 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;
30
use Time::Piece;
31
use JSON::XS qw( );
32
use HTML::Entities qw( encode_entities );
29
33
30
my $input = new CGI;
34
my $input = new CGI;
31
35
Lines 39-44 my ($template, $user, $cookie) = get_template_and_user({ Link Here
39
    flagsrequired   => { borrowers => 'edit_borrowers' }
43
    flagsrequired   => { borrowers => 'edit_borrowers' }
40
});
44
});
41
45
46
my $first_query = $input->param('first_query');
42
my $searchmember = $input->param('searchmember');
47
my $searchmember = $input->param('searchmember');
43
my $firstletter  = $input->param('firstletter');
48
my $firstletter  = $input->param('firstletter');
44
my $categorycode = $input->param('categorycode');
49
my $categorycode = $input->param('categorycode');
Lines 74-115 if ( $searchmember Link Here
74
79
75
# Perform the patrons search
80
# Perform the patrons search
76
$results = C4::Utils::DataTables::Members::search(
81
$results = C4::Utils::DataTables::Members::search(
77
    {
82
  {
78
        searchmember => $searchmember,
83
     searchmember => $first_query,
79
        firstletter => $firstletter,
84
     firstletter => $firstletter,
80
        categorycode => $categorycode,
85
     categorycode => $categorycode,
81
        branchcode => $branchcode,
86
     branchcode => $branchcode,
82
        searchtype => $searchtype,
87
     searchtype => $searchtype,
83
        searchfieldstype => $searchfieldstype,
88
     searchfieldstype => $searchfieldstype,
84
        dt_params => \%dt_params,
89
     dt_params => \%dt_params,
85
    }
90
  }
86
) unless $results;
91
) unless $results;
87
92
88
# It is not recommanded to use the has_permission param if you use the pagination
93
    # It is not recommanded to use the has_permission param if you use the pagination
89
# The filter is done AFTER requested the data
94
    # The filter is done AFTER requested the data
90
if ($has_permission) {
95
    if ($has_permission) {
91
    my ( $permission, $subpermission ) = split /\./, $has_permission;
96
        my ( $permission, $subpermission ) = split /\./, $has_permission;
92
    my @patrons_with_permission;
97
        my @patrons_with_permission;
93
    for my $patron ( @{ $results->{patrons} } ) {
98
        for my $patron ( @{ $results->{patrons} } ) {
94
        my $perms = haspermission( $patron->{userid} );
99
            my $perms = haspermission( $patron->{userid} );
95
        if (   $perms->{superlibrarian} == 1
100
            if (   $perms->{superlibrarian} == 1
96
            or $perms->{$permission} == 1 )
101
                or $perms->{$permission} == 1 )
97
        {
102
            {
98
            push @patrons_with_permission, $patron;
103
                push @patrons_with_permission, $patron;
99
            next;
104
                next;
105
            }
106
107
            if ($subpermission) {
108
                my $subperms = get_user_subpermissions( $patron->{userid} );
109
                push @patrons_with_permission, $patron
110
                if $subperms->{$permission}->{$subpermission};
111
            }
100
        }
112
        }
101
113
        $results->{patrons} = \@patrons_with_permission;
102
        if ($subpermission) {
114
        $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
103
            my $subperms = get_user_subpermissions( $patron->{userid} );
115
    }
104
            push @patrons_with_permission, $patron
116
    my $date_format = C4::Context->preference("dateformat");
105
              if $subperms->{$permission}->{$subpermission};
117
118
    if ($searchmember) {
119
        my @filtered_patron_list;
120
        my $count;
121
        for my $patron ( @{ $results->{patrons} } ) {
122
            my $match;
123
            for my $value (values $patron) {
124
                warn $value;
125
                my $lc_patron_value = lc $value;
126
                my $lc_searchmember = lc $searchmember;
127
128
                #Reformat the date value
129
                if ($lc_patron_value =~ /^\d{4}-\d\d-\d\d$/) {
130
                    if ($date_format eq "us" ) {
131
                       $lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%m/%d/%Y');
132
                    } elsif ($date_format eq "metric" ) {
133
                         $lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%d/%m/%Y');
134
                    } elsif ($date_format eq "iso" ) {
135
                         $lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%Y-%m-%d');
136
                    } elsif ($date_format eq "dmydot" ) {
137
                         $lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%d.%m.%Y');
138
139
                    }
140
                }
141
                warn $lc_patron_value;
142
                warn $lc_searchmember;
143
                if ($searchtype eq "start_with") {
144
                    #Find a match starting with the start of a value in the patron record
145
                    if (index($lc_patron_value, $lc_searchmember) == 0) {
146
                        $match = 1;
147
                        warn $lc_patron_value;
148
                        warn $lc_searchmember;
149
                    }
150
                } else {
151
                    if (($lc_patron_value) =~ /($lc_searchmember)/) {
152
                        $match = 1;
153
                    }
154
                }
155
            }
156
            if ($match) {
157
                push @filtered_patron_list, $patron;
158
                next;
159
            }
106
        }
160
        }
161
        $results->{patrons} = \@filtered_patron_list;
162
        $results->{iTotalDisplayRecords} = scalar( @filtered_patron_list );
107
    }
163
    }
108
    $results->{patrons} = \@patrons_with_permission;
164
109
    $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
165
    my $date_format = C4::Context->preference("dateformat");
110
}
166
    my $json = JSON::XS->new->allow_nonref;
167
    my $date_format = $json->encode($date_format);
168
    my $date_format = encode_entities($date_format);
111
169
112
$template->param(
170
$template->param(
171
    dateformat => $date_format,
113
    sEcho => $sEcho,
172
    sEcho => $sEcho,
114
    iTotalRecords => $results->{iTotalRecords},
173
    iTotalRecords => $results->{iTotalRecords},
115
    iTotalDisplayRecords => $results->{iTotalDisplayRecords},
174
    iTotalDisplayRecords => $results->{iTotalDisplayRecords},
116
- 

Return to bug 20346