View | Details | Raw Unified | Return to bug 8352
Collapse All | Expand All

(-)a/Koha/Object.pm (+12 lines)
Lines 207-212 sub id { Link Here
207
    return $id;
207
    return $id;
208
}
208
}
209
209
210
=head3 $object->unblessed();
211
212
Returns an unblessed representation of object.
213
214
=cut
215
216
sub unblessed {
217
    my ($self) = @_;
218
219
    return { $self->_result->get_columns };
220
}
221
210
=head3 $object->_result();
222
=head3 $object->_result();
211
223
212
Returns the internal DBIC Row object
224
Returns the internal DBIC Row object
(-)a/Koha/Objects.pm (+13 lines)
Lines 181-186 sub as_list { Link Here
181
    return wantarray ? @objects : \@objects;
181
    return wantarray ? @objects : \@objects;
182
}
182
}
183
183
184
=head3 Koha::Objects->unblessed
185
186
Returns an unblessed representation of objects.
187
188
=cut
189
190
sub unblessed {
191
    my ($self) = @_;
192
193
    return [ map { $_->unblessed } $self->as_list ];
194
}
195
196
184
=head3 Koha::Objects->_wrap
197
=head3 Koha::Objects->_wrap
185
198
186
wraps the DBIC object in a corresponding Koha object
199
wraps the DBIC object in a corresponding Koha object
(-)a/Koha/Printer.pm (+114 lines)
Line 0 Link Here
1
package Koha::Printer;
2
3
# Copyright ByWater Solutions 2014
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Printer - Koha Printer Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 print
39
40
$printer->print( { data => $data, is_html => $is_html } );
41
42
=cut
43
44
sub print {
45
    my ( $self, $params ) = @_;
46
47
    my $data    = $params->{data};
48
    my $is_html = $params->{is_html};
49
50
    return unless ($data);
51
52
    if ($is_html) {
53
        require HTML::HTMLDoc;
54
        my $htmldoc = new HTML::HTMLDoc();
55
        $htmldoc->set_output_format('ps');
56
        $htmldoc->set_html_content($data);
57
        my $doc = $htmldoc->generate_pdf();
58
        $data = $doc->to_string();
59
    }
60
61
    my ( $result, $error );
62
63
    if ( $self->queue() =~ /:/ ) {
64
65
        # Printer has a server:port address, use Net::Printer
66
        require Net::Printer;
67
68
        my ( $server, $port ) = split( /:/, $self->queue() );
69
70
        my $printer = new Net::Printer(
71
            printer     => $self->name(),
72
            server      => $server,
73
            port        => $port,
74
            lineconvert => "YES"
75
        );
76
77
        $result = $printer->printstring($data);
78
79
        $error = $printer->printerror();
80
    }
81
    else {
82
        require Printer;
83
84
        my $printer_name = $self->name();
85
86
        my $printer = new Printer( 'linux' => 'lp' );
87
        $printer->print_command(
88
            linux => {
89
                type    => 'pipe',
90
                command => "lp -d $printer_name",
91
            }
92
        );
93
94
        $result = $printer->print($data);
95
    }
96
97
    return ( $result eq '1', $error );
98
}
99
100
=head3 type
101
102
=cut
103
104
sub type {
105
    return 'Printer';
106
}
107
108
=head1 AUTHOR
109
110
Kyle M Hall <kyle@bywatersolutions.com>
111
112
=cut
113
114
1;
(-)a/Koha/Printers.pm (+58 lines)
Line 0 Link Here
1
package Koha::Printers;
2
3
# Copyright ByWater Solutions 2014
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Printer;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Printer - Koha Printer Object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'Printer';
46
}
47
48
sub object_class {
49
    return 'Koha::Printer';
50
}
51
52
=head1 AUTHOR
53
54
Kyle M Hall <kyle@bywatersolutions.com>
55
56
=cut
57
58
1;
(-)a/Koha/Schema/Result/Printer.pm (-56 lines)
Lines 61-120 __PACKAGE__->set_primary_key("id"); Link Here
61
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2014-05-19 09:04:19
61
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2014-05-19 09:04:19
62
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uapO0jjBiwFJZjpbJMas/g
62
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uapO0jjBiwFJZjpbJMas/g
63
63
64
sub print {
65
    my ( $self, $params ) = @_;
66
67
    my $data    = $params->{data};
68
    my $is_html = $params->{is_html};
69
70
    return unless ($data);
71
72
    if ($is_html) {
73
        require HTML::HTMLDoc;
74
        my $htmldoc = new HTML::HTMLDoc();
75
        $htmldoc->set_output_format('ps');
76
        $htmldoc->set_html_content($data);
77
        my $doc = $htmldoc->generate_pdf();
78
        $data = $doc->to_string();
79
    }
80
81
    my ( $result, $error );
82
83
    if ( $self->queue() =~ /:/ ) {
84
85
        # Printer has a server:port address, use Net::Printer
86
        require Net::Printer;
87
88
        my ( $server, $port ) = split( /:/, $self->queue() );
89
90
        my $printer = new Net::Printer(
91
            printer     => $self->name(),
92
            server      => $server,
93
            port        => $port,
94
            lineconvert => "YES"
95
        );
96
97
        $result = $printer->printstring($data);
98
99
        $error = $printer->printerror();
100
    }
101
    else {
102
        require Printer;
103
104
        my $printer_name = $self->name();
105
106
        my $printer = new Printer( 'linux' => 'lp' );
107
        $printer->print_command(
108
            linux => {
109
                type    => 'pipe',
110
                command => "lp -d $printer_name",
111
            }
112
        );
113
114
        $result = $printer->print($data);
115
    }
116
117
    return ( $result eq '1', $error );
118
}
119
120
1;
64
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/printers.tt (-3 lines)
Lines 23-29 $(document).ready(function() { Link Here
23
                    { "sWidth": "5%"  },
23
                    { "sWidth": "5%"  },
24
                    { "sWidth": "40%" },
24
                    { "sWidth": "40%" },
25
                    { "sWidth": "55%" },
25
                    { "sWidth": "55%" },
26
                    { "bVisible": false },
27
                ],
26
                ],
28
                "oLanguage"          : {
27
                "oLanguage"          : {
29
                    "oPaginate": {
28
                    "oPaginate": {
Lines 56-62 $(document).ready(function() { Link Here
56
                    if ( printerID == "NA") {
55
                    if ( printerID == "NA") {
57
                        $('td', nRow)[0].setAttribute("id","no_edit");
56
                        $('td', nRow)[0].setAttribute("id","no_edit");
58
                        $('td', nRow)[1].setAttribute("id","no_edit");
57
                        $('td', nRow)[1].setAttribute("id","no_edit");
59
                        $('td', nRow)[2].setAttribute("id","no_edit");
60
                    }
58
                    }
61
                    else {
59
                    else {
62
                        $('td', nRow)[0].setAttribute("id","no_edit");
60
                        $('td', nRow)[0].setAttribute("id","no_edit");
Lines 198-204 $(document).ready(function() { Link Here
198
                            <th><span style="cursor: help" onclick="event.stopPropagation();alert(MSG_ID_HELP);">ID</span></th>
196
                            <th><span style="cursor: help" onclick="event.stopPropagation();alert(MSG_ID_HELP);">ID</span></th>
199
                            <th>Name</th>
197
                            <th>Name</th>
200
                            <th>Server:Port</th>
198
                            <th>Server:Port</th>
201
                            <th>Type</th>
202
                        </tr>
199
                        </tr>
203
                    </thead>
200
                    </thead>
204
                </table>
201
                </table>
(-)a/misc/cronjobs/holds/print_holds.pl (-37 / +29 lines)
Lines 1-12 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2009-2010 Kyle Hall
3
# Copyright 2015 ByWater Solutions
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
10
# version.
11
#
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
Lines 31-46 use Getopt::Long; Link Here
31
use Pod::Usage;
31
use Pod::Usage;
32
use Net::Printer;
32
use Net::Printer;
33
33
34
use C4::Context;
35
use C4::Members qw(GetMember);
36
use C4::Letters qw(GetPreparedLetter);
34
use C4::Letters qw(GetPreparedLetter);
37
use Koha::Database;
35
36
use Koha::DateUtils;
37
use Koha::Holds;
38
use Koha::Printers;
39
use Koha::Borrowers;
38
40
39
my $help    = 0;
41
my $help    = 0;
40
my $test    = 0;
42
my $test    = 0;
41
my $verbose = 0;
43
my $verbose = 0;
42
my $confirm = 0;
44
my $confirm = 0;
43
my @printers;
45
my @printers;
46
44
GetOptions(
47
GetOptions(
45
    "help|?"      => \$help,
48
    "help|?"      => \$help,
46
    "verbose|v"   => \$verbose,
49
    "verbose|v"   => \$verbose,
Lines 48-107 GetOptions( Link Here
48
    "confirm|c"   => \$confirm,
51
    "confirm|c"   => \$confirm,
49
    "printer|p=s" => \@printers,
52
    "printer|p=s" => \@printers,
50
);
53
);
54
51
pod2usage(1) if $help;
55
pod2usage(1) if $help;
52
pod2usage(1) unless @printers;
56
pod2usage(1) unless @printers;
53
pod2usage(1) unless ( $test || $confirm );
57
pod2usage(1) unless ( $test || $confirm );
54
pod2usage(1) if ( $test && $confirm );
58
pod2usage(1) if ( $test && $confirm );
55
59
56
my $schema = Koha::Database->new()->schema();
57
58
my %printers;
60
my %printers;
59
foreach my $p (@printers) {
61
foreach my $p (@printers) {
60
    my ( $branchcode, $printer_id ) = split( /:/, $p );
62
    my ( $branchcode, $printer_id ) = split( /:/, $p );
61
    $printers{$branchcode} = $schema->resultset('Printer')->find($printer_id);
63
    $printers{$branchcode} = Koha::Printers->find($printer_id);
62
}
64
}
63
65
64
my $dbh   = C4::Context->dbh;
66
my $holds = Koha::Holds->search( { printed => undef } );
65
my $query = "SELECT * FROM reserves WHERE printed IS NULL";
66
my $sth   = $dbh->prepare($query);
67
$sth->execute();
68
69
my $set_printed_query = "
70
    UPDATE reserves
71
    SET printed = NOW()
72
    WHERE reserve_id = ?
73
";
74
my $set_printed_sth = $dbh->prepare($set_printed_query);
75
67
76
while ( my $hold = $sth->fetchrow_hashref() ) {
68
while ( my $hold = $holds->next() ) {
77
    if ($verbose) {
69
    if ($verbose) {
78
        say "\nFound Notice to Print";
70
        say "\nFound Notice to Print";
79
        say "Borrowernumber: " . $hold->{'borrowernumber'};
71
        say "Borrowernumber: " . $hold->borrowernumber;
80
        say "Biblionumber: " . $hold->{'biblionumber'};
72
        say "Biblionumber: " . $hold->biblionumber;
81
        say "Branch: " . $hold->{'branchcode'};
73
        say "Branch: " . $hold->branchcode;
82
    }
74
    }
83
75
84
    my $borrower =
76
    my $borrower = Koha::Borrowers->find( $hold->borrowernumber );
85
      C4::Members::GetMember( 'borrowernumber' => $hold->{'borrowernumber'} );
86
77
87
    my $letter = GetPreparedLetter(
78
    my $letter = GetPreparedLetter(
88
        module      => 'reserves',
79
        module      => 'reserves',
89
        letter_code => 'HOLD_PLACED_PRINT',
80
        letter_code => 'HOLD_PLACED_PRINT',
90
        branchcode  => $hold->{branchcode},
81
        branchcode  => $hold->branchcode,
91
        tables      => {
82
        tables      => {
92
            branches    => $hold->{'branchcode'},
83
            branches    => $hold->branchcode,
93
            biblio      => $hold->{'biblionumber'},
84
            biblio      => $hold->biblionumber,
94
            biblioitems => $hold->{'biblionumber'},
85
            biblioitems => $hold->biblionumber,
95
            items       => $hold->{'itemnumber'},
86
            items       => $hold->itemnumber,
96
            borrowers   => $borrower,
87
            borrowers   => $borrower->unblessed,
97
            reserves    => $hold,
88
            reserves    => $hold->unblessed,
98
89
99
        }
90
        }
100
    );
91
    );
101
92
102
    if ( defined( $printers{ $hold->{branchcode} } ) ) {
93
    if ( defined( $printers{ $hold->branchcode } ) ) {
103
        unless ($test) {
94
        unless ($test) {
104
            my ( $success, $error ) = $printers{ $hold->{'branchcode'} }->print(
95
            my ( $success, $error ) = $printers{ $hold->branchcode }->print(
105
                {
96
                {
106
                    data    => $letter->{content},
97
                    data    => $letter->{content},
107
                    is_html => $letter->{is_html},
98
                    is_html => $letter->{is_html},
Lines 109-115 while ( my $hold = $sth->fetchrow_hashref() ) { Link Here
109
            );
100
            );
110
101
111
            if ($success) {
102
            if ($success) {
112
                $set_printed_sth->execute( $hold->{'reserve_id'} );
103
                my $ts = output_pref( { dt => dt_from_string(), dateformat => 'iso', timeformat => '24h' } );
104
                $hold->printed($ts);
105
                $hold->store();
113
            }
106
            }
114
            else {
107
            else {
115
                warn "ERROR: $error";
108
                warn "ERROR: $error";
Lines 121-128 while ( my $hold = $sth->fetchrow_hashref() ) { Link Here
121
        }
114
        }
122
    }
115
    }
123
    else {
116
    else {
124
        say "WARNING: No printer defined for branchcode "
117
        say "WARNING: No printer defined for branchcode " . $hold->branchcode
125
          . $hold->{'branchcode'}
126
          if ($verbose);
118
          if ($verbose);
127
    }
119
    }
128
120
(-)a/svc/printer (-56 / +23 lines)
Lines 18-57 Link Here
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
21
use strict;
21
use Modern::Perl;
22
use warnings;
23
22
24
use CGI;
23
use CGI;
25
use JSON;
24
use JSON;
26
use autouse 'Data::Dumper' => qw(Dumper);
25
use autouse 'Data::Dumper' => qw(Dumper);
27
26
28
use C4::Auth;
27
use C4::Auth qw(check_cookie_auth);
29
use C4::Context;
28
use C4::Context;
30
29
30
use Koha::Printer;
31
use Koha::Printers;
32
31
my $cgi          = CGI->new;
33
my $cgi          = CGI->new;
32
my $dbh          = C4::Context->dbh;
34
my $dbh          = C4::Context->dbh;
33
my $sort_columns = [ "id", "source", "text", "timestamp" ];
35
my $sort_columns = [ "id", "source", "text", "timestamp" ];
34
36
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37
my ( $auth_status, $sessionID ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { tools => 'edit_printers' } );
36
    {
38
if ( $auth_status ne "ok" ) {
37
        template_name   => "",
39
    exit 0;
38
        query           => $cgi,
40
}
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { tools => 'edit_printers' },
42
        debug           => 1,
43
    }
44
);
45
41
46
my $params = $cgi->Vars;
42
my $params = $cgi->Vars;
47
43
48
print $cgi->header('application/json; charset=utf-8');
44
print $cgi->header('application/json; charset=utf-8');
49
45
50
unless ( $params->{action} ) {
46
unless ( $params->{action} ) {
51
    my $sth = $dbh->prepare("SELECT * FROM printers");
47
    my $printers = Koha::Printers->search();
52
    $sth->execute();
48
    my @aaData = map { [ $_->id, $_->name, $_->queue ] } $printers->as_list();
53
49
    my $aaData = \@aaData;
54
    my $aaData = $sth->fetchall_arrayref;
55
50
56
    print to_json(
51
    print to_json(
57
        {
52
        {
Lines 64-114 unless ( $params->{action} ) { Link Here
64
    );
59
    );
65
}
60
}
66
elsif ( $params->{action} eq 'add' ) {
61
elsif ( $params->{action} eq 'add' ) {
67
    my $sth = $dbh->prepare(
62
    my $printer = Koha::Printer->new( { name => $params->{name}, queue => $params->{queue} } )->store();
68
        'INSERT INTO printers ( name, queue, type ) VALUES (?, ?, ?)');
63
    print to_json( [ [ $printer->id, $printer->name, $printer->queue ] ], { utf8 => 1 } );
69
    $sth->execute( $params->{name}, $params->{queue}, $params->{type} );
70
    if ( $sth->err ) {
71
        warn
72
          sprintf( 'Database returned the following error: %s', $sth->errstr );
73
        exit 1;
74
    }
75
    my $new_printer_id = $dbh->{q{mysql_insertid}};    # ALERT: mysqlism here
76
    $sth = $dbh->prepare('SELECT * FROM printers WHERE id = ?;');
77
    $sth->execute($new_printer_id);
78
    print to_json( $sth->fetchall_arrayref, { utf8 => 1 } );
79
    exit 1;
64
    exit 1;
80
}
65
}
81
elsif ( $params->{action} eq 'edit' ) {
66
elsif ( $params->{action} eq 'edit' ) {
82
    my $aaData           = [];
67
    my $editable_columns =
83
    my $editable_columns = [qw(name queue type)]
68
      [qw(name queue type)];    # pay attention to element order; these columns match the printers table columns
84
      ; # pay attention to element order; these columns match the printers table columns
69
    my $column = $editable_columns->[ $params->{column} - 1 ];
85
70
86
    my $sth = $dbh->prepare(
71
    my $printer = Koha::Printers->find( $params->{id} );
87
"UPDATE printers SET $editable_columns->[$params->{column}-1]  = ? WHERE id = ?;"
72
    $printer->set( { $column => $params->{value} } )->store();
88
    );
89
    $sth->execute( $params->{value}, $params->{id} );
90
    if ( $sth->err ) {
91
        warn
92
          sprintf( 'Database returned the following error: %s', $sth->errstr );
93
        exit 1;
94
    }
95
73
96
    $sth = $dbh->prepare(
74
    print Encode::encode( 'utf8', $printer->$column );
97
"SELECT $editable_columns->[$params->{column}-1] FROM printers WHERE id = ?;"
98
    );
99
    $sth->execute( $params->{id} );
100
    $aaData = $sth->fetchrow_array();
101
    print Encode::encode( 'utf8', $aaData );
102
75
103
    exit 1;
76
    exit 1;
104
}
77
}
105
elsif ( $params->{action} eq 'delete' ) {
78
elsif ( $params->{action} eq 'delete' ) {
106
    my $sth = $dbh->prepare("DELETE FROM printers WHERE id = ?;");
79
    my $printer = Koha::Printers->find( $params->{id} );
107
    $sth->execute( $params->{id} );
80
    $printer->delete();
108
    if ( $sth->err ) {
81
    exit $printer->in_storage();
109
        warn
110
          sprintf( 'Database returned the following error: %s', $sth->errstr );
111
        exit 1;
112
    }
113
    exit 0;
114
}
82
}
115
- 

Return to bug 8352