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

(-)a/C4/Items.pm (-1 / +6 lines)
Lines 2042-2051 sub _koha_new_item { Link Here
2042
            $item->{'copynumber'},
2042
            $item->{'copynumber'},
2043
            $item->{'stocknumber'},
2043
            $item->{'stocknumber'},
2044
    );
2044
    );
2045
    my $itemnumber = $dbh->{'mysql_insertid'};
2045
2046
    my $itemnumber;
2046
    if ( defined $sth->errstr ) {
2047
    if ( defined $sth->errstr ) {
2047
        $error.="ERROR in _koha_new_item $query".$sth->errstr;
2048
        $error.="ERROR in _koha_new_item $query".$sth->errstr;
2048
    }
2049
    }
2050
    else {
2051
        $itemnumber = $dbh->{'mysql_insertid'};
2052
    }
2053
2049
    return ( $itemnumber, $error );
2054
    return ( $itemnumber, $error );
2050
}
2055
}
2051
2056
(-)a/acqui/check_duplicate_barcode_ajax.pl (+55 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Frédérick Capovilla, 2011 - Libéo
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
#use warnings; FIXME - Bug 2505
22
use CGI;
23
use CGI::Cookie;
24
use JSON;
25
use C4::Auth;
26
use C4::Items;
27
use C4::Context;
28
29
my $input        = new CGI;
30
print $input->header('application/json');
31
32
# Check the user's permissions
33
my %cookies = fetch CGI::Cookie;
34
my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
35
my ($auth_status, $auth_sessid) = C4::Auth::check_cookie_auth($sessid, {acquisition => 'order_manage'});
36
if ($auth_status ne "ok") {
37
    print to_json({status => 'UNAUTHORIZED'});
38
    exit 0;
39
}
40
41
my $json;
42
43
#Check if the barcodes already exist.
44
my @barcodes = $input->param('barcodes');
45
foreach my $barcode (@barcodes) {
46
    my $existing_itemnumber = GetItemnumberFromBarcode($barcode);
47
    if ($existing_itemnumber) {
48
        $json->{status} = "DUPLICATES";
49
        push @{$json->{barcodes}}, $barcode;
50
    }
51
}
52
53
$json->{status} = 'OK' unless defined $json->{status};
54
print to_json($json);
55
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-4 / +43 lines)
Lines 46-71 function Check(ff) { Link Here
46
    }
46
    }
47
47
48
    if ( ff.field_value ) {
48
    if ( ff.field_value ) {
49
        var barcodes = [];
49
        var empty_item_mandatory = 0;
50
        var empty_item_mandatory = 0;
50
        for (i = 0; i < ff.field_value.length; i++) {
51
        for (i = 0; i < ff.field_value.length; i++) {
51
            //alert("i = " + i + " => " + ff.kohafield[i] );
52
            //alert("i = " + i + " => " + ff.kohafield[i] );
52
            if (ff.field_value[i].value.length == 0 && ff.mandatory[i].value == 1) {
53
            if (ff.field_value[i].value.length == 0 && ff.mandatory[i].value == 1) {
53
                empty_item_mandatory++;
54
                empty_item_mandatory++;
54
            }
55
            }
56
            if(ff.subfield[i].value == 'p') {
57
                barcodes.push(ff.field_value[i].value);
58
            }
55
        }
59
        }
56
        if (empty_item_mandatory > 0) {
60
        if (empty_item_mandatory > 0) {
57
            ok = 1;
61
            ok = 1;
58
            _alertString +=
62
            _alertString +=
59
                "\n- " + empty_item_mandatory + _(" item mandatory fields empty");
63
                "\n- " + empty_item_mandatory + _(" item mandatory fields empty");
60
        }
64
        }
65
66
        // Check for duplicate barcodes in the form
67
        barcodes = barcodes.sort();
68
        for(var i=0; i<barcodes.length-1; i++) {
69
            if(barcodes[i] == barcodes[i+1]) {
70
                ok = 1;
71
                _alertString += "\n- " + _("The barcode ") + barcodes[i] + _(" is used more than once in the form. Every barcode must be unique");
72
            }
73
        }
74
75
        // Check for duplicate barcodes in the database via an ajax call
76
        $.ajax({
77
            url: "/cgi-bin/koha/acqui/check_duplicate_barcode_ajax.pl",
78
            async:false,
79
            method: "post",
80
            data: {barcodes : barcodes},
81
            dataType: 'json',
82
83
            error: function(xhr) {
84
                alert("Error: \n" + xhr.responseText);
85
            },
86
            success: function(json) {
87
                switch(json.status) {
88
                    case 'UNAUTHORIZED':
89
                        ok = 1;
90
                        _alertString += "\n- " + _("Error: Duplicate barcode verification failed. Insufficient user permissions.");
91
                        break;
92
                    case 'DUPLICATES':
93
                        ok = 1;
94
                        $.each(json.barcodes, function(index, barcode) {
95
                            _alertString += "\n- " + _("The barcode ") + barcode + _(" already exists in the database");
96
                        });
97
                        break;
98
                }
99
            },
100
        });
61
    }
101
    }
62
102
63
if (ok) {
103
    if (ok) {
64
        alert(_alertString);
104
        alert(_alertString);
65
    return false;
105
        return false;
66
    }
106
    }
67
107
68
ff.submit();
108
    ff.submit();
69
109
70
}
110
}
71
111
72
- 

Return to bug 6963