From bb8b344e4021e0eb9b51e3b8f52d7cfb915fe4de Mon Sep 17 00:00:00 2001 From: truth_nz Date: Tue, 14 May 2002 04:12:52 +0000 Subject: [PATCH] Added code to allow deleting of biblioitems --- C4/Acquisitions.pm | 76 ++++++++++++++++++++++++---------- acqui.simple/addbooks.pl | 10 ++++- acqui.simple/savebiblioitem.pl | 8 +++- deletebiblioitem.pl | 21 ++++++++++ modbibitem.pl | 2 +- 5 files changed, 89 insertions(+), 28 deletions(-) create mode 100755 deletebiblioitem.pl diff --git a/C4/Acquisitions.pm b/C4/Acquisitions.pm index f7d400b5bf..088c1d7440 100644 --- a/C4/Acquisitions.pm +++ b/C4/Acquisitions.pm @@ -15,7 +15,7 @@ $VERSION = 0.01; &newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder &bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem &getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems -&findall &needsmod &delitem &delbibitem &delbiblio &delorder &branches +&findall &needsmod &delitem &deletebiblioitem &delbiblio &delorder &branches &getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder &updatecost &checkitems &modnote &getitemtypes &getbiblio &getbiblioitem &getitemsbybiblioitem &isbnsearch &keywordsearch @@ -1115,32 +1115,62 @@ sub delitem{ $dbh->disconnect; } -sub delbibitem{ - my ($itemnum)=@_; - my $dbh=C4Connect; - my $query="select * from biblioitems where biblioitemnumber=$itemnum"; - my $sth=$dbh->prepare($query); - $sth->execute; - if (my @data=$sth->fetchrow_array){ - $sth->finish; - $query="Insert into deletedbiblioitems values ("; - foreach my $temp (@data){ - $temp=~ s/\'/\\\'/g; - $query=$query."'$temp',"; - } - $query=~ s/\,$/\)/; -# print $query; - $sth=$dbh->prepare($query); + +sub deletebiblioitem { + my ($biblioitemnumber) = @_; + my $dbh = C4Connect; + my $query = "Select * from biblioitems +where biblioitemnumber = $biblioitemnumber"; + my $sth = $dbh->prepare($query); + my @results; + $sth->execute; + + if (@results = $sth->fetchrow_array) { + + $query = "Insert into deletedbiblioitems values ("; + foreach my $value (@results) { + $value = $dbh->quote($value); + $query .= "$value,"; + } # foreach + + $query =~ s/\,$/\)/; + $dbh->do($query); + + $query = "Delete from biblioitems +where biblioitemnumber = $biblioitemnumber"; + $dbh->do($query); + } # if + $sth->finish; - $query = "Delete from biblioitems where biblioitemnumber=$itemnum"; - $sth=$dbh->prepare($query); + +# Now delete all the items attached to the biblioitem + + $query = "Select * from items where biblioitemnumber = $biblioitemnumber"; + $sth = $dbh->prepare($query); + $sth->execute; + + while (@results = $sth->fetchrow_array) { + + $query = "Insert into deleteditems values ("; + foreach my $value (@results) { + $value = $dbh->quote($value); + $query .= "$value,"; + } # foreach + + $query =~ s/\,$/\)/; + $dbh->do($query); + } # while + $sth->finish; - } - $sth->finish; - $dbh->disconnect; -} + + $query = "Delete from items where biblioitemnumber = $biblioitemnumber"; + $dbh->do($query); + + $dbh->disconnect; +} # sub deletebiblioitem + sub delbiblio{ my ($biblio)=@_; diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index 4a335e23b7..6e016f3a11 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -11,7 +11,8 @@ use strict; use C4::Output; my $input = new CGI; -my $error = $input->param('error'); +my $error = $input->param('error'); +my $success = $input->param('biblioitem'); print $input->header; print startpage(); @@ -33,7 +34,12 @@ EOF No items found

EOF - } # if + } elsif ($success eq "added") { + print << "EOF"; +Website Biblioitem Added +

+EOF + } # elsif print << "EOF"; diff --git a/acqui.simple/savebiblioitem.pl b/acqui.simple/savebiblioitem.pl index 2e3d06e4e8..39704300c1 100755 --- a/acqui.simple/savebiblioitem.pl +++ b/acqui.simple/savebiblioitem.pl @@ -35,6 +35,10 @@ if (! $biblionumber) { } else { $biblioitemnum = &newbiblioitem($biblioitem); - - print $input->redirect("additem.pl?biblioitemnum=$biblioitemnum"); + + if ($input->param('itemtype') eq "WEB") { + print $input->redirect("addbooks.pl?biblioitem=added"); + } else { + print $input->redirect("additem.pl?biblioitemnum=$biblioitemnum"); + } # else } # else diff --git a/deletebiblioitem.pl b/deletebiblioitem.pl new file mode 100755 index 0000000000..292c33e0ce --- /dev/null +++ b/deletebiblioitem.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use strict; +use C4::Acquisitions; +use CGI; + +my $input = new CGI; +my $biblionumber = $input->param('biblionumber'); +my $biblioitemnumber = $input->param('biblioitemnumber'); + +if (! $biblionumber) { + print $input->redirect("/catalogue/"); + +} elsif (! $biblioitemnumber) { + print $input->param("detail.pl?type=intra&bib=$biblionumber"); + +} else { + &deletebiblioitem($biblioitemnumber); + + print $input->redirect("detail.pl?type=intra&bib=$biblionumber"); +} # else diff --git a/modbibitem.pl b/modbibitem.pl index 9640994a0b..d9555b002d 100755 --- a/modbibitem.pl +++ b/modbibitem.pl @@ -19,7 +19,7 @@ my $data=bibitemdata($bibitemnum); my $biblio=$input->param('biblio'); my $submit=$input->param('submit.x'); if ($submit eq ''){ - print $input->redirect("/cgi-bin/koha/delbibitem.pl?bibitemnum=$bibitemnum&biblio=$biblio"); + print $input->redirect("deletebiblioitem.pl?biblioitemnumber=$bibitemnum&biblionumber=$biblio"); } print $input->header; #my ($count,$subject)=subject($data->{'biblionumber'}); -- 2.39.5