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

(-)a/C4/Utils/DataTables/Members.pm (-7 / +36 lines)
Lines 14-19 sub search { Link Here
14
    my $branchcode = $params->{branchcode};
14
    my $branchcode = $params->{branchcode};
15
    my $searchtype = $params->{searchtype} || 'contain';
15
    my $searchtype = $params->{searchtype} || 'contain';
16
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
16
    my $searchfieldstype = $params->{searchfieldstype} || 'standard';
17
    my $has_permission = $params->{has_permission};
17
    my $dt_params = $params->{dt_params};
18
    my $dt_params = $params->{dt_params};
18
19
19
    unless ( $searchmember ) {
20
    unless ( $searchmember ) {
Lines 28-39 sub search { Link Here
28
29
29
    my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords);
30
    my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords);
30
    my $dbh = C4::Context->dbh;
31
    my $dbh = C4::Context->dbh;
32
33
    # Get the module_bit from a given permission code
34
    if ( $has_permission ) {
35
        ($has_permission->{module_bit}) = $dbh->selectrow_array(q|
36
            SELECT bit FROM userflags WHERE flag=?
37
        |, undef, $has_permission->{permission});
38
    }
39
31
    # Get the iTotalRecords DataTable variable
40
    # Get the iTotalRecords DataTable variable
32
    $query = $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
41
    $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
42
    if ( $has_permission ) {
43
        $iTotalQuery .= ' LEFT JOIN user_permissions on borrowers.borrowernumber=user_permissions.borrowernumber';
44
    }
45
46
    my (@where, @conditions);
33
    if ( @restricted_branchcodes ) {
47
    if ( @restricted_branchcodes ) {
34
        $iTotalQuery .= " WHERE borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
48
        push @where, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
49
        push @conditions, @restricted_branchcodes;
35
    }
50
    }
36
    ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @restricted_branchcodes );
51
    if ( $has_permission ) {
52
        push @where, '( borrowers.flags = 1 OR borrowers.flags & (1 << ?) OR module_bit=? AND code=? )';
53
        push @conditions, ($has_permission->{module_bit}) x 2, $has_permission->{subpermission};
54
    }
55
    $iTotalQuery .= ' WHERE ' . join ' AND ', @where if @where;
56
    ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @conditions );
37
57
38
    # Do that after iTotalQuery!
58
    # Do that after iTotalQuery!
39
    if ( defined $branchcode and $branchcode ) {
59
    if ( defined $branchcode and $branchcode ) {
Lines 58-63 sub search { Link Here
58
78
59
    my $select = "SELECT
79
    my $select = "SELECT
60
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
80
        borrowers.borrowernumber, borrowers.surname, borrowers.firstname,
81
        borrowers.flags,
61
        borrowers.streetnumber, borrowers.streettype, borrowers.address,
82
        borrowers.streetnumber, borrowers.streettype, borrowers.address,
62
        borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
83
        borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
63
        borrowers.country, cardnumber, borrowers.dateexpiry,
84
        borrowers.country, cardnumber, borrowers.dateexpiry,
Lines 66-73 sub search { Link Here
66
        categories.description AS category_description, categories.category_type,
87
        categories.description AS category_description, categories.category_type,
67
        branches.branchname, borrowers.phone";
88
        branches.branchname, borrowers.phone";
68
    my $from = "FROM borrowers
89
    my $from = "FROM borrowers
69
        LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
90
                LEFT JOIN branches ON borrowers.branchcode = branches.branchcode
70
        LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
91
                LEFT JOIN categories ON borrowers.categorycode = categories.categorycode";
92
    if ( $has_permission ) {
93
        $from .= '
94
                LEFT JOIN user_permissions on borrowers.borrowernumber=user_permissions.borrowernumber';
95
    }
71
    my @where_args;
96
    my @where_args;
72
    my @where_strs;
97
    my @where_strs;
73
    if(defined $firstletter and $firstletter ne '') {
98
    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 (-25 / +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-114 $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
        my $perms = haspermission( $patron->{userid}, undef );
95
        if (   $perms->{superlibrarian} == 1
96
            or $perms->{$permission} == 1 )
97
        {
98
            push @patrons_with_permission, $patron;
99
            next;
100
        }
101
102
        if ($subpermission) {
103
            my $subperms = get_user_subpermissions( $patron->{userid} );
104
            push @patrons_with_permission, $patron
105
              if $subperms->{$permission}->{$subpermission};
106
        }
107
    }
108
    $results->{patrons} = \@patrons_with_permission;
109
    $results->{iTotalDisplayRecords} = scalar( @patrons_with_permission );
110
}
111
112
$template->param(
94
$template->param(
113
    sEcho => $sEcho,
95
    sEcho => $sEcho,
114
    iTotalRecords => $results->{iTotalRecords},
96
    iTotalRecords => $results->{iTotalRecords},
115
- 

Return to bug 24964