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

(-)a/C4/Members.pm (-9 / +98 lines)
Lines 32-38 use C4::Reserves; Link Here
32
use C4::Accounts;
32
use C4::Accounts;
33
use C4::Biblio;
33
use C4::Biblio;
34
use C4::Letters;
34
use C4::Letters;
35
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable);
36
use C4::Members::Attributes qw(SearchIdMatchingAttribute);
35
use C4::Members::Attributes qw(SearchIdMatchingAttribute);
37
use C4::NewsChannels; #get slip news
36
use C4::NewsChannels; #get slip news
38
use DateTime;
37
use DateTime;
Lines 197-202 sub _express_member_find { Link Here
197
    return (undef, $search_on_fields, $searchtype);
196
    return (undef, $search_on_fields, $searchtype);
198
}
197
}
199
198
199
sub _get_cond_for_dbix {
200
    my ($params) = @_;
201
    my $filters          = $params->{filters};
202
    my $exact_search     = $params->{exact_search};
203
    my $search_on_fields = $params->{search_on_fields};
204
205
    my $cond;
206
    if( ref($filters) eq 'ARRAY' ) {
207
        $cond = [];
208
        foreach my $filter (@$filters) {
209
            push @$cond, _get_cond_for_dbix({
210
                filters          => $filter,
211
                exact_search     => $exact_search,
212
                search_on_fields => $search_on_fields,
213
            });
214
        };
215
    }
216
    elsif( ref($filters) eq 'HASH' ) {
217
        $cond = { %$filters };
218
        $cond->{'-or'} = _get_columns_cond({
219
            string           => $filters->{''},
220
            search_on_fields => $search_on_fields,
221
            exact_search     => $exact_search,
222
        }) if( exists( $filters->{''} ) );
223
        delete $cond->{''};
224
    }
225
    elsif( not ref($filters) ) {
226
        $cond = _get_columns_cond({
227
            string           => $filters,
228
            search_on_fields => $search_on_fields,
229
            exact_search     => $exact_search,
230
        });
231
    }
232
    return $cond;
233
}
234
235
sub _get_columns_cond {
236
    my ($params) = @_;
237
    my $string           = $params->{string};
238
    my $exact_search     = $params->{exact_search} // 1;
239
    my $search_on_fields = $params->{search_on_fields} || undef;
240
241
    my $source  = Koha::Database->new()->schema->source('Borrower');
242
    my @columns = $search_on_fields ? @$search_on_fields : $source->columns;
243
244
    my $cond = [];
245
    foreach my $column (@columns) {
246
        if( $exact_search ) {
247
            push @$cond, { $column => [ map { $_ } split(' ', $string) ] };
248
        }
249
        else {
250
            push @$cond, { $column => { like => [ map { $_.'%' } split(' ', $string) ] } };
251
        }
252
    }
253
    return $cond;
254
}
255
200
sub Search {
256
sub Search {
201
    my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_;
257
    my ( $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype ) = @_;
202
258
Lines 283-289 sub Search { Link Here
283
    }
339
    }
284
    $searchtype ||= "start_with";
340
    $searchtype ||= "start_with";
285
341
286
    return SearchInTable( "borrowers", $filter, $orderby, $limit, $columns_out, $search_on_fields, $searchtype );
342
    my $cond = _get_cond_for_dbix({
343
        filters          => $filter,
344
        exact_search     => ($searchtype eq 'exact') ? 1 : 0,
345
        search_on_fields => $search_on_fields,
346
    });
347
348
    my $rs = Koha::Database->new()->schema->resultset('Borrower');
349
    $rs = $rs->search(
350
        $cond,
351
        {
352
            ($columns_out) ? { columns  => $columns_out } : {},
353
            order_by => $orderby,
354
            rows     => $limit,
355
        },
356
    );
357
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
358
    return [ $rs->all ];
287
}
359
}
288
360
289
=head2 GetMemberDetails
361
=head2 GetMemberDetails
Lines 787-794 sub ModMember { Link Here
787
        }
