(bug #3802) fix branch deletion checks
authorNahuel ANGELINETTI <nahuel.angelinetti@biblibre.com>
Mon, 23 Nov 2009 09:20:00 +0000 (10:20 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 23 Nov 2009 09:35:25 +0000 (10:35 +0100)
This fix checks that are done when a branch is deleted, and the message shown.
Now it check for borrowers and items attached to the deleted branch.

admin/branches.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl

index 8150a1d..744ccfb 100755 (executable)
@@ -114,10 +114,13 @@ elsif ( $op eq 'delete' ) {
     
     # check to see if the branchcode is being used in the database somewhere....
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("select count(*) from items where holdingbranch=? or homebranch=?");
-    $sth->execute( $branchcode, $branchcode );
-    my ($total) = $sth->fetchrow_array;
-    if ($total) {
+    my $sthitems     = $dbh->prepare("select count(*) from items where holdingbranch=? or homebranch=?");
+    my $sthborrowers = $dbh->prepare("select count(*) from borrowers where branchcode=?");
+    $sthitems->execute( $branchcode, $branchcode );
+    $sthborrowers->execute( $branchcode );
+    my ($totalitems)     = $sthitems->fetchrow_array;
+    my ($totalborrowers) = $sthitems->fetchrow_array;
+    if ($totalitems or $totalborrowers) {
         $template->param( else => 1 );
         default("MESSAGE7", $template);
     }
index b3ecf07..de96c18 100644 (file)
     <!-- TMPL_IF name="MESSAGE4" --><div class="dialog message">Library category added</div><!-- /TMPL_IF -->
     <!-- TMPL_IF name="MESSAGE5" --><div class="dialog message">Library category modified</div><!-- /TMPL_IF -->
     <!-- TMPL_IF name="MESSAGE6" --><div class="dialog message">Library category deleted</div><!-- /TMPL_IF -->
-    <!-- TMPL_IF name="MESSAGE7" --><div class="dialog message">Library cannot be deleted because there are patrons using that library</div><!-- /TMPL_IF -->
+    <!-- TMPL_IF name="MESSAGE7" --><div class="dialog message">Library cannot be deleted because there are patrons or items using that library</div><!-- /TMPL_IF -->
     <!-- TMPL_IF name="MESSAGE8" --><div class="dialog message">Category cannot be deleted because there are libraries using that category</div><!-- /TMPL_IF -->
 
 <!-- TMPL_IF NAME="branches" -->