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; |