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

(-)a/C4/Letters.pm (-3 / +6 lines)
Lines 771-777 sub GetPrintMessages { Link Here
771
    my $params = shift || {};
771
    my $params = shift || {};
772
    
772
    
773
    return _get_unsent_messages( { message_transport_type => 'print',
773
    return _get_unsent_messages( { message_transport_type => 'print',
774
                                   borrowernumber         => $params->{'borrowernumber'}, } );
774
                                   borrowernumber         => $params->{'borrowernumber'},
775
                                 } );
775
}
776
}
776
777
777
=head2 GetQueuedMessages ([$hashref])
778
=head2 GetQueuedMessages ([$hashref])
Lines 866-873 sub _get_unsent_messages (;$) { Link Here
866
867
867
    my $dbh = C4::Context->dbh();
868
    my $dbh = C4::Context->dbh();
868
    my $statement = << 'ENDSQL';
869
    my $statement = << 'ENDSQL';
869
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, from_address, to_address, content_type
870
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode
870
  FROM message_queue
871
  FROM message_queue mq
872
  LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
871
 WHERE status = ?
873
 WHERE status = ?
872
ENDSQL
874
ENDSQL
873
875
Lines 886-891 ENDSQL Link Here
886
            push @query_params, $params->{'limit'};
888
            push @query_params, $params->{'limit'};
887
        }
889
        }
888
    }
890
    }
891
    
889
    $debug and warn "_get_unsent_messages SQL: $statement";
892
    $debug and warn "_get_unsent_messages SQL: $statement";
890
    $debug and warn "_get_unsent_messages params: " . join(',',@query_params);
893
    $debug and warn "_get_unsent_messages params: " . join(',',@query_params);
891
    my $sth = $dbh->prepare( $statement );
894
    my $sth = $dbh->prepare( $statement );
(-)a/misc/cronjobs/gather_print_notices.pl (-22 / +68 lines)
Lines 21-34 use strict; Link Here
21
use warnings;
21
use warnings;
22
22
23
BEGIN {
23
BEGIN {
24
25
    # find Koha's Perl modules
24
    # find Koha's Perl modules
26
    # test carefully before changing this
25
    # test carefully before changing this
27
    use FindBin;
26
    use FindBin;
28
    eval { require "$FindBin::Bin/../kohalib.pl" };
27
    eval { require "$FindBin::Bin/../kohalib.pl" };
29
}
28
}
30
29
31
use CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
30
use
31
  CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
32
use C4::Context;
32
use C4::Context;
33
use C4::Dates;
33
use C4::Dates;
34
use C4::Debug;
34
use C4::Debug;
Lines 42-82 sub usage { Link Here
42
Usage: $0 OUTPUT_DIRECTORY
42
Usage: $0 OUTPUT_DIRECTORY
43
  Will print all waiting print notices to
43
  Will print all waiting print notices to
44
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
44
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
45
  
46
  -s --split  Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
45
USAGE
47
USAGE
46
    exit $_[0];
48
    exit $_[0];
47
}
49
}
48
50
49
my ( $stylesheet, $help );
51
my ( $stylesheet, $help, $split );
50
52
51
GetOptions(
53
GetOptions(
52
    'h|help' => \$help,
54
    'h|help'  => \$help,
53
) || usage( 1 );
55
    's|split' => \$split,
56
) || usage(1);
54
57
55
usage( 0 ) if ( $help );
58
usage(0) if ($help);
56
59
57
my $output_directory = $ARGV[0];
60
my $output_directory = $ARGV[0];
58
61
59
if ( !$output_directory || !-d $output_directory ) {
62
if ( !$output_directory || !-d $output_directory ) {
60
    print STDERR "Error: You must specify a valid directory to dump the print notices in.\n";
63
    print STDERR
61
    usage( 1 );
64
"Error: You must specify a valid directory to dump the print notices in.\n";
65
    usage(1);
66
}
67
68
my $today        = C4::Dates->new();
69
my @all_messages = @{ GetPrintMessages() };
70
exit unless (@all_messages);
71
72
if ($split) {
73
    my %messages_by_branch;
74
    foreach my $message (@all_messages) {
75
        push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message );
76
    }
77
78
    foreach my $branchcode ( keys %messages_by_branch ) {
79
        my @messages = @{ $messages_by_branch{$branchcode} };
80
81
        open $OUTPUT, '>',
82
          File::Spec->catdir( $output_directory,
83
            "holdnotices-" . $today->output('iso') . "-$branchcode.html" );
84
85
        my $template =
86
          C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
87
            new CGI );
88
89
        $template->param(
90
            stylesheet => C4::Context->preference("NoticeCSS"),
91
            today      => $today->output(),
92
            messages   => \@messages,
93
        );
94
95
        print $OUTPUT $template->output;
96
97
        foreach my $message (@messages) {
98
            C4::Letters::_set_message_status(
99
                { message_id => $message->{'message_id'}, status => 'sent' } );
100
        }
101
102
        close $OUTPUT;
103
    }
62
}
104
}
105
else {
106
    open $OUTPUT, '>',
107
      File::Spec->catdir( $output_directory,
108
        "holdnotices-" . $today->output('iso') . ".html" );
63
109
64
my $today = C4::Dates->new();
110
    my $template =
65
my @messages = @{ GetPrintMessages() };
111
      C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
66
exit unless( @messages );
112
        new CGI );
67
113
68
open OUTPUT, '>', File::Spec->catdir( $output_directory, "holdnotices-" . $today->output( 'iso' ) . ".html" );
114
    $template->param(
115
        stylesheet => C4::Context->preference("NoticeCSS"),
116
        today      => $today->output(),
117
        messages   => \@all_messages,
118
    );
69
119
70
my $template = C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', new CGI );
120
    print $OUTPUT $template->output;
71
121
72
$template->param(
122
    foreach my $message (@all_messages) {
73
    stylesheet => C4::Context->preference("NoticeCSS"),
123
        C4::Letters::_set_message_status(
74
    today => $today->output(),
124
            { message_id => $message->{'message_id'}, status => 'sent' } );
75
    messages => \@messages,
125
    }
76
);
77
126
78
print OUTPUT $template->output;
127
    close $OUTPUT;
79
128
80
foreach my $message ( @messages ) {
81
    C4::Letters::_set_message_status( { message_id => $message->{'message_id'}, status => 'sent' } );
82
}
129
}
83
- 

Return to bug 8063