Bug 15511: Fix tabbed display on OPAC patron account summary page
[koha.git] / opac / opac-ics.pl
1 #!/usr/bin/perl
2
3 # Copyright 2007 Liblime Ltd
4
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 # This script builds an ICalendar file (rfc 2445) for use in programs such as Ical
21
22 use strict;
23 use warnings;
24
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;
33
34 use C4::Auth;
35 use C4::Koha;
36 use C4::Circulation;
37 use C4::Members;
38 use C4::Dates;
39
40 my $query = new CGI;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42     {
43         template_name   => "opac-user.tt",
44         query           => $query,
45         type            => "opac",
46         authnotrequired => 0,
47         flagsrequired   => { borrow => 1 },
48         debug           => 1,
49     }
50 );
51
52 # Create Calendar
53 my $calendar = Data::ICal->new();
54
55 # get issued items ....
56 my $issues = GetPendingIssues($borrowernumber);
57
58 foreach my $issue ( @$issues ) {
59     my $vevent = Data::ICal::Entry::Event->new();
60     my ($year,$month,$day)=Parse_Date($issue->{'date_due'});
61     ($year,$month,$day)=split /-|\/|\.|:/,$issue->{'date_due'} unless ($year && $month);
62 #    Decode_Date_EU2($string))
63     my $datestart = DateTime->new(
64         day    => $day,
65         month  => $month,
66         year   => $year,
67         hour   => 9,
68         minute => 0,
69         second => 0
70     );
71     my $dateend = DateTime->new(
72         day    => $day,
73         month  => $month,
74         year   => $year,
75         hour   => 10,
76         minute => 0,
77         second => 0
78     );
79     $vevent->add_properties(
80         summary => "$issue->{'title'} Due",
81         description =>
82 "Your copy of $issue->{'title'} barcode $issue->{'barcode'} is due back at the library today",
83         dtstart => DateTime::Format::ICal->format_datetime($datestart),
84         dtend   => DateTime::Format::ICal->format_datetime($dateend),
85     );
86     $calendar->add_entry($vevent);
87 }
88
89 print $query->header(
90     -type        => 'application/octet-stream',
91     -attachment => 'koha.ics'
92 );
93
94
95 print $calendar->as_string;