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 (-21 / +68 lines)
Lines 28-34 BEGIN { Link Here
28
    eval { require "$FindBin::Bin/../kohalib.pl" };
28
    eval { require "$FindBin::Bin/../kohalib.pl" };
29
}
29
}
30
30
31
use CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
31
use
32
  CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
32
use C4::Context;
33
use C4::Context;
33
use C4::Dates;
34
use C4::Dates;
34
use C4::Debug;
35
use C4::Debug;
Lines 42-82 sub usage { Link Here
42
Usage: $0 OUTPUT_DIRECTORY
43
Usage: $0 OUTPUT_DIRECTORY
43
  Will print all waiting print notices to
44
  Will print all waiting print notices to
44
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
45
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
46
  
47
  -s --split  Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
45
USAGE
48
USAGE
46
    exit $_[0];
49
    exit $_[0];
47
}
50
}
48
51
49
my ( $stylesheet, $help );
52
my ( $stylesheet, $help, $split );
50
53
51
GetOptions(
54
GetOptions(
52
    'h|help' => \$help,
55
    'h|help'  => \$help,
53
) || usage( 1 );
56
    's|split' => \$split,
57
) || usage(1);
54
58
55
usage( 0 ) if ( $help );
59
usage(0) if ($help);
56
60
57
my $output_directory = $ARGV[0];
61
my $output_directory = $ARGV[0];
58
62
59
if ( !$output_directory || !-d $output_directory ) {
63
if ( !$output_directory || !-d $output_directory ) {
60
    print STDERR "Error: You must specify a valid directory to dump the print notices in.\n";
64
    print STDERR
61
    usage( 1 );
65
"Error: You must specify a valid directory to dump the print notices in.\n";
66
    usage(1);
62
}
67
}
63
68
64
my $today = C4::Dates->new();
69
my $today        = C4::Dates->new();
65
my @messages = @{ GetPrintMessages() };
70
my @all_messages = @{ GetPrintMessages() };
66
exit unless( @messages );
71
exit unless (@all_messages);
67
72
68
open OUTPUT, '>', File::Spec->catdir( $output_directory, "holdnotices-" . $today->output( 'iso' ) . ".html" );
73
if ($split) {
74
    my %messages_by_branch;
75
    foreach my $message (@all_messages) {
76
        push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message );
77
    }
69
78
70
my $template = C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', new CGI );
79
    foreach my $branchcode ( keys %messages_by_branch ) {
80
        my @messages = @{ $messages_by_branch{$branchcode} };
71
81
72
$template->param(
82
        open OUTPUT, '>',
73
    stylesheet => C4::Context->preference("NoticeCSS"),
83
          File::Spec->catdir( $output_directory,
74
    today => $today->output(),
84
            "holdnotices-" . $today->output('iso') . "-$branchcode.html" );
75
    messages => \@messages,
76
);
77
85
78
print OUTPUT $template->output;
86
        my $template =
87
          C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
88
            new CGI );
89
90
        $template->param(
91
            stylesheet => C4::Context->preference("NoticeCSS"),
92
            today      => $today->output(),
93
            messages   => \@messages,
94
        );
95
96
        print OUTPUT $template->output;
97
98
        foreach my $message (@messages) {
99
            C4::Letters::_set_message_status(
100
                { message_id => $message->{'message_id'}, status => 'sent' } );
101
        }
102
103
        close OUTPUT;
104
    }
105
}
106
else {
107
    open OUTPUT, '>',
108
      File::Spec->catdir( $output_directory,
109
        "holdnotices-" . $today->output('iso') . ".html" );
110
111
    my $template =
112
      C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
113
        new CGI );
114
115
    $template->param(
116
        stylesheet => C4::Context->preference("NoticeCSS"),
117
        today      => $today->output(),
118
        messages   => \@all_messages,
119
    );
120
121
    print OUTPUT $template->output;
122
123
    foreach my $message (@all_messages) {
124
        C4::Letters::_set_message_status(
125
            { message_id => $message->{'message_id'}, status => 'sent' } );
126
    }
127
128
    close OUTPUT;
79
129
80
foreach my $message ( @messages ) {
81
    C4::Letters::_set_message_status( { message_id => $message->{'message_id'}, status => 'sent' } );
82
}
130
}
83
- 

Return to bug 8063