Bug 16818: External auth redirect broken under Plack
[koha.git] / opac / opac-ics.pl
blobf92d5aadd4d424ce591ba4a42f0603c340308ac1
1 #!/usr/bin/perl
3 # Copyright 2007 Liblime Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 # This script builds an ICalendar file (rfc 2445) for use in programs such as Ical
22 use strict;
23 use warnings;
25 use CGI qw ( -utf8 );
26 use Data::ICal;
27 use Data::ICal::Entry::Event;
28 use DateTime;
29 use DateTime::Format::ICal;
30 use Date::Calc qw (Parse_Date);
31 use DateTime;
32 use DateTime::Event::ICal;
34 use C4::Auth;
35 use C4::Koha;
36 use C4::Circulation;
37 use C4::Members;
39 my $query = new CGI;
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42 template_name => "opac-user.tt",
43 query => $query,
44 type => "opac",
45 authnotrequired => 0,
46 debug => 1,
50 # Create Calendar
51 my $calendar = Data::ICal->new();
53 # get issued items ....
54 my $issues = GetPendingIssues($borrowernumber);
56 foreach my $issue ( @$issues ) {
57 my $vevent = Data::ICal::Entry::Event->new();
58 my ($year,$month,$day)=Parse_Date($issue->{'date_due'});
59 ($year,$month,$day)=split /-|\/|\.|:/,$issue->{'date_due'} unless ($year && $month);
60 # Decode_Date_EU2($string))
61 my $datestart = DateTime->new(
62 day => $day,
63 month => $month,
64 year => $year,
65 hour => 9,
66 minute => 0,
67 second => 0
69 my $dateend = DateTime->new(
70 day => $day,
71 month => $month,
72 year => $year,
73 hour => 10,
74 minute => 0,
75 second => 0
77 $vevent->add_properties(
78 summary => "$issue->{'title'} Due",
79 description =>
80 "Your copy of $issue->{'title'} barcode $issue->{'barcode'} is due back at the library today",
81 dtstart => DateTime::Format::ICal->format_datetime($datestart),
82 dtend => DateTime::Format::ICal->format_datetime($dateend),
84 $calendar->add_entry($vevent);
87 print $query->header(
88 -type => 'application/octet-stream',
89 -attachment => 'koha.ics'
93 print $calendar->as_string;