[Koha-patches] [PATCH] bug_8034: Disable delete printer for printers asigned to branches

Srdjan srdjan at catalyst.net.nz
Wed Feb 13 06:38:13 CET 2013


* C4::Printer - added branch count to printer queries
* admin/printers.tt - show or not delete link
---
 C4/Printer.pm                                      |   24 ++++++++++++++------
 admin/printers.pl                                  |    8 ++++++-
 .../prog/en/modules/admin/printers.tt              |    9 +++++++-
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/C4/Printer.pm b/C4/Printer.pm
index 0990bad..e24c9b2 100644
--- a/C4/Printer.pm
+++ b/C4/Printer.pm
@@ -67,10 +67,17 @@ references-to-hash, whose keys are the fields in the printers table.
 
 =cut
 
+my $PRINTER_SELECT_FROM = <<EOQ;
+SELECT printername, printqueue, printtype, branches
+FROM printers
+LEFT OUTER JOIN (SELECT branchprinter, COUNT(*) AS branches FROM branches GROUP BY branchprinter) b
+  ON (branchprinter = printqueue)
+EOQ
+
 sub GetPrinters {
     my %printers;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("select * from printers");
+    my $sth = $dbh->prepare($PRINTER_SELECT_FROM);
     $sth->execute;
     while ( my $printer = $sth->fetchrow_hashref ) {
         $printers{ $printer->{'printqueue'} } = $printer;
@@ -87,10 +94,11 @@ sub GetPrinters {
 sub SearchPrinters {
     my ($searchstring)=@_;
     $searchstring .= '%';
-    return C4::Context->dbh->selectall_arrayref("
-        SELECT * FROM printers 
-        WHERE printername like ? OR printqueue like ? ORDER BY printername
-        ", {Slice => {}}, $searchstring, $searchstring);
+    return C4::Context->dbh->selectall_arrayref(
+        "$PRINTER_SELECT_FROM
+         WHERE printername like ? OR printqueue like ? ORDER BY printername",
+        {Slice => {}},
+        $searchstring, $searchstring);
 }
 
 =head2 GetPrinterDetails
@@ -102,8 +110,10 @@ sub SearchPrinters {
 sub GetPrinterDetails {
     my ( $printer ) = @_;
     my $dbh = C4::Context->dbh;
-    my $printername = $dbh->selectrow_hashref('SELECT * FROM printers WHERE printqueue = ?', undef, $printer);
-    return $printername;
+    return $dbh->selectrow_hashref(
+        "$PRINTER_SELECT_FROM
+         WHERE printqueue = ?",
+        undef, $printer);
 }
 
 =head2 AddPrinter
diff --git a/admin/printers.pl b/admin/printers.pl
index 12e42d7..38eb177 100755
--- a/admin/printers.pl
+++ b/admin/printers.pl
@@ -101,8 +101,14 @@ if ($op eq 'add_form') {
 # called by default form, used to confirm deletion of data in DB
 } elsif ($op eq 'delete_confirm') {
     $list_printers = 0;
-    $template->param(delete_confirm => 1);
     my $data=GetPrinterDetails($searchfield);
+    my $branches = $data->{branches};
+    if ($branches && $branches > 0) {
+        $template->param(cannot_delete_branches => $branches);
+        $template->param(add_form => 1);
+    } else {
+        $template->param(delete_confirm => 1);
+    }
     $template->param(
         printqueue => $data->{'printqueue'},
         printtype  => $data->{'printtype'},
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt
index 06fd229..29445c4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt
@@ -171,7 +171,14 @@
 			<td>[% loo.printername %]</td>
 			<td>[% loo.printqueue %]</td>
 			<td>[% loo.printtype %]</td>
-                     <td><a href="[% loo.script_name %]?op=add_form&searchfield=[% loo.printqueue %]">Edit</a> <a href="[% loo.script_name %]?op=delete_confirm&searchfield=[% loo.printqueue %]">Delete</a></td>
+                     <td>
+                         <a href="[% loo.script_name %]?op=add_form&searchfield=[% loo.printqueue %]">Edit</a>
+                     [% IF loo.branches %]
+                         Default printer for [% loo.branches %] branch(es)
+                     [% ELSE %]
+                         <a href="[% loo.script_name %]?op=delete_confirm&searchfield=[% loo.printqueue %]">Delete</a>
+                     [% END %]
+                     </td>
 		</tr>
 		[% END %]
 	</table>[% ELSE %]<div class="notice">No printers defined.</div>[% END %]
-- 
1.7.10.4



More information about the Koha-patches mailing list