859
        }
788
    }
860
    }
789
    my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
861
    my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
790
    my $execute_success=UpdateInTable("borrowers",\%data);
862
791
    if ($execute_success) { # only proceed if the update was a success
863
    # get only the columns of a borrower
864
    my $schema = Koha::Database->new()->schema;
865
    my @columns = $schema->source('Borrower')->columns;
866
    my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) };
867
    delete $new_borrower->{flags};
868
869
    my $rs = $schema->resultset('Borrower')->search({
870
        borrowernumber => $new_borrower->{borrowernumber},
871
     });
872
    my $execute_success = $rs->update($new_borrower);
873
    if ($execute_success ne '0E0') { # only proceed if the update was a success
792
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
874
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
793
        # so when we update information for an adult we should check for guarantees and update the relevant part
875
        # so when we update information for an adult we should check for guarantees and update the relevant part
794
        # of their records, ie addresses and phone numbers
876
        # of their records, ie addresses and phone numbers
Lines 823-828 Returns as undef upon any db error without further processing Link Here
823
sub AddMember {
905
sub AddMember {
824
    my (%data) = @_;
906
    my (%data) = @_;
825
    my $dbh = C4::Context->dbh;
907
    my $dbh = C4::Context->dbh;
908
    my $schema = Koha::Database->new()->schema;
826
909
827
    # generate a proper login if none provided
910
    # generate a proper login if none provided
828
    $data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq '';
911
    $data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq '';
Lines 837-845 sub AddMember { Link Here
837
        $data{'dateenrolled'} = C4::Dates->new()->output("iso");
920
        $data{'dateenrolled'} = C4::Dates->new()->output("iso");
838
    }
921
    }
839
922
840
    my $patron_category =
923
    my $patron_category = $schema->resultset('Category')->find( $data{'categorycode'} );
841
      Koha::Database->new()->schema()->resultset('Category')
842
      ->find( $data{'categorycode'} );
843
    $data{'privacy'} =
924
    $data{'privacy'} =
844
        $patron_category->default_privacy() eq 'default' ? 1
925
        $patron_category->default_privacy() eq 'default' ? 1
845
      : $patron_category->default_privacy() eq 'never'   ? 2
926
      : $patron_category->default_privacy() eq 'never'   ? 2
Lines 848-861 sub AddMember { Link Here
848
929
849
    # create a disabled account if no password provided
930
    # create a disabled account if no password provided
850
    $data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!';
931
    $data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!';
851
    $data{'borrowernumber'}=InsertInTable("borrowers",\%data);
932
    $data{'dateofbirth'} = undef if( not $data{'dateofbirth'} );
933
934
    # get only the columns of Borrower
935
    my @columns = $schema->source('Borrower')->columns;
936
    my $new_member = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $data{$_} )  : () } keys(%data) } ;
937
    delete $new_member->{borrowernumber};
938
939
    my $rs = $schema->resultset('Borrower');
940
    $data{borrowernumber} = $rs->create($new_member)->id;
852
941
853
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
942
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
854
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
943
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
855
944
856
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
945
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
857
946
858
    return $data{'borrowernumber'};
947
    return $data{borrowernumber};
859
}
948
}
860
949
861
=head2 Check_Userid
950
=head2 Check_Userid
(-)a/members/guarantor_search.pl (-1 / +6 lines)
Lines 47-52 my $orderby = $input->param('orderby'); Link Here
47
my $category_type = $input->param('category_type');
47
my $category_type = $input->param('category_type');
48
48
49
$orderby = "surname,firstname" unless $orderby;
49
$orderby = "surname,firstname" unless $orderby;
50
my $orderby_array = [ split(',', $orderby) ];
50
$member =~ s/,//g;     #remove any commas from search string
51
$member =~ s/,//g;     #remove any commas from search string
51
$member =~ s/\*/%/g;
52
$member =~ s/\*/%/g;
52
53
Lines 61-68 my ( $count, $results ); Link Here
61
my @resultsdata;
62
my @resultsdata;
62
63
63
if ( $member ne '' ) {
64
if ( $member ne '' ) {
65
    my $rs = Koha::Database->new()->schema->resultset('Category')->search({ category_type => $search_category }, { columns => ['categorycode'] } );
66
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
67
    my $categorycodes = [ map { $_->{categorycode}  } $rs->all ];
68
64
    $results =
69
    $results =
65
      Search( { '' => $member, category_type => $search_category }, $orderby );
70
      Search( { '' => $member, categorycode => $categorycodes }, $orderby_array );
66
71
67
    $count = $results ? @$results : 0;
72
    $count = $results ? @$results : 0;
68
73
(-)a/patroncards/members-search.pl (-4 / +4 lines)
Lines 17-24 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use CGI;
22
use CGI;
24
23
Lines 68-79 if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){ Link Here
68
}
67
}
69
68
70
$orderby = "surname,firstname" unless $orderby;
69
$orderby = "surname,firstname" unless $orderby;
70
my $orderby_array = [ split(',', $orderby)  ];
71
$member =~ s/,//g;   #remove any commas from search string
71
$member =~ s/,//g;   #remove any commas from search string
72
$member =~ s/\*/%/g;
72
$member =~ s/\*/%/g;
73
73
74
if ($member || $category) {
74
if ($member || $category) {
75
    my $results = $category ? Search({''=>$member, categorycode=>$category}, $orderby)
75
    my $results = $category ? Search({''=>$member, categorycode=>$category}, $orderby_array)
76
                            : Search($member, $orderby);
76
                            : Search($member, $orderby_array);
77
    my $count = $results ? @$results : 0;
77
    my $count = $results ? @$results : 0;
78
78
79
    my @resultsdata = ();
79
    my @resultsdata = ();
(-)a/serials/member-search.pl (-19 / +14 lines)
Lines 90-116 if ( C4::Context->preference("IndependentBranches") ) { Link Here
90
        $$patron{branchcode} = C4::Context->userenv->{'branch'};
90
        $$patron{branchcode} = C4::Context->userenv->{'branch'};
91
    }
91
    }
92
}
92
}
93
$$patron{firstname}.="\%" if ($$patron{firstname});
94
$$patron{surname}.="\%" if ($$patron{surname});
95
93
96
my @searchpatron;
94
my $searchpatron = {};
97
push @searchpatron, $member if ($member);
95
$searchpatron->{''} = $member if( $member );
98
push @searchpatron, $patron if ( keys %$patron );
96
$searchpatron->{branchcode}   = $patron->{branchcode}   if( defined $patron->{branchcode} );
97
$searchpatron->{categorycode} = $patron->{categorycode} if( defined $patron->{categorycode} );
98
$results = Search(
99
    $searchpatron,
100
    [ { -asc => 'surname' }, { -asc => 'firstname' } ],
101
    undef,
102
    undef,
103
    [ "firstname", "surname", "email", "othernames", "cardnumber" ],
104
    "start_with"
105
);
106
$count = scalar(@$results);
99
my $from = ( $startfrom - 1 ) * $resultsperpage;
107
my $from = ( $startfrom - 1 ) * $resultsperpage;
100
my $to   = $from + $resultsperpage;
108
my $to   = $from + $resultsperpage;
101
if (@searchpatron) {
109
102
    ($results) = Search(
103
        \@searchpatron,
104
        [ { surname => 0 }, { firstname => 0 } ],
105
        undef,
106
        undef,
107
        [ "firstname", "surname", "email", "othernames", "cardnumber" ],
108
        "start_with"
109
    );
110
}
111
if ($results) {
112
    $count = scalar(@$results);
113
}
114
my @resultsdata;
110
my @resultsdata;
115
$to=($count>$to?$to:$count);
111
$to=($count>$to?$to:$count);
116
my $index=$from;
112
my $index=$from;
117
- 

Return to bug 12633