Move checks of additem.pl to the API
[koha.git] / cataloguing / additem.pl
index 376687c..ee551c9 100755 (executable)
@@ -134,27 +134,12 @@ if ($op eq "additem") {
 #-------------------------------------------------------------------------------
 } elsif ($op eq "delitem") {
 #-------------------------------------------------------------------------------
-    # check that there is no issue on this item before deletion.
-    my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
-    $sth->execute($itemnumber);
-    my $onloan=$sth->fetchrow;
-       $sth->finish();
-    push @errors,"book_on_loan" if ($onloan); ##error book_on_loan added to template as well
-    if ($onloan){
-               $nextop="additem";
-    } else {
-               # check it doesnt have a waiting reserve
-               $sth=$dbh->prepare("SELECT * FROM reserves WHERE found = 'W' AND itemnumber = ?");
-               $sth->execute($itemnumber);
-               my $reserve=$sth->fetchrow;
-               if ($reserve){
-                       push @errors,"book_reserved";
-                       $nextop="additem";
-               }
-               else {
-                       &DelItem($dbh,$biblionumber,$itemnumber);
-                       print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
-               }
+    $error = &DelItemCheck($dbh,$biblionumber,$itemnumber);
+    if($error == 1){
+        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
+    }else{
+        push @errors,$error;
+        $nextop="additem";
     }
 #-------------------------------------------------------------------------------
 } elsif ($op eq "delallitems") {