Bug 21206: Replace C4::Items::GetItem
[koha.git] / catalogue / updateitem.pl
1 #!/usr/bin/perl
2
3 # $Id: updateitem.pl,v 1.9.2.1.2.4 2006/10/05 18:36:50 kados Exp $
4 # Copyright 2006 LibLime
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use C4::Auth;
23 use C4::Context;
24 use C4::Biblio;
25 use C4::Items;
26 use C4::Output;
27 use C4::Circulation;
28 use C4::Reserves;
29
30 my $cgi= new CGI;
31
32 checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet');
33
34 my $biblionumber=$cgi->param('biblionumber');
35 my $itemnumber=$cgi->param('itemnumber');
36 my $biblioitemnumber=$cgi->param('biblioitemnumber');
37 my $itemlost=$cgi->param('itemlost');
38 my $itemnotes=$cgi->param('itemnotes');
39 my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic');
40 my $withdrawn=$cgi->param('withdrawn');
41 my $damaged=$cgi->param('damaged');
42
43 my $confirm=$cgi->param('confirm');
44 my $dbh = C4::Context->dbh;
45
46 # get the rest of this item's information
47 my $item_data_hashref = Koha::Items->find($itemnumber)->unblessed;
48
49 # make sure item statuses are set to 0 if empty or NULL
50 for ($damaged,$itemlost,$withdrawn) {
51     if (!$_ or $_ eq "") {
52         $_ = 0;
53     }
54 }
55
56 # modify MARC item if input differs from items table.
57 my $item_changes = {};
58 if (defined $itemnotes_nonpublic) { # i.e., itemnotes_nonpublic parameter passed from form
59     checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
60     if ((not defined  $item_data_hashref->{'itemnotes_nonpublic'}) or $itemnotes_nonpublic ne $item_data_hashref->{'itemnotes_nonpublic'}) {
61         $item_changes->{'itemnotes_nonpublic'} = $itemnotes_nonpublic;
62     }
63 }
64 elsif (defined $itemnotes) { # i.e., itemnotes parameter passed from form
65     checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
66     if ((not defined  $item_data_hashref->{'itemnotes'}) or $itemnotes ne $item_data_hashref->{'itemnotes'}) {
67         $item_changes->{'itemnotes'} = $itemnotes;
68     }
69 } elsif ($itemlost ne $item_data_hashref->{'itemlost'}) {
70     $item_changes->{'itemlost'} = $itemlost;
71 } elsif ($withdrawn ne $item_data_hashref->{'withdrawn'}) {
72     $item_changes->{'withdrawn'} = $withdrawn;
73 } elsif ($damaged ne $item_data_hashref->{'damaged'}) {
74     $item_changes->{'damaged'} = $damaged;
75 } else {
76     #nothings changed, so do nothing.
77     print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
78         exit;
79 }
80
81 ModItem($item_changes, $biblionumber, $itemnumber);
82
83 LostItem($itemnumber, 'moredetail') if $itemlost;
84
85 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");