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

(-)a/C4/Items.pm (+38 lines)
Lines 80-85 BEGIN { Link Here
80
	GetAnalyticsCount
80
	GetAnalyticsCount
81
        GetItemHolds
81
        GetItemHolds
82
82
83
        SearchItems
83
84
84
        PrepareItemrecordDisplay
85
        PrepareItemrecordDisplay
85
86
Lines 2493-2498 sub GetItemHolds { Link Here
2493
    $holds = $sth->fetchrow;
2494
    $holds = $sth->fetchrow;
2494
    return $holds;
2495
    return $holds;
2495
}
2496
}
2497
2498
# Return the list of the column names of items table
2499
sub _get_items_columns {
2500
    my $dbh = C4::Context->dbh;
2501
    my $sth = $dbh->column_info(undef, undef, 'items', '%');
2502
    $sth->execute;
2503
    my $results = $sth->fetchall_hashref('COLUMN_NAME');
2504
    return keys %$results;
2505
}
2506
2507
=head2 SearchItems
2508
2509
    my $items = SearchItems($field, $value);
2510
2511
SearchItems will search for items on a specific given field.
2512
For instance you can search all items with a specific stocknumber like this:
2513
2514
    my $items = SearchItems('stocknumber', $stocknumber);
2515
2516
=cut
2517
2518
sub SearchItems {
2519
    my ($field, $value) = @_;
2520
2521
    my $dbh = C4::Context->dbh;
2522
    my @columns = _get_items_columns;
2523
    my $results = [];
2524
    if(0 < grep /^$field$/, @columns) {
2525
        my $query = "SELECT $field FROM items WHERE $field = ?";
2526
        my $sth = $dbh->prepare( $query );
2527
        $sth->execute( $value );
2528
        $results = $sth->fetchall_arrayref({});
2529
    }
2530
    return $results;
2531
}
2532
2533
2496
=head1  OTHER FUNCTIONS
2534
=head1  OTHER FUNCTIONS
2497
2535
2498
=head2 _find_value
2536
=head2 _find_value
(-)a/acqui/check_uniqueness.pl (-22 / +6 lines)
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';
69
- 

Return to bug 7178