|
Lines 33-68
use Modern::Perl;
Link Here
|
| 33 |
|
33 |
|
| 34 |
use CGI; |
34 |
use CGI; |
| 35 |
use JSON; |
35 |
use JSON; |
| 36 |
use C4::Context; |
|
|
| 37 |
use C4::Output; |
36 |
use C4::Output; |
| 38 |
use C4::Auth; |
37 |
use C4::Items; |
| 39 |
|
38 |
|
| 40 |
my $input = new CGI; |
39 |
my $input = new CGI; |
| 41 |
my @field = $input->param('field'); |
40 |
my @field = $input->param('field'); |
| 42 |
my @value = $input->param('value'); |
41 |
my @value = $input->param('value'); |
| 43 |
|
42 |
|
| 44 |
my $dbh = C4::Context->dbh; |
|
|
| 45 |
|
| 46 |
my $query = "SHOW COLUMNS FROM items"; |
| 47 |
my $sth = $dbh->prepare($query); |
| 48 |
$sth->execute; |
| 49 |
my $results = $sth->fetchall_hashref('Field'); |
| 50 |
my @columns = keys %$results; |
| 51 |
|
| 52 |
my $r = {}; |
43 |
my $r = {}; |
| 53 |
my $index = 0; |
44 |
my $i = 0; |
| 54 |
for my $f ( @field ) { |
45 |
for ( my $i=0; $i<@field; $i++ ) { |
| 55 |
if(0 < grep /^$f$/, @columns) { |
46 |
my $items = C4::Items::SearchItems($field[$i], $value[$i]); |
| 56 |
$query = "SELECT $f FROM items WHERE $f = ?"; |
|
|
| 57 |
$sth = $dbh->prepare( $query ); |
| 58 |
$sth->execute( $value[$index] ); |
| 59 |
my @values = $sth->fetchrow_array; |
| 60 |
|
47 |
|
| 61 |
if ( @values ) { |
48 |
if ( @$items ) { |
| 62 |
push @{ $r->{$f} }, $values[0]; |
49 |
push @{ $r->{$field[$i]} }, $value[$i]; |
| 63 |
} |
|
|
| 64 |
} |
50 |
} |
| 65 |
$index++; |
|
|
| 66 |
} |
51 |
} |
| 67 |
|
52 |
|
| 68 |
output_with_http_headers $input, undef, to_json($r), 'json'; |
53 |
output_with_http_headers $input, undef, to_json($r), 'json'; |