[Koha-patches] [PATCH] bug_8034: Restored network printer maintenance and selection

Srdjan srdjan at catalyst.net.nz
Fri Jan 8 07:14:37 CET 2016


This patch is just for restoring printer maintenance and selection, not
for priting itself. It is just a preparation step.

* Added UsePrintQueues syspref. If set to No, no printer info will be
  displayed/used
* Database changes:
- printers table PRIMARY KEY is now printqueue. It is more natural. We
  should really have a synthetic id, but printqueue is good enough
- branches.branchprinter is a FOREIGN KEY to printers.printqueue
* Created C4::Auth::get_user_printer() function that will return
  appropriate printer. In order of preference:
- session selected
- logged in branch branchprinter
* Moved printer functions to C4::Printer
* C4::Printer - added branch count to printer queries
* admin/printers.tt - show or not delete link
* Restored printer maint/selection in admin zone UsePrintQueues
  permitting
* Restored printer selection in circ/selectbranchprinter.pl
  UsePrintQueues permitting
---
 C4/Auth.pm                                         |  53 +++++--
 C4/Koha.pm                                         |  40 ------
 C4/Printer.pm                                      | 158 +++++++++++++++++++++
 admin/branches.pl                                  |  31 ++--
 admin/printers.pl                                  | 148 ++++++++++---------
 circ/circulation.pl                                |  11 +-
 circ/returns.pl                                    |  13 +-
 circ/selectbranchprinter.pl                        |  49 ++++---
 .../mysql/atomicupdate/bug_8034_printer_queues.sql |   8 ++
 installer/data/mysql/kohastructure.sql             |  20 +--
 installer/data/mysql/sysprefs.sql                  |   1 +
 .../intranet-tmpl/prog/en/includes/admin-menu.inc  |   2 +-
 .../intranet-tmpl/prog/en/includes/header.inc      |   3 +
 .../prog/en/modules/admin/admin-home.tt            |   6 +-
 .../prog/en/modules/admin/branches.tt              |  18 ++-
 .../en/modules/admin/preferences/circulation.pref  |   6 +
 .../prog/en/modules/admin/printers.tt              |  40 ++----
 .../prog/en/modules/circ/circulation.tt            |   2 -
 .../prog/en/modules/circ/selectbranchprinter.tt    |   5 +-
 t/db_dependent/Printer.t                           |  62 ++++++++
 20 files changed, 448 insertions(+), 228 deletions(-)
 create mode 100644 C4/Printer.pm
 create mode 100644 installer/data/mysql/atomicupdate/bug_8034_printer_queues.sql
 create mode 100644 t/db_dependent/Printer.t

diff --git a/C4/Auth.pm b/C4/Auth.pm
index d7be1d8..3dfe01f 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -29,6 +29,7 @@ use C4::Context;
 use C4::Templates;    # to get the template
 use C4::Languages;
 use C4::Branch;       # GetBranches
+use C4::Printer qw(GetPrinterDetails);
 use C4::Search::History;
 use Koha;
 use Koha::AuthUtils qw(hash_password);
@@ -52,7 +53,7 @@ BEGIN {
     @ISA       = qw(Exporter);
     @EXPORT    = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
     @EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
-      &get_all_subpermissions &get_user_subpermissions
+      &get_all_subpermissions &get_user_subpermissions &get_user_printer
     );
     %EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );
     $ldap      = C4::Context->config('useldapserver') || 0;
@@ -398,6 +399,9 @@ sub get_template_and_user {
 
     $template->param(auth_forwarded_hash => $in->{'query'}->param('auth_forwarded_hash'));
 
+    my $userenv = C4::Context->userenv;
+    my $userenv_branch = $userenv ? $userenv->{"branch"} : undef;
+
     # these template parameters are set the same regardless of $in->{'type'}
 
     # Set the using_https variable for templates
@@ -411,11 +415,11 @@ sub get_template_and_user {
         GoogleJackets                                                      => C4::Context->preference("GoogleJackets"),
         OpenLibraryCovers                                                  => C4::Context->preference("OpenLibraryCovers"),
         KohaAdminEmailAddress                                              => "" . C4::Context->preference("KohaAdminEmailAddress"),
-        LoginBranchcode => ( C4::Context->userenv ? C4::Context->userenv->{"branch"}    : undef ),
-        LoginFirstname  => ( C4::Context->userenv ? C4::Context->userenv->{"firstname"} : "Bel" ),
-        LoginSurname    => C4::Context->userenv ? C4::Context->userenv->{"surname"}      : "Inconnu",
-        emailaddress    => C4::Context->userenv ? C4::Context->userenv->{"emailaddress"} : undef,
-        loggedinpersona => C4::Context->userenv ? C4::Context->userenv->{"persona"}      : undef,
+        LoginBranchcode => $userenv_branch,
+        LoginFirstname  => ( $userenv ? $userenv->{"firstname"} : undef ),
+        LoginSurname    => $userenv ? $userenv->{"surname"}      : undef,
+        emailaddress    => $userenv ? $userenv->{"emailaddress"} : undef,
+        loggedinpersona => $userenv ? $userenv->{"persona"}      : undef,
         TagsEnabled     => C4::Context->preference("TagsEnabled"),
         hide_marc       => C4::Context->preference("hide_marc"),
         item_level_itypes  => C4::Context->preference('item-level_itypes'),
@@ -440,7 +444,7 @@ sub get_template_and_user {
             IntranetNav                                                                => C4::Context->preference("IntranetNav"),
             IntranetmainUserblock                                                      => C4::Context->preference("IntranetmainUserblock"),
             LibraryName                                                                => C4::Context->preference("LibraryName"),
-            LoginBranchname                                                            => ( C4::Context->userenv ? C4::Context->userenv->{"branchname"} : undef ),
+            LoginBranchname                                                            => ( $userenv ? $userenv->{"branchname"} : undef ),
             advancedMARCEditor                                                         => C4::Context->preference("advancedMARCEditor"),
             canreservefromotherbranches                                                => C4::Context->preference('canreservefromotherbranches'),
             intranetcolorstylesheet                                                    => C4::Context->preference("intranetcolorstylesheet"),
@@ -462,6 +466,14 @@ sub get_template_and_user {
             UseCourseReserves                                                          => C4::Context->preference("UseCourseReserves"),
             useDischarge                                                               => C4::Context->preference('useDischarge'),
         );
+        if ( C4::Context->preference('UsePrintQueues') ) {
+            my $printer = get_user_printer();
+            my $printer_rec = $printer ? GetPrinterDetails($printer) : {};
+            $template->param(
+                UsePrintQueues          => 1,
+                PrinterName             => $printer_rec->{printername},
+            );
+        }
     }
     else {
         warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
@@ -497,8 +509,8 @@ sub get_template_and_user {
             $opac_name = $1;    # opac_search_limit is a branch, so we use it.
         } elsif ( $in->{'query'}->param('multibranchlimit') ) {
             $opac_name = $in->{'query'}->param('multibranchlimit');
-        } elsif ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv && C4::Context->userenv->{'branch'} ) {
-            $opac_name = C4::Context->userenv->{'branch'};
+        } elsif ( C4::Context->preference("SearchMyLibraryFirst") && $userenv_branch ) {
+            $opac_name = $userenv_branch;
         }
 
         $template->param(
@@ -509,7 +521,7 @@ sub get_template_and_user {
             BranchCategoriesLoop                  => GetBranchCategories( 'searchdomain', 1, $opac_name ),
             LibraryName                           => "" . C4::Context->preference("LibraryName"),
             LibraryNameTitle                      => "" . $LibraryNameTitle,
-            LoginBranchname                       => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "",
+            LoginBranchname                       => $userenv ? $userenv->{"branchname"} : "",
             OPACAmazonCoverImages                 => C4::Context->preference("OPACAmazonCoverImages"),
             OPACFRBRizeEditions                   => C4::Context->preference("OPACFRBRizeEditions"),
             OpacHighlightedWords                  => C4::Context->preference("OpacHighlightedWords"),
@@ -535,7 +547,7 @@ sub get_template_and_user {
             RequestOnOpac                         => C4::Context->preference("RequestOnOpac"),
             'Version'                             => C4::Context->preference('Version'),
             hidelostitems                         => C4::Context->preference("hidelostitems"),
-            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv ) ? C4::Context->userenv->{'branch'} : '',
+            mylibraryfirst                        => ( C4::Context->preference("SearchMyLibraryFirst") && $userenv ) ? $userenv_branch : '',
             opaclayoutstylesheet                  => "" . C4::Context->preference("opaclayoutstylesheet"),
             opacbookbag                           => "" . C4::Context->preference("opacbookbag"),
             opaccredits                           => "" . C4::Context->preference("opaccredits"),
@@ -2023,7 +2035,24 @@ sub getborrowernumber {
     return 0;
 }
 
-END { }    # module clean-up code here (global destructor)
+=head2 get_user_printer
+
+  $printer = get_user_printer();
+
+  Returns printer queue that is to be used for the logged in user
+
+=cut
+
+sub get_user_printer {
+    my $userenv = C4::Context->userenv or return;
+    if (my $printer = $userenv->{branchprinter}) {
+        return $printer;
+    }
+    my $branchname = $userenv->{branch} or return;
+    my $branch = GetBranchDetail($branchname) or return;
+    return $branch->{branchprinter};
+}
+
 1;
 __END__
 
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 12ac19c..f4ea5bb 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -40,7 +40,6 @@ BEGIN {
 	@EXPORT = qw(
 		&slashifyDate
 		&subfield_is_koha_internal_p
-		&GetPrinters &GetPrinter
 		&GetItemTypes &getitemtypeinfo
                 &GetItemTypesCategorized &GetItemTypesByCategory
 		&GetSupportName &GetSupportList
@@ -672,45 +671,6 @@ sub getImageSets {
     return \@imagesets;
 }
 
-=head2 GetPrinters
-
-  $printers = &GetPrinters();
-  @queues = keys %$printers;
-
-Returns information about existing printer queues.
-
-C<$printers> is a reference-to-hash whose keys are the print queues
-defined in the printers table of the Koha database. The values are
-references-to-hash, whose keys are the fields in the printers table.
-
-=cut
-
-sub GetPrinters {
-    my %printers;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("select * from printers");
-    $sth->execute;
-    while ( my $printer = $sth->fetchrow_hashref ) {
-        $printers{ $printer->{'printqueue'} } = $printer;
-    }
-    return ( \%printers );
-}
-
-=head2 GetPrinter
-
-  $printer = GetPrinter( $query, $printers );
-
-=cut
-
-sub GetPrinter {
-    my ( $query, $printers ) = @_;    # get printer for this query from printers
-    my $printer = $query->param('printer');
-    my %cookie = $query->cookie('userenv');
-    ($printer) || ( $printer = $cookie{'printer'} ) || ( $printer = '' );
-    ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
-    return $printer;
-}
-
 =head2 getnbpages
 
 Returns the number of pages to display in a pagination bar, given the number
diff --git a/C4/Printer.pm b/C4/Printer.pm
new file mode 100644
index 0000000..e24c9b2
--- /dev/null
+++ b/C4/Printer.pm
@@ -0,0 +1,158 @@
+#!/usr/bin/perl
+
+package C4::Printer;
+
+# Copyright 2012 Catalyst IT
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use strict;
+use warnings;
+
+use C4::Context;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
+
+BEGIN {
+    $VERSION = 3.07.00.049;
+    require Exporter;
+    @ISA    = qw(Exporter);
+    @EXPORT = qw(
+    );
+    @EXPORT_OK = qw(
+        &GetPrinters &SearchPrinters &GetPrinterDetails
+        &AddPrinter &UpdatePrinter &DeletePrinter
+    );
+}
+
+=head1 NAME
+
+C4::Printer - functions that deal with printer selection
+
+=head1 SYNOPSIS
+
+  use C4::Printer;
+
+=head1 DESCRIPTION
+
+This module provides functions to select printer for slips etc.
+
+TODO: Move SQL from admin/printers.pl to this module
+
+=head1 FUNCTIONS
+
+=head2 GetPrinters
+
+  $printers = &GetPrinters();
+  @queues = keys %$printers;
+
+Returns information about existing printer queues.
+
+C<$printers> is a reference-to-hash whose keys are the print queues
+defined in the printers table of the Koha database. The values are
+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($PRINTER_SELECT_FROM);
+    $sth->execute;
+    while ( my $printer = $sth->fetchrow_hashref ) {
+        $printers{ $printer->{'printqueue'} } = $printer;
+    }
+    return ( \%printers );
+}
+
+=head2 SearchPrinters
+
+  $printers = SearchPrinters( $searchstring );
+
+=cut
+
+sub SearchPrinters {
+    my ($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
+
+  $printer_rec = GetPrinterDetails( $printqueue );
+
+=cut
+
+sub GetPrinterDetails {
+    my ( $printer ) = @_;
+    my $dbh = C4::Context->dbh;
+    return $dbh->selectrow_hashref(
+        "$PRINTER_SELECT_FROM
+         WHERE printqueue = ?",
+        undef, $printer);
+}
+
+=head2 AddPrinter
+
+  AddPrinter( $data );
+
+=cut
+
+sub AddPrinter {
+    my ( $data ) = @_;
+    my $dbh = C4::Context->dbh;
+    $dbh->do("INSERT INTO printers (printername,printqueue,printtype) VALUES (?,?,?)", undef,
+        $data->{printername}, $data->{printqueue}, $data->{printtype});
+}
+
+=head2 UpdatePrinter
+
+  UpdatePrinter( $printqueue, $data );
+
+=cut
+
+sub UpdatePrinter {
+    my ( $printqueue, $data ) = @_;
+    my $dbh = C4::Context->dbh;
+    $dbh->do("UPDATE printers SET printqueue = ?, printername = ?, printtype = ? WHERE printqueue = ?", undef,
+        $data->{printqueue}, $data->{printername}, $data->{printtype}, $printqueue);
+}
+
+=head2 DeletePrinter
+
+  DeletePrinter( $printqueue );
+
+=cut
+
+sub DeletePrinter {
+    my ( $printqueue ) = @_;
+    my $dbh = C4::Context->dbh;
+    $dbh->do("DELETE FROM printers WHERE printqueue = ?", undef,
+        $printqueue);
+}
+
+1;
diff --git a/admin/branches.pl b/admin/branches.pl
index 4a56f9d..d3a5158 100755
--- a/admin/branches.pl
+++ b/admin/branches.pl
@@ -45,6 +45,7 @@ use C4::Context;
 use C4::Output;
 use C4::Koha;
 use C4::Branch;
+use C4::Printer qw(GetPrinters);
 
 # Fixed variables
 my $script_name = "/cgi-bin/koha/admin/branches.pl";
@@ -228,13 +229,10 @@ sub default {
 
 sub editbranchform {
     my ($branchcode,$innertemplate) = @_;
-    # initiate the scrolling-list to select the printers
-    my $printers = GetPrinters();
-    my @printerloop;
+
     my $data;
     my $oldprinter = "";
 
-
     # make the checkboxes.....
     my $catinfo = GetBranchCategories();
 
@@ -260,15 +258,20 @@ sub editbranchform {
     }
     $innertemplate->param( categoryloop => $catinfo );
 
-    foreach my $thisprinter ( keys %$printers ) {
-        push @printerloop, {
-            value         => $thisprinter,
-            selected      => ( $oldprinter eq $printers->{$thisprinter} ),
-            branchprinter => $printers->{$thisprinter}->{'printqueue'},
-        };
-    }
+    if ( C4::Context->preference('UsePrintQueues') ) {
+        # initiate the scrolling-list to select the printers
+        my $printers = GetPrinters();
+        my @printerloop;
+        foreach my $thisprinter ( keys %$printers ) {
+            push @printerloop, {
+                value         => $thisprinter,
+                selected      => ( $oldprinter eq $thisprinter ),
+                branchprinter => $printers->{$thisprinter}->{'printername'},
+            };
+        }
 
-    $innertemplate->param( printerloop => \@printerloop );
+        $innertemplate->param( printerloop => \@printerloop );
+    }
 
     for my $obsolete ( 'categoryname', 'categorycode', 'codedescription' ) {
         $innertemplate->param(
@@ -304,6 +307,7 @@ sub branchinfotable {
 
     my ($branchcode,$innertemplate) = @_;
     my $branchinfo = $branchcode ? GetBranchInfo($branchcode) : GetBranchInfo();
+    my $printers = GetPrinters();
     my @loop_data = ();
     foreach my $branch (@$branchinfo) {
         #
@@ -363,6 +367,9 @@ sub branchinfotable {
         $row{'branch_name'} = $branch->{'branchname'};
         $row{'branch_code'} = $branch->{'branchcode'};
         $row{'value'}       = $branch->{'branchcode'};
+        if (my $printer = $branch->{'branchprinter'}) {
+            $row{'branchprintername'} = $printers->{$printer}->{'printername'};
+        }
 
         push @loop_data, \%row;
     }
diff --git a/admin/printers.pl b/admin/printers.pl
index 9e0163b..b0436bc 100755
--- a/admin/printers.pl
+++ b/admin/printers.pl
@@ -7,17 +7,17 @@
 # ALGO :
 # this script use an $op to know what to do.
 # if $op is empty or none of the above values,
-#	- the default screen is build (with all records, or filtered datas).
-#	- the   user can clic on add, modify or delete record.
+#   - the default screen is build (with all records, or filtered datas).
+#   - the   user can clic on add, modify or delete record.
 # if $op=add_form
-#	- if primkey exists, this is a modification,so we read the $primkey record
-#	- builds the add/modify form
+#   - if primkey exists, this is a modification,so we read the $primkey record
+#   - builds the add/modify form
 # if $op=add_validate
-#	- the user has just send datas, so we create/modify the record
+#   - the user has just send datas, so we create/modify the record
 # if $op=delete_form
-#	- we show the record having primkey=$primkey and ask for deletion validation form
+#   - we show the record having primkey=$primkey and ask for deletion validation form
 # if $op=delete_confirm
-#	- we delete the record having primkey=$primkey
+#   - we delete the record having primkey=$primkey
 
 
 # Copyright 2000-2002 Katipo Communications
@@ -43,19 +43,7 @@ use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Output;
 use C4::Auth;
-
-sub StringSearch  {
-	my ($searchstring,$type)=@_;		# why bother with $type if we don't use it?!
-	$searchstring=~ s/\'/\\\'/g;
-	my @data=split(' ',$searchstring);
-	my $sth = C4::Context->dbh->prepare("
-		SELECT printername,printqueue,printtype from printers 
-		WHERE (printername like ?) order by printername
-	");
-	$sth->execute("$data[0]%");
-	my $data=$sth->fetchall_arrayref({});
-	return (scalar(@$data),$data);
-}
+use C4::Printer qw(GetPrinterDetails SearchPrinters AddPrinter UpdatePrinter DeletePrinter);
 
 my $input = new CGI;
 my $searchfield=$input->param('searchfield');
@@ -78,75 +66,93 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user(
     }
 );
 
-$template->param(searchfield => $searchfield,
-		 script_name => $script_name);
-
 #start the page and read in includes
 
 my $dbh = C4::Context->dbh;
+my $list_printers = 1;
 ################## ADD_FORM ##################################
 # called by default. Used to create form to add or  modify a record
 if ($op eq 'add_form') {
-	$template->param(add_form => 1);
-	#---- if primkey exists, it's a modify action, so read values to modify...
-	my $data;
-	if ($searchfield) {
-		my $sth=$dbh->prepare("SELECT printername,printqueue,printtype from printers where printername=?");
-		$sth->execute($searchfield);
-		$data=$sth->fetchrow_hashref;
-	}
-
-	$template->param(printqueue => $data->{'printqueue'},
-			 printtype => $data->{'printtype'});
-													# END $OP eq ADD_FORM
+    $list_printers = 0;
+    $template->param(add_form => 1);
+    #---- if primkey exists, it's a modify action, so read values to modify...
+    my $data;
+    if ($searchfield) {
+        $data=GetPrinterDetails($searchfield);
+    }
+
+    $template->param(
+        printqueue => $data->{'printqueue'},
+        printername => $data->{'printername'},
+        printtype => $data->{'printtype'}
+    );
+# END $OP eq ADD_FORM
 ################## ADD_VALIDATE ##################################
 # called by add_form, used to insert/modify data in DB
 } elsif ($op eq 'add_validate') {
-	$template->param(add_validate => 1);
-	if ($input->param('add')){
-		my $sth=$dbh->prepare("INSERT INTO printers (printername,printqueue,printtype) VALUES (?,?,?)");
-		$sth->execute($input->param('printername'),$input->param('printqueue'),$input->param('printtype'));
-	} else {
-		my $sth=$dbh->prepare("UPDATE printers SET printqueue=?,printtype=? WHERE printername=?");
-		$sth->execute($input->param('printqueue'),$input->param('printtype'),$input->param('printername'));
-	}
-													# END $OP eq ADD_VALIDATE
+    my $params = $input->Vars;
+    if ($input->param('add')){
+        AddPrinter($params);
+    } else {
+        UpdatePrinter($searchfield, $params);
+    }
+    $template->param(add_validate => 1);
+    $searchfield = '';
+# END $OP eq ADD_VALIDATE
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
 } elsif ($op eq 'delete_confirm') {
-	$template->param(delete_confirm => 1);
-	my $sth=$dbh->prepare("select printername,printqueue,printtype from printers where printername=?");
-	$sth->execute($searchfield);
-	my $data=$sth->fetchrow_hashref;
-	$template->param(printqueue => $data->{'printqueue'},
-			 printtype  => $data->{'printtype'});
-													# END $OP eq DELETE_CONFIRM
+    $list_printers = 0;
+    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'},
+    );
+# END $OP eq DELETE_CONFIRM
 ################## DELETE_CONFIRMED ##################################
 # called by delete_confirm, used to effectively confirm deletion of data in DB
 } elsif ($op eq 'delete_confirmed') {
-	$template->param(delete_confirmed => 1);
-	my $sth=$dbh->prepare("delete from printers where printername=?");
-	$sth->execute($searchfield);
-													# END $OP eq DELETE_CONFIRMED
+    # XXX Delete can fail
+    DeletePrinter($searchfield);
+    $template->param(delete_confirmed => 1);
+    $template->param(list_printers => 1);
+    $searchfield = '';
+# END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ###########################################
 } else { # DEFAULT
-	$template->param(else => 1);
-	my ($count,$results)=StringSearch($searchfield,'web');
-	my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count;
-	my @loop = (@$results)[$offset..$max];
-	
-	$template->param(loop => \@loop);
-	
-	if ($offset>0) {
-		$template->param(offsetgtzero => 1,
-				 prevpage => $offset-$pagesize);
-	}
-	if ($offset+$pagesize<$count) {
-		$template->param(ltcount => 1,
-				 nextpage => $offset+$pagesize);
-	}
-
+    $searchfield ||= $input->param('description') || "";
 } #---- END $OP eq DEFAULT
 
+if ($list_printers) {
+    $template->param(list_printers => 1);
+    my $results=SearchPrinters($searchfield);
+    my $count = $results ? scalar(@$results) : 0;
+    my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count;
+    my @loop = (@$results)[$offset..$max-1];
+
+    $template->param(loop => \@loop);
+
+    if ($offset>0) {
+        $template->param(offsetgtzero => 1,
+                 prevpage => $offset-$pagesize);
+    }
+    if ($offset+$pagesize<$count) {
+        $template->param(ltcount => 1,
+                 nextpage => $offset+$pagesize);
+    }
+}
+
+$template->param(
+    searchfield => $searchfield,
+    script_name => $script_name
+);
+
 output_html_with_http_headers $input, $cookie, $template->output;
 
diff --git a/circ/circulation.pl b/circ/circulation.pl
index 5747fbf..9ee6849 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -31,7 +31,7 @@ use C4::Output;
 use C4::Print;
 use C4::Auth qw/:DEFAULT get_session haspermission/;
 use C4::Branch; # GetBranches
-use C4::Koha;   # GetPrinter
+use C4::Koha;
 use C4::Circulation;
 use C4::Utils::DataTables::Members;
 use C4::Members;
@@ -73,12 +73,6 @@ if ($branch){
     $session->param('branchname', GetBranchName($branch));
 }
 
-my $printer = $query->param('printer');
-if ($printer){
-    # update our session so the userenv is updated
-    $session->param('branchprinter', $printer);
-}
-
 if (!C4::Context->userenv && !$branch){
     if ($session->param('branch') eq 'NO_LIBRARY_SET'){
         # no branch set we can't issue
@@ -153,7 +147,6 @@ my $findborrower = $query->param('findborrower') || q{};
 $findborrower =~ s|,| |g;
 
 $branch  = C4::Context->userenv->{'branch'};  
-$printer = C4::Context->userenv->{'branchprinter'};
 
 # If AutoLocation is not activated, we show the Circulation Parameters to chage settings of librarian
 if (C4::Context->preference("AutoLocation") != 1) {
@@ -600,8 +593,6 @@ $template->param(
     categoryname      => $borrower->{'description'},
     branch            => $branch,
     branchname        => GetBranchName($borrower->{'branchcode'}),
-    printer           => $printer,
-    printername       => $printer,
     was_renewed       => $query->param('was_renewed') ? 1 : 0,
     expiry            => $borrower->{'dateexpiry'},
     roadtype          => $roadtype,
diff --git a/circ/returns.pl b/circ/returns.pl
index f7fb52c..8d020bc 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -39,7 +39,6 @@ use C4::Context;
 use C4::Auth qw/:DEFAULT get_session/;
 use C4::Output;
 use C4::Circulation;
-use C4::Print;
 use C4::Reserves;
 use C4::Biblio;
 use C4::Items;
@@ -83,16 +82,11 @@ if ( $query->param('print_slip') ) {
 #####################
 #Global vars
 my $branches = GetBranches();
-my $printers = GetPrinters();
 my $userenv = C4::Context->userenv;
 my $userenv_branch = $userenv->{'branch'} // '';
-my $printer = $userenv->{'branchprinter'} // '';
 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
 
 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
-#
-# Some code to handle the error if there is no branch or printer setting.....
-#
 
 # Set up the item stack ....
 my %returneditems;
@@ -600,19 +594,14 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
     }
     push @riloop, \%ri;
 }
-my ($genbrname, $genprname);
+my $genbrname;
 if (my $b = $branches->{$userenv_branch}) {
     $genbrname = $b->{'branchname'};
 }
-if (my $p = $printers->{$printer}) {
-    $genprname = $p->{'printername'};
-}
 $template->param(
     riloop         => \@riloop,
     genbrname      => $genbrname,
-    genprname      => $genprname,
     branchname     => $genbrname,
-    printer        => $printer,
     errmsgloop     => \@errmsgloop,
     exemptfine     => $exemptfine,
     dropboxmode    => $dropboxmode,
diff --git a/circ/selectbranchprinter.pl b/circ/selectbranchprinter.pl
index 7c0c6d7..1f53dc0 100755
--- a/circ/selectbranchprinter.pl
+++ b/circ/selectbranchprinter.pl
@@ -23,10 +23,10 @@ use CGI qw ( -utf8 );
 
 use C4::Context;
 use C4::Output;
-use C4::Auth qw/:DEFAULT get_session/;
-use C4::Print;  # GetPrinters
+use C4::Auth qw/:DEFAULT get_session get_user_printer/;
 use C4::Koha;
 use C4::Branch; # GetBranches GetBranchesLoop
+use C4::Printer qw(GetPrinters);
 
 # this will be the script that chooses branch and printer settings....
 
@@ -56,9 +56,10 @@ my $userenv_printer = C4::Context->userenv->{'branchprinter'} || '';
 my @updated;
 
 # $session lddines here are doing the updating
-if ($branch and $branches->{$branch}) {
+my $branch_rec = $branch ? $branches->{$branch} : undef;
+if ($branch_rec) {
     if (! $userenv_branch or $userenv_branch ne $branch ) {
-        my $branchname = GetBranchName($branch);
+        my $branchname = $branch_rec->{branchname};
         $template->param(LoginBranchname => $branchname);   # update template for new branch
         $template->param(LoginBranchcode => $branch);       # update template for new branch
         $session->param('branchname', $branchname);         # update sesssion in DB
@@ -67,6 +68,8 @@ if ($branch and $branches->{$branch}) {
             updated_branch => 1,
                 old_branch => $userenv_branch,
         };
+        $printer ||= $branch_rec->{branchprinter};
+        undef $userenv_printer;
     } # else branch the same, no update
 } else {
     $branch = $userenv_branch;  # fallback value
@@ -87,7 +90,7 @@ if ($printer) {
         };
     } # else printer is the same, no update
 } else {
-    $printer = $userenv_printer;  # fallback value
+    $printer = get_user_printer();  # fallback value
 }
 
 $template->param(updated => \@updated) if (scalar @updated);
@@ -96,21 +99,6 @@ unless ($branches->{$branch}) {
     $branch = (keys %$branches)[0];  # if branch didn't really exist, then replace it w/ one that does
 }
 
-my @printkeys = sort keys %$printers;
-if (scalar(@printkeys) == 1 or not $printers->{$printer}) {
-    $printer = $printkeys[0];   # if printer didn't really exist, or there is only 1 anyway, then replace it w/ one that does
-}
-
-my @printerloop;
-foreach ( @printkeys ) {
-    next unless ($_); # skip printer if blank.
-    push @printerloop, {
-        selected => ( $_ eq $printer ),
-        name     => $printers->{$_}->{'printername'},
-        value    => $_,
-    };
-}
-
 my @recycle_loop;
 foreach ($query->param()) {
     $_ or next;                   # disclude blanks
@@ -133,9 +121,28 @@ if (scalar @updated and not scalar @recycle_loop) {
 
 $template->param(
     referer     => $referer,
-    printerloop => \@printerloop,
     branchloop  => GetBranchesLoop($branch),
     recycle_loop=> \@recycle_loop,
 );
 
+if ( C4::Context->preference('UsePrintQueues') ) {
+    my @printkeys = keys %$printers;
+    if (scalar(@printkeys) == 1 or not $printers->{$printer}) {
+        $printer = $printkeys[0];   # if printer didn't really exist, or there is only 1 anyway, then replace it w/ one that does
+    }
+
+    my @printerloop;
+    foreach ( @printkeys ) {
+        push @printerloop, {
+            selected => ( $_ eq $printer ),
+            name     => $printers->{$_}->{'printername'},
+            value    => $_,
+        };
+    }
+
+    $template->param(
+        printerloop => \@printerloop,
+    );
+}
+
 output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/installer/data/mysql/atomicupdate/bug_8034_printer_queues.sql b/installer/data/mysql/atomicupdate/bug_8034_printer_queues.sql
new file mode 100644
index 0000000..cb0a599
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_8034_printer_queues.sql
@@ -0,0 +1,8 @@
+ALTER TABLE printers DROP PRIMARY KEY;
+ALTER TABLE printers MODIFY printqueue varchar(20) NOT NULL PRIMARY KEY;
+ALTER TABLE printers ADD UNIQUE (printername);
+
+ALTER TABLE branches MODIFY branchprinter varchar(20) NULL;
+ALTER TABLE branches ADD FOREIGN KEY (branchprinter) REFERENCES printers (printqueue) ON UPDATE CASCADE;
+
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('UsePrintQueues','0',NULL,NULL,'YesNo');
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 431a541..8661d6a 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -413,10 +413,11 @@ CREATE TABLE `branches` ( -- information about your libraries or branches are st
   `branchurl` mediumtext, -- the URL for your library or branch's website
   `issuing` tinyint(4) default NULL, -- unused in Koha
   `branchip` varchar(15) default NULL, -- the IP address for your library or branch
-  `branchprinter` varchar(100) default NULL, -- unused in Koha
+  `branchprinter` varchar(20) default NULL,
   `branchnotes` mediumtext, -- notes related to your library or branch
   opac_info text, -- HTML that displays in OPAC
-  PRIMARY KEY (`branchcode`)
+  PRIMARY KEY (`branchcode`),
+  FOREIGN KEY (branchprinter) REFERENCES printers (printqueue) ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
@@ -1774,13 +1775,14 @@ CREATE TABLE pending_offline_operations (
 -- Table structure for table `printers`
 --
 
-DROP TABLE IF EXISTS `printers`;
-CREATE TABLE `printers` (
-  `printername` varchar(40) NOT NULL default '',
-  `printqueue` varchar(20) default NULL,
-  `printtype` varchar(20) default NULL,
-  PRIMARY KEY  (`printername`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+DROP TABLE IF EXISTS printers;
+CREATE TABLE printers (
+  printername varchar(40) NOT NULL default '',
+  printqueue varchar(20) NOT NULL,
+  printtype varchar(20) default NULL,
+  PRIMARY KEY  (printqueue),
+  UNIQUE (printername)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 --
 -- Table structure for table `printers_profile`
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index aa53139..8259ac7 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -501,6 +501,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('useDischarge','','','Allows librarians to discharge borrowers and borrowers to request a discharge','YesNo'),
 ('UseICU','0','1','Tell Koha if ICU indexing is in use for Zebra or not.','YesNo'),
 ('UseKohaPlugins','0','','Enable or disable the ability to use Koha Plugins.','YesNo'),
+('UsePrintQueues','0',NULL,'Use printer queues','YesNo'),
 ('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
 ('UseTransportCostMatrix','0','','Use Transport Cost Matrix when filling holds','YesNo'),
 ('UseWYSIWYGinSystemPreferences','0','','Show WYSIWYG editor when editing certain HTML system preferences.','YesNo'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
index 6e6fa49..b75ae25 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
@@ -67,7 +67,7 @@
 <h5>Additional parameters</h5>
 
 <ul>
-    <!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
+    [% IF UsePrintQueues %]<li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li>[% END %]
     <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
     <li><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></li>
     <li><a href="/cgi-bin/koha/admin/columns_settings.pl">Columns settings</a></li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
index 50b348b..3167c98 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
@@ -59,6 +59,9 @@
                     [% END %]
                     </strong>
                     [% END %]
+                    [% IF UsePrintQueues && PrinterName %]
+                    - [% PrinterName %]
+                    [% END %]
                     <b class="caret"></b>
                 </a>
                 <ul class="dropdown-menu" role="menu" aria-labelledby="drop3">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
index 633b3cc..8ee4d42 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
@@ -100,8 +100,10 @@
 
                 <h3>Additional parameters</h3>
                 <dl>
-                    <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
-                    <dd>Printers (UNIX paths).</dd> -->
+                [% IF UsePrintQueues %]
+                    <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
+                    <dd>Printers (UNIX paths).</dd>
+                [% END %]
                     <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
                     <dd>Define which external servers to query for MARC data.</dd>
                     <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
index 29b54b9..23c9692 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
@@ -143,10 +143,10 @@ tinyMCE.init({
         <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl"  size="80" value="[% branchurl |html %]" class="url" /></li>
         <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% opac_info |html %]</textarea></li>
         <li><label for="branchip">IP: </label><input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% branchip |html %]" /> <span class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</span></li>
-		<!--
+[% IF UsePrintQueues %]
         <li><label for="branchprinter">Library Printer: </label>
             <select id="branchprinter" name="branchprinter">
-                <option value="">None</option>
+                <option value="">(None)</option>
             [% FOREACH printerloo IN printerloop %]
                 [% IF ( printerloo.selected ) %]
 				<option value="[% printerloo.value %]" selected="selected">[% printerloo.branchprinter %]</option>
@@ -155,7 +155,7 @@ tinyMCE.init({
 				[% END %]
                 [% END %]
             </select></li>
-			-->
+[% END %]
         <li><label for="branchnotes">Notes: </label><input type="text" name="branchnotes" id="branchnotes" size="80" value="[% branchnotes |html %]" /></li>
         </ol>
         </fieldset>
@@ -195,7 +195,9 @@ tinyMCE.init({
             <th>Address</th>
             <th>Properties</th>
             <th>IP</th>
-            <!-- <th>Printer</th> -->
+[% IF UsePrintQueues %]
+            <th>Printer</th>
+[% END %]
             <th> </th>
             <th> </th>
         </tr></thead><tbody>
@@ -244,9 +246,11 @@ tinyMCE.init({
                 <td>
                     [% branche.branchip %]
                 </td>
-                <!-- <td>
-                    [% branche.branchprinter %]
-                </td> -->
+[% IF UsePrintQueues %]
+                <td>
+                    [% branche.branchprintername %]
+                </td>
+[% END %]
                 <td>
                     <a href="[% branche.action %]?op=edit&branchcode=[% branche.value |url %]">Edit</a>
                 </td>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index d9c7e25..fd6cf70 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -117,6 +117,12 @@ Circulation:
                   no: "Do not"
             - update a bibliographic record's total issues count whenever an item is issued (WARNING! This increases server load significantly; if performance is a concern, use the update_totalissues.pl cron job to update the total issues count).
         -
+            - pref: UsePrintQueues
+              choices:
+                  yes: "Use"
+                  no: "Don't use"
+            - server print queues.
+        -
             - Use the
             - pref: ExportWithCsvProfile
             - CSV profile when exporting patron checkout history (enter CSV Profile name)
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 62c0258..a67c88a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt
@@ -4,7 +4,7 @@
 [% IF ( add_validate ) %] Printers › Printer added[% END %]
 [% IF ( delete_confirm ) %] Printers › Confirm deletion of printer '[% searchfield %]'[% END %]
 [% IF ( delete_confirmed ) %] Printers › Printer deleted[% END %]
-[% IF ( else ) %]Printers[% END %]</title>
+[% IF ( list_printers ) %]Printers[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% IF ( add_form ) %]<script type="text/javascript">
 //<![CDATA[
@@ -58,7 +58,7 @@
 [% IF ( add_validate ) %] <a href="/cgi-bin/koha/admin/printers.pl">Printers</a> › Printer added[% END %]
 [% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/admin/printers.pl">Printers</a> › Confirm deletion of printer '[% searchfield %]'[% END %]
 [% IF ( delete_confirmed ) %] <a href="/cgi-bin/koha/admin/printers.pl">Printers</a> › Printer deleted[% END %]
-[% IF ( else ) %]Printers[% END %]</div>
+[% IF ( list_printers ) %]Printers[% END %]</div>
 
 <div id="doc3" class="yui-t2">
    
@@ -76,22 +76,17 @@
         <form action="[% script_name %]" name="Aform" method="post">
         <input type="hidden" name="op" value="add_validate" />
 	[% IF ( searchfield ) %]
+          <input type="hidden" name="searchfield" value="[% searchfield %]" />
 		<input type="hidden" name="add" value="0" />
 	[% ELSE %]
 		<input type="hidden" name="add" value="1" />
 	[% END %]
 	<fieldset class="rows">
-<ol>	[% IF ( searchfield ) %]
-		<li>
-            <span class="label">Printer name: </span>
-				<input type="hidden" name="printername" id="" value="[% searchfield %]" />[% searchfield %]
-		</li>
-	[% ELSE %]
+<ol>
 		<li>
             <label for="printername">Printer name: </label>
-				<input type="text" name="printername" id="printername" size="50" maxlength="50" />
+                             <input type="text" name="printername" id="printername" size="50" maxlength="50" value="[% printername %]" />
 		</li>
-	[% END %]
         	<li>
 			<label for="printqueue">Queue: </label>
 			<input type="text" name="printqueue" id="printqueue" size="50" maxlength="50" value="[% printqueue %]" /> 
@@ -106,13 +101,6 @@
 
 [% END %]
 
-[% IF ( add_validate ) %]
-<h3>Printer added</h3>
-<form action="[% script_name %]" method="post">
-       <fieldset class="action"> <input type="submit" value="OK" /></fieldset>
-</form>
-[% END %]
-
 [% IF ( delete_confirm ) %]
 <h3>Confirm deletion of printer <em>[% searchfield %]</em></h3>
 <ul>
@@ -138,14 +126,7 @@
 			</form>
 [% END %]
 
-[% IF ( delete_confirmed ) %]
-<h3>Printer deleted</h3>
-<form action="[% script_name %]" method="post">
-		<fieldset class="action"><input type="submit" value="OK" /></fieldset>
-</form>
-[% END %]
-
-[% IF ( else ) %]
+[% IF ( list_printers ) %]
 
 <div id="toolbar" class="btn-toolbar">
     <a class="btn btn-small" id="newprinter" href="/cgi-bin/koha/admin/printers.pl?op=add_form"><i class="fa fa-plus"></i> New printer</a>
@@ -168,7 +149,14 @@
 			<td>[% loo.printername %]</td>
 			<td>[% loo.printqueue %]</td>
 			<td>[% loo.printtype %]</td>
-			<td><a href="[% loo.script_name %]?op=add_form&searchfield=[% loo.printername %]">Edit</a> <a href="[% loo.script_name %]?op=delete_confirm&searchfield=[% loo.printername %]">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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
index 7c5573a..41bef03 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
@@ -559,7 +559,6 @@ No patron matched <span class="ex">[% message %]</span>
 
 [% IF (forceallow) %]<input type="hidden" name="forceallow" value="1">[% END %]
     <input type="hidden" name="branch" value="[% branch %]" />
-    <input type="hidden" name="printer" value="[% printer %]" />
     <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
     <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
 
@@ -678,7 +677,6 @@ No patron matched <span class="ex">[% message %]</span>
 
           <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
           <input type="hidden" name="branch" value="[% branch %]" />
-          <input type="hidden" name="printer" value="[% printer %]" />
           <input type="hidden" name="print" value="maybe" />
           <input type="hidden" name="debt_confirmed" value="[% debt_confirmed %]" />
                 [% IF ( CHARGES ) %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectbranchprinter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectbranchprinter.tt
index faaa963..261e529 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectbranchprinter.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectbranchprinter.tt
@@ -28,7 +28,7 @@ Updated:<ul>
     [% IF ( update.updated_branch ) %]
         <li>Library: [% update.old_branch or "?" %] ⇒ [% update.LoginBranchcode or "?" %]</li>
     [% ELSIF ( update.updated_printer ) %]
-      <!-- FIXME:  <li>Printer: [% update.old_printer or "?" %] ⇒ [% update.new_printer or "?" %]</li> -->
+        <li>Printer: [% update.old_printer or "?" %] ⇒ [% update.new_printer or "?" %]</li>
     [% ELSE %]
         <li>ERROR - unknown</li>
     [% END %]
@@ -63,7 +63,6 @@ Updated:<ul>
         [% END %]
         </select></li>
     [% END %]
-<!--
     [% IF ( printerloop ) %]
         <li><label for="printer">Choose a network printer:</label>
         <select name="printer" id="printer">
@@ -75,7 +74,7 @@ Updated:<ul>
                 [% END %]
             [% END %]
         </select></li>
-    [% END %] -->
+    [% END %]
     </ol>
 </fieldset>
 <fieldset class="action">
diff --git a/t/db_dependent/Printer.t b/t/db_dependent/Printer.t
new file mode 100644
index 0000000..e779b90
--- /dev/null
+++ b/t/db_dependent/Printer.t
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+
+use Koha::Database;
+use Data::Dumper;
+
+use Test::More tests => 7;
+
+my $TEST_PRINTER_QUEUE = "TEST_PRINTER_QUEUE";
+my %TEST_PRINTER = (
+    printqueue => $TEST_PRINTER_QUEUE,
+    printername => "Test printer",
+    printtype => "Some string",
+);
+my $UPDATED_NAME = "Updated Test printer";
+
+use_ok("C4::Printer");
+
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
+
+C4::Printer::AddPrinter(\%TEST_PRINTER);
+pass("AddPrinter");
+
+C4::Printer::UpdatePrinter($TEST_PRINTER_QUEUE, {%TEST_PRINTER, printername => $UPDATED_NAME});
+
+my $p = C4::Printer::GetPrinterDetails($TEST_PRINTER_QUEUE);
+my $found = $p && $p->{printqueue} eq $TEST_PRINTER_QUEUE;
+ok($found, "GetPrinterDetails") or diag(Dumper($p));
+
+SKIP: {
+    skip 1, "Cannot find printer" unless $found;
+
+    is($p->{printername}, $UPDATED_NAME, "UpdatePrinter")
+      or diag(Dumper($p));
+}
+
+my $printers = C4::Printer::GetPrinters();
+$found = 0;
+while (my ($q, $p) = each %$printers) {
+    if ($q eq $TEST_PRINTER_QUEUE) {
+        $found = $p->{printername} eq $UPDATED_NAME;
+        last;
+    }
+}
+ok($found, "GetPrinters") or diag(Dumper($printers));
+
+$printers = C4::Printer::SearchPrinters("TEST");
+$found = 0;
+foreach $p (@$printers) {
+    if ($p->{printqueue} eq $TEST_PRINTER_QUEUE) {
+        $found = $p->{printername} eq $UPDATED_NAME;
+        last;
+    }
+}
+ok($found, "SearchPrinters") or diag(Dumper($printers));
+
+C4::Printer::DeletePrinter($TEST_PRINTER_QUEUE);
+$p = C4::Printer::GetPrinterDetails($TEST_PRINTER_QUEUE);
+$found = $p && $p->{printqueue} eq $TEST_PRINTER_QUEUE;
+ok(!$found, "DeletePrinter") or diag(Dumper($p));
+
+$schema->storage->txn_rollback();
-- 
1.9.1


More information about the Koha-patches mailing list