Lines 27-45
use Data::ICal;
Link Here
|
27 |
use Data::ICal::Entry::Event; |
27 |
use Data::ICal::Entry::Event; |
28 |
use DateTime; |
28 |
use DateTime; |
29 |
use DateTime::Format::ICal; |
29 |
use DateTime::Format::ICal; |
30 |
use Date::Calc qw (Parse_Date); |
|
|
31 |
use DateTime; |
32 |
use DateTime::Event::ICal; |
30 |
use DateTime::Event::ICal; |
|
|
31 |
use URI; |
33 |
|
32 |
|
34 |
use C4::Auth; |
33 |
use C4::Auth; |
35 |
use C4::Koha; |
34 |
use C4::Koha; |
36 |
use C4::Circulation; |
35 |
use C4::Circulation; |
37 |
use C4::Members; |
36 |
use C4::Members; |
|
|
37 |
use Koha::DateUtils; |
38 |
|
38 |
|
39 |
my $query = new CGI; |
39 |
my $query = new CGI; |
40 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
40 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
41 |
{ |
41 |
{ |
42 |
template_name => "opac-user.tt", |
42 |
template_name => "opac-ics.tt", |
43 |
query => $query, |
43 |
query => $query, |
44 |
type => "opac", |
44 |
type => "opac", |
45 |
authnotrequired => 0, |
45 |
authnotrequired => 0, |
Lines 55-93
my $issues = GetPendingIssues($borrowernumber);
Link Here
|
55 |
|
55 |
|
56 |
foreach my $issue ( @$issues ) { |
56 |
foreach my $issue ( @$issues ) { |
57 |
my $vevent = Data::ICal::Entry::Event->new(); |
57 |
my $vevent = Data::ICal::Entry::Event->new(); |
58 |
my ($year,$month,$day)=Parse_Date($issue->{'date_due'}); |
58 |
my $timestamp = DateTime->now(); # Defaults to UTC |
59 |
($year,$month,$day)=split /-|\/|\.|:/,$issue->{'date_due'} unless ($year && $month); |
59 |
# Send some values to the template to generate summary and description |
60 |
# Decode_Date_EU2($string)) |
60 |
$template->param( |
61 |
my $datestart = DateTime->new( |
61 |
overdue => $issue->{'overdue'}, |
62 |
day => $day, |
62 |
title => $issue->{'title'}, |
63 |
month => $month, |
63 |
barcode => $issue->{'barcode'}, |
64 |
year => $year, |
|
|
65 |
hour => 9, |
66 |
minute => 0, |
67 |
second => 0 |
68 |
); |
69 |
my $dateend = DateTime->new( |
70 |
day => $day, |
71 |
month => $month, |
72 |
year => $year, |
73 |
hour => 10, |
74 |
minute => 0, |
75 |
second => 0 |
76 |
); |
64 |
); |
|
|
65 |
# Catch the result of the template and split on newline |
66 |
my ($summary,$description) = split /\n/, $template->output; |
67 |
my $datestart; |
68 |
if ($issue->{'overdue'} && $issue->{'overdue'} == 1) { |
69 |
# Not much use adding an event in the past for a book that is overdue |
70 |
# so we set datestart = now |
71 |
$datestart = $timestamp; |
72 |
} else { |
73 |
$datestart = dt_from_string($issue->{'date_due'}); |
74 |
$datestart->set_time_zone('UTC'); |
75 |
} |
76 |
# Create a UID that includes the issue number and the domain |
77 |
my $domain = ''; |
78 |
my $baseurl = C4::Context->preference('OPACBaseURL'); |
79 |
if ( $baseurl ne '' ) { |
80 |
my $url = URI->new($baseurl); |
81 |
$domain = $url->host; |
82 |
} else { |
83 |
warn "Make sure the systempreference OPACBaseURL is set!"; |
84 |
} |
85 |
my $uid = 'issue-' . $issue->{'issue_id'} . '@' . $domain; |
86 |
# Create the event |
77 |
$vevent->add_properties( |
87 |
$vevent->add_properties( |
78 |
summary => "$issue->{'title'} Due", |
88 |
summary => $summary, |
79 |
description => |
89 |
description => $description, |
80 |
"Your copy of $issue->{'title'} barcode $issue->{'barcode'} is due back at the library today", |
90 |
dtstamp => DateTime::Format::ICal->format_datetime($timestamp), |
81 |
dtstart => DateTime::Format::ICal->format_datetime($datestart), |
91 |
dtstart => DateTime::Format::ICal->format_datetime($datestart), |
82 |
dtend => DateTime::Format::ICal->format_datetime($dateend), |
92 |
uid => $uid, |
83 |
); |
93 |
); |
|
|
94 |
# Add it to the calendar |
84 |
$calendar->add_entry($vevent); |
95 |
$calendar->add_entry($vevent); |
85 |
} |
96 |
} |
86 |
|
97 |
|
87 |
print $query->header( |
98 |
print $query->header( |
88 |
-type => 'application/octet-stream', |
99 |
-type => 'application/octet-stream', |
89 |
-attachment => 'koha.ics' |
100 |
-attachment => 'koha.ics' |
90 |
); |
101 |
); |
91 |
|
102 |
|
92 |
|
|
|
93 |
print $calendar->as_string; |
103 |
print $calendar->as_string; |
94 |
- |
|
|