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

(-)a/C4/Members.pm (-2 / +69 lines)
Lines 124-129 BEGIN { Link Here
124
        &fixup_cardnumber
124
        &fixup_cardnumber
125
        &checkcardnumber
125
        &checkcardnumber
126
    );
126
    );
127
128
    push @EXPORT_OK, qw(
129
        FindByPartialName
130
    );
127
}
131
}
128
132
129
=head1 NAME
133
=head1 NAME
Lines 285-294 C<&search_on_fields> is an array ref to the fieldnames you want to limit search Link Here
285
289
286
C<&searchtype> is a string telling the type of search you want todo : start_with, exact or contains are allowed
290
C<&searchtype> is a string telling the type of search you want todo : start_with, exact or contains are allowed
287
291
292
C<skipExtendedAttributes> is a boolean that tells us to avoid searching the
293
extended attributes even if we otherwise would.
294
288
=cut
295
=cut
289
296
290
sub Search {
297
sub Search {
291
    my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_;
298
    my ( $filter, $orderby, $limit, $columns_out, $search_on_fields,
299
        $searchtype, $skipExtendedAttributes ) = @_;
292
    my @filters;
300
    my @filters;
293
    my %filtersmatching_record;
301
    my %filtersmatching_record;
294
    my @finalfilter;
302
    my @finalfilter;
Lines 297-303 sub Search { Link Here
297
    } else {
305
    } else {
298
        push @filters, $filter;
306
        push @filters, $filter;
299
    }
307
    }
300
    if ( C4::Context->preference('ExtendedPatronAttributes') ) {
308
    if (!$skipExtendedAttributes &&
309
    	C4::Context->preference('ExtendedPatronAttributes') ) {
301
        my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
310
        my $matching_records = C4::Members::Attributes::SearchIdMatchingAttribute($filter);
302
        if(scalar(@$matching_records)>0) {
311
        if(scalar(@$matching_records)>0) {
303
			foreach my $matching_record (@$matching_records) {
312
			foreach my $matching_record (@$matching_records) {
Lines 314-319 sub Search { Link Here
314
    return ($data);
323
    return ($data);
315
}
324
}
316
325
326
=head2 FindByPartialName
327
328
  @result = FindByPartialName('string', categorycode => 'C', branchcode => 'L' );
329
330
This is a simplified version of the "Search" function above. It compares what
331
has been entered against the surname, firstname, othernames, and email as 
332
a prefix, a literal match against the barcode, and allows filtering by the
333
user's library and category.
334
335
=head3 RETURNS
336
337
An array of hashrefs that contain the values from the borrowers table of things
338
that match.
339
340
=head3 NOTES
341
342
Supplying all fields as blank or C<undef> will return all users. Searches that
343
have no result will end up in an empty list. If you get undef, there was
344
an error of some sort.
345
346
=cut
347
348
sub FindByPartialName {
349
    my ($prefix, %options) = @_;
350
351
    my $qry_start = 'SELECT * FROM borrowers';
352
    my ($qry_end, @params);
353
    if ($prefix) {
354
    	$qry_end .= <<EOH;
355
(surname LIKE ? OR
356
firstname LIKE ? OR
357
othernames  LIKE ? OR
358
email LIKE ? OR
359
cardnumber=?)
360
EOH
361
        push @params, ("$prefix%","$prefix%","$prefix%","$prefix%", $prefix);
362
    }
363
    foreach my $field ("categorycode", "branchcode") {
364
    	next if !$options{$field};
365
    	my $val = $options{$field};
366
        my $q = "($field=?)";
367
        push @params, $val;
368
        $qry_end .= ($qry_end ? " AND $q" : $q) . "\n";
369
    }
370
    my $qry_sort = " ORDER BY surname,firstname DESC";
371
    my $query = "$qry_start " . ($qry_end ? "WHERE $qry_end" : '') . " $qry_sort";
372
373
    my $dbh = C4::Context->dbh;
374
    my $sth = $dbh->prepare($query);
375
    eval { $sth->execute(@params) };
376
	if ($@) {
377
    	warn $@;
378
    	return undef;
379
    }
380
    my $result = $sth->fetchall_arrayref( {} );
381
    return @$result;
382
}
383
317
=head2 GetMemberDetails
384
=head2 GetMemberDetails
318
385
319
($borrower) = &GetMemberDetails($borrowernumber, $cardnumber);
386
($borrower) = &GetMemberDetails($borrowernumber, $cardnumber);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/member-search.tt (-4 / +3 lines)
Lines 24-33 function add_member(subscriptionid,borrowernumber){ Link Here
24
	<form action="[% actionname %]" method="get">
24
	<form action="[% actionname %]" method="get">
25
            <input type="hidden" name="subscriptionid" id="subscriptionid" value="[% subscriptionid %]" />
25
            <input type="hidden" name="subscriptionid" id="subscriptionid" value="[% subscriptionid %]" />
26
		<fieldset class="rows">
26
		<fieldset class="rows">
27
			<legend> Filter :</legend>
27
			<legend> Filter:</legend>
28
			<ol>
28
			<ol>
29
			<li><label for="member">Name:</label> <input type="hidden" name="surname" value="[% surname %]" />
29
			<li><label for="member">Name:</label><input type="text" name="member" id="member" value="[% member %]" /></li>
30
			<input type="text" name="member" id="member" value="[% member %]" /></li>
31
			<li><label for="branchcode"> Library :</label><select name="branchcode" id="branchcode">
30
			<li><label for="branchcode"> Library :</label><select name="branchcode" id="branchcode">
32
			<option value="">Any</option>[% FOREACH branchloo IN branchloop %]
31
			<option value="">Any</option>[% FOREACH branchloo IN branchloop %]
33
			[% IF ( branchloo.selected ) %]
32
			[% IF ( branchloo.selected ) %]
Lines 46-52 function add_member(subscriptionid,borrowernumber){ Link Here
46
	  </form>
45
	  </form>
47
</div> 
46
</div> 
48
[% IF ( resultsloop ) %]
47
[% IF ( resultsloop ) %]
49
<div id="searchheader" style="margin-top:.7em;"> <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></div>
48
<div id="searchheader" style="margin-top:.7em;"> <h3>Results [% from %] to [% to %] of [% numresults %] found [% IF ( member ) %]for '<span class="ex">[% member %]</span>'[% END %]</h3></div>
50
<div class="searchresults">
49
<div class="searchresults">
51
50
52
<table id="memberresultst">
51
<table id="memberresultst">
(-)a/serials/member-search.pl (-65 / +47 lines)
Lines 28-34 use warnings; Link Here
28
use CGI;
28
use CGI;
29
use C4::Auth;       # get_template_and_user
29
use C4::Auth;       # get_template_and_user
30
use C4::Output;
30
use C4::Output;
31
use C4::Members;    # BornameSearch
31
use C4::Members qw/ FindByPartialName /;
32
use C4::Branch;
32
use C4::Branch;
33
use C4::Category;
33
use C4::Category;
34
use File::Basename;
34
use File::Basename;
Lines 38-56 my $theme = $cgi->param('theme') || "default"; Link Here
38
my $resultsperpage = $cgi->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
38
my $resultsperpage = $cgi->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
39
my $startfrom = $cgi->param('startfrom')||1;
39
my $startfrom = $cgi->param('startfrom')||1;
40
40
41
my $patron = $cgi->Vars;
41
my $member=$cgi->param('member');
42
foreach (keys %$patron){
42
my $branchcode = $cgi->param('branchcode');
43
    delete $$patron{$_} unless($$patron{$_});
43
my $categorycode = $cgi->param('categorycode');
44
}
45
44
46
my @categories=C4::Category->all;
45
my @categories=C4::Category->all;
47
my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
46
my @branches=@{ GetBranchesLoop(
48
my $subscriptionid = $cgi->param('subscriptionid');
47
    $branchcode || undef
49
my $searchstring   = $cgi->param('member');
48
) };
50
49
51
my %categories_dislay;
50
my %categories_display;
52
my ($template, $loggedinuser, $cookie);
51
my ($template, $loggedinuser, $cookie)
53
    ($template, $loggedinuser, $cookie)
54
    = get_template_and_user({template_name => "serials/member-search.tmpl",
52
    = get_template_and_user({template_name => "serials/member-search.tmpl",
55
                 query => $cgi,
53
                 query => $cgi,
56
                 type => "intranet",
54
                 type => "intranet",
Lines 63-146 foreach my $category (@categories){ Link Here
63
			category_description=>$$category{description},
61
			category_description=>$$category{description},
64
			category_type=>$$category{category_type}
62
			category_type=>$$category{category_type}
65
			 };
63
			 };
66
	$categories_dislay{$$category{categorycode}} = $hash;
64
	$categories_display{$$category{categorycode}} = $hash;
67
}
65
}
68
$template->param(
69
        "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
70
            );
71
if (C4::Context->preference("AddPatronLists")=~/code/){
66
if (C4::Context->preference("AddPatronLists")=~/code/){
72
    $categories[0]->{'first'}=1;
67
    $categories[0]->{'first'}=1;
73
}
68
}
74
69
75
my $member=$cgi->param('member');
76
my $orderby=$cgi->param('orderby');
77
$orderby = "surname,firstname" unless $orderby;
78
if (defined $member) {
79
    $member =~ s/,//g;   #remove any commas from search string
80
    $member =~ s/\*/%/g;
81
}
82
70
83
my ($count,$results);
71
my ($count,@results) = (0);
72
73
my $shouldsearch = $branchcode || $categorycode || $member;
84
74
85
if (C4::Context->preference("IndependantBranches")){
75
if (C4::Context->preference("IndependantBranches")){
86
   if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
76
   if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
87
        $$patron{branchcode}=C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
77
        $branchcode = C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
88
   }
78
   }
89
}
79
}
90
$$patron{firstname}.="\%" if ($$patron{firstname});
91
$$patron{surname}.="\%" if ($$patron{surname});
92
80
93
my @searchpatron;
81
94
push @searchpatron, $member if ($member);
95
push @searchpatron, $patron if ( keys %$patron );
96
my $from = ( $startfrom - 1 ) * $resultsperpage;
82
my $from = ( $startfrom - 1 ) * $resultsperpage;
97
my $to   = $from + $resultsperpage;
83
my $to   = $from + $resultsperpage;
98
if (@searchpatron) {
84
if ($shouldsearch) {
99
    ($results) = Search(
85
    @results = FindByPartialName(
100
        \@searchpatron,
86
        $member,
101
        [ { surname => 0 }, { firstname => 0 } ],
87
        categorycode    => $categorycode,
102
        undef,
88
        branchcode      => $branchcode,
103
        undef,
104
        [ "firstname", "surname", "email", "othernames", "cardnumber" ],
105
        "start_with"
106
    );
89
    );
107
}
90
}
108
if ($results) {
91
if (@results) {
109
    $count = scalar(@$results);
92
    $count = @results;
110
}
93
}
111
my @resultsdata;
94
my @resultsdata;
112
$to=($count>$to?$to:$count);
95
$to=($count>$to?$to:$count);
113
my $index=$from;
96
my $index=$from;
114
foreach my $borrower(@$results[$from..$to-1]){
97
foreach my $borrower (@results[$from..$to-1]){
115
    # find out stats
98
    # find out stats
116
    $borrower->{'dateexpiry'}= C4::Dates->new($borrower->{'dateexpiry'},'iso')->output('syspref');
99
    if ($categories_display{$borrower->{'categorycode'}}){
117
    if ($categories_dislay{$borrower->{'categorycode'}}){
118
        my %row = (
100
        my %row = (
119
	    count => $index++,
101
            count => $index++,
120
	    %$borrower,
102
            %$borrower,
121
	    %{$categories_dislay{$$borrower{categorycode}}},
103
            %{$categories_display{$$borrower{categorycode}}},
122
	);
104
        );
123
	push(@resultsdata, \%row);
105
        push(@resultsdata, \%row);
124
    }
106
    } else {
125
    else {
107
        warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
126
	 warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
127
    }
108
    }
128
}
109
}
129
if ($$patron{branchcode}){
110
if ($branchcode){
130
	foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
111
	foreach my $branch (grep {$_->{value} eq $branchcode} @branches){
131
		$$branch{selected}=1;
112
		$$branch{selected}=1;
132
	}
113
	}
133
}
114
}
134
if ($$patron{categorycode}){
115
if ($categorycode){
135
	foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
116
	foreach my $category (grep {$_->{categorycode} eq $categorycode} @categories){
136
		$$category{selected}=1;
117
		$$category{selected}=1;
137
	}
118
	}
138
}
119
}
139
my %parameters=
120
my %parameters=(
140
(  %{$patron},
121
    member          => $member,
141
    'orderby' => $orderby,
122
    categorycode    => $categorycode,
142
    'resultsperpage' => $resultsperpage,
123
    branchcode      => $branchcode,
143
    'type'=> 'intranet');
124
    resultsperpage  => $resultsperpage,
125
    type            => 'intranet'
126
);
144
my $base_url =
127
my $base_url =
145
    'member-search.pl?&amp;'
128
    'member-search.pl?&amp;'
146
  . join(
129
  . join(
Lines 158-175 $template->param( Link Here
158
    to        => $to,
141
    to        => $to,
159
    multipage => ($count != $to+1 || $startfrom!=1),
142
    multipage => ($count != $to+1 || $startfrom!=1),
160
);
143
);
144
161
$template->param(
145
$template->param(
162
    branchloop=>$branches,
146
    branchloop=>\@branches,
163
	categoryloop=>\@categories,
147
	categoryloop=>\@categories,
164
);
148
);
165
149
166
167
$template->param(
150
$template->param(
168
        searching       => "1",
151
        searching       => $shouldsearch,
169
		actionname		=> basename($0),
152
		actionname		=> basename($0),
170
		%$patron,
153
		%parameters,
171
        numresults      => $count,
154
        numresults      => $count,
172
        resultsloop     => \@resultsdata,
155
        resultsloop     => \@resultsdata,
173
            );
156
);
174
157
175
output_html_with_http_headers $cgi, $cookie, $template->output;
158
output_html_with_http_headers $cgi, $cookie, $template->output;
176
- 

Return to bug 6513