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

(-)a/C4/Utils/DataTables/Members.pm (-7 / +36 lines)
Lines 13-18 sub search { Link Here
13
    my $branchcode = $params->{branchcode};
13
    my $branchcode = $params->{branchcode};
14
    my $searchtype = $params->{searchtype} || 'contain';
14
    my $searchtype = $params->{searchtype} || 'contain';
15
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
15
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
16
    my $has_permission = $params->{has_permission};
16
    my $dt_params = $params->{dt_params};
17
    my $dt_params = $params->{dt_params};
17
18
18
    unless ( $searchmember ) {
19
    unless ( $searchmember ) {
Lines 27-38 sub search { Link Here
27
28
28
    my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords);
29
    my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords);
29
    my $dbh = C4::Context->dbh;
30
    my $dbh = C4::Context->dbh;
31
32
    # Get the module_bit from a given permission code
33
    if ( $has_permission ) {
34
        ($has_permission->{module_bit}) = $dbh->selectrow_array(q|
35
            SELECT bit FROM userflags WHERE flag=?
36
        |, undef, $has_permission->{permission});
37
    }
38
30
    # Get the iTotalRecords DataTable variable
39
    # Get the iTotalRecords DataTable variable
31
    $query = $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
40
    $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
41
    if ( $has_permission ) {
42
        $iTotalQuery .= ' LEFT JOIN user_permissions on borrowers.borrowernumber=user_permissions.borrowernumber';
43
    }
44
45
    my (@where, @conditions);
32
    if ( @restricted_branchcodes ) {
46
    if ( @restricted_branchcodes ) {
33
        $iTotalQuery .= " WHERE borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
47
        push @where, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
48
        push @conditions, @restricted_branchcodes;
34
    }
49
    }
35
    ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @restricted_branchcodes );
50
    if ( $has_permission ) {
51
        push @where, 'borrowers.flags = 1 OR borrowers.flags & (1 << ?) OR module_bit=? AND code=?';
52
        push @conditions, ($has_permission->{module_bit}) x 2, $has_permission->{subpermission};
53
    }
54
    $iTotalQuery .= ' WHERE ' . join ' AND ', @where if @where;
55
    ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @conditions );
36
56
37
    # Do that after iTotalQuery!
57
    # Do that after iTotalQuery!
38
    if ( defined $branchcode and $branchcode ) {
58
    if ( defined $branchcode and $branchcode ) {
Lines 57-62 sub search { Link Here
57
77
58
    my $select = "SELECT
78
    my $select = "SELECT
59
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
79
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
80
        borrowers.flags,
60
        borrowers.streetnumber, borrowers.streettype, borrowers.address,
81
        borrowers.streetnumber, borrowers.streettype, borrowers.address,
61
        borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
82
        borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
62
        borrowers.country, cardnumber, borrowers.dateexpiry,
83
        borrowers.country, cardnumber, borrowers.dateexpiry,
Lines 65-72 sub search { Link Here
65
        categories.description AS category_description, categories.category_type,
86
        categories.description AS category_description, categories.category_type,
66
        branches.branchname, borrowers.phone";
87
        branches.branchname, borrowers.phone";
67
    my $from = "FROM borrowers
88
    my $from = "FROM borrowers
68
        LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
89
                LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
69
        LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
90
                LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
91
    if ( $has_permission ) {
92
        $from .= '
93
                LEFT JOIN user_permissions on borrowers.borrowernumber=user_permissions.borrowernumber';
94
    }
70
    my @where_args;
95
    my @where_args;
71
    my @where_strs;
96
    my @where_strs;
72
    if(defined $firstletter and $firstletter ne '') {
97
    if(defined $firstletter and $firstletter ne '') {
Lines 142-149 sub search { Link Here
142
            if @where_strs_or;
167
            if @where_strs_or;
143
    }
168
    }
144
169
145
    my $where;
170
    if ( $has_permission ) {
146
    $where = " WHERE " . join (" AND ", @where_strs) if @where_strs;
171
        push @where_strs, '( borrowers.flags = 1 OR borrowers.flags & (1 << ?) OR module_bit=? AND code=? )';
172
        push @where_args, ($has_permission->{module_bit}) x 2, $has_permission->{subpermission};
173
    }
174
175
    my $where = " WHERE " . join (" AND ", @where_strs) if @where_strs;
147
    my $orderby = dt_build_orderby($dt_params);
176
    my $orderby = dt_build_orderby($dt_params);
148
177
149
    my $limit;
178
    my $limit;
(-)a/svc/members/search (-14 / +6 lines)
Lines 72-77 if ( $searchmember Link Here
72
    } if $member;
72
    } if $member;
73
}
73
}
74
74
75
if ($has_permission) {
76
    my ( $permission, $subpermission ) = split /\./, $has_permission;
77
    $has_permission = {permission => $permission, subpermission => $subpermission};
78
}
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
    {
Lines 82-103 $results = C4::Utils::DataTables::Members::search( Link Here
82
        searchtype => $searchtype,
87
        searchtype => $searchtype,
83
        searchfieldstype => $searchfieldstype,
88
        searchfieldstype => $searchfieldstype,
84
        dt_params => \%dt_params,
89
        dt_params => \%dt_params,
90
        ( $has_permission ? ( has_permission => $has_permission ) : () ),
85
    }
91
    }
86
) unless $results;
92
) unless $results;
87
93
88
# It is not recommanded to use the has_permission param if you use the pagination
89
# The filter is done AFTER requested the data
90
if ($has_permission) {
91
    my ( $permission, $subpermission ) = split /\./, $has_permission;
92
    my @patrons_with_permission;
93
    for my $patron ( @{ $results->{patrons} } ) {
94
        push @patrons_with_permission, $patron
95
            if haspermission( $patron->{userid}, { $permission => $subpermission } );
96
    }
97
    $results->{patrons} = \@patrons_with_permission;
98
    $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
99
}
100
101
$template->param(
94
$template->param(
102
    sEcho => $sEcho,
95
    sEcho => $sEcho,
103
    iTotalRecords => $results->{iTotalRecords},
96
    iTotalRecords => $results->{iTotalRecords},
104
- 

Return to bug 24964