From 87d73f3a1ce45e5e4b2cb9b2de81f0f21ba00509 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Wed, 13 Feb 2013 18:30:31 +1300 Subject: [PATCH] bug_8034: Disable delete printer for printers asigned to branches * 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 = <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 @@ [% loo.printername %] [% loo.printqueue %] [% loo.printtype %] - Edit Delete + + Edit + [% IF loo.branches %] + Default printer for [% loo.branches %] branch(es) + [% ELSE %] + Delete + [% END %] + [% END %] [% ELSE %]
No printers defined.
[% END %] -- 1.7.10.4