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