X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=catalogue%2Fupdateitem.pl;h=74613e27a99e79ebcbd45975eb462078182e6e80;hb=2b8b5ae225af6119e41e2112f9a8573b4170b927;hp=9c95ec3d2a9a4bed428c9099acaacf5ae8106ee5;hpb=f768cd610879688d61741d53cd06d29270652c39;p=koha_fer diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index 9c95ec3d2a..74613e27a9 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -14,92 +14,66 @@ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA -use strict; use warnings; +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +use strict; +use warnings; use CGI; +use C4::Auth; use C4::Context; use C4::Biblio; +use C4::Items; use C4::Output; use C4::Circulation; -use C4::Accounts; use C4::Reserves; my $cgi= new CGI; +checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet'); + my $biblionumber=$cgi->param('biblionumber'); my $itemnumber=$cgi->param('itemnumber'); my $biblioitemnumber=$cgi->param('biblioitemnumber'); my $itemlost=$cgi->param('itemlost'); my $itemnotes=$cgi->param('itemnotes'); -my $wthdrawn=$cgi->param('wthdrawn'); +my $withdrawn=$cgi->param('withdrawn'); my $damaged=$cgi->param('damaged'); my $confirm=$cgi->param('confirm'); my $dbh = C4::Context->dbh; + # get the rest of this item's information my $item_data_hashref = GetItem($itemnumber, undef); -my $newitemdata; + +# make sure item statuses are set to 0 if empty or NULL +for ($damaged,$itemlost,$withdrawn) { + if (!$_ or $_ eq "") { + $_ = 0; + } +} + # modify MARC item if input differs from items table. -if ( $itemnotes ne $item_data_hashref->{'itemnotes'}) { - ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemnotes', $itemnotes); - $newitemdata->{'itemnotes'} = $itemnotes; +my $item_changes = {}; +if (defined $itemnotes) { # i.e., itemnotes parameter passed from form + checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet'); + if ((not defined $item_data_hashref->{'itemnotes'}) or $itemnotes ne $item_data_hashref->{'itemnotes'}) { + $item_changes->{'itemnotes'} = $itemnotes; + } } elsif ($itemlost ne $item_data_hashref->{'itemlost'}) { - ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemlost', $itemlost); - $newitemdata->{'itemlost'} = $itemlost; -} elsif ($wthdrawn ne $item_data_hashref->{'wthdrawn'}) { - ModItemInMarconefield($biblionumber, $itemnumber, 'items.wthdrawn', $wthdrawn); - $newitemdata->{'wthdrawn'} = $wthdrawn; + $item_changes->{'itemlost'} = $itemlost; +} elsif ($withdrawn ne $item_data_hashref->{'withdrawn'}) { + $item_changes->{'withdrawn'} = $withdrawn; } elsif ($damaged ne $item_data_hashref->{'damaged'}) { - ModItemInMarconefield($biblionumber, $itemnumber, 'items.damaged', $damaged); - $newitemdata->{'damaged'} = $damaged; + $item_changes->{'damaged'} = $damaged; } else { - #nothings changed, so do nothing. - print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber"); + #nothings changed, so do nothing. + print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber"); + exit; } -# FIXME: eventually we'll use Biblio.pm, but it's currently too buggy (is this current ??) -#ModItem( $dbh,'',$biblionumber,$itemnumber,'',$item_hashref ); - $newitemdata->{'itemnumber'} = $itemnumber; -# &C4::Biblio::_koha_modify_item($dbh,$newitemdata); +ModItem($item_changes, $biblionumber, $itemnumber); - $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=?,itemnotes=? WHERE itemnumber=?"); - $sth->execute($wthdrawn,$itemlost,$damaged,$itemnotes,$itemnumber); - &ModZebra($biblionumber,"specialUpdate","biblioserver"); - -# check issues iff itemlost. - # FIXME : is there documentation or enforcement that itemlost value must be '1'? if no replacement price, then borrower just doesn't get charged? -if ($itemlost==1) { - my $sth=$dbh->prepare("SELECT * FROM issues WHERE (itemnumber=? AND returndate IS NULL)"); - $sth->execute($itemnumber); - my $issues=$sth->fetchrow_hashref(); - - # if a borrower lost the item, add a replacement cost to the their record - if ( ($issues->{borrowernumber}) && ($itemlost==1) ){ - - # first make sure the borrower hasn't already been charged for this item - my $sth1=$dbh->prepare("SELECT * from accountlines - WHERE borrowernumber=? AND itemnumber=?"); - $sth1->execute($issues->{'borrowernumber'},$itemnumber); - my $existing_charge_hashref=$sth1->fetchrow_hashref(); - - # OK, they haven't - unless ($existing_charge_hashref) { - # This item is on issue ... add replacement cost to the borrower's record and mark it returned - my $accountno = getnextacctno('',$issues->{'borrowernumber'},$dbh); - my $sth2=$dbh->prepare("INSERT INTO accountlines - (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber) - VALUES - (?,?,now(),?,?,'L',?,?)"); - $sth2->execute($issues->{'borrowernumber'},$accountno,$item_data_hashref->{'replacementprice'}, - "Lost Item $item_data_hashref->{'title'} $item_data_hashref->{'barcode'}", - $item_data_hashref->{'replacementprice'},$itemnumber); - $sth2->finish; - # FIXME: Log this ? - } - } - $sth->finish; -} +LostItem($itemnumber, 'MARK RETURNED') if $itemlost; -print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber"); +print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");