Bug 11772: (follow-up) make warning about no active currency a link to currency setup...
[koha.git] / opac / opac-ics.pl
blobd9d90a6711b0242f362c8c71892625619ea99423
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
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;
38 use C4::Dates;
40 my $query = new CGI;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 template_name => "opac-user.tmpl",
44 query => $query,
45 type => "opac",
46 authnotrequired => 0,
47 flagsrequired => { borrow => 1 },
48 debug => 1,
52 # get borrower information ....
53 my ( $borr ) = GetMemberDetails( $borrowernumber );
55 # Create Calendar
56 my $calendar = Data::ICal->new();
58 # get issued items ....
59 my $issues = GetPendingIssues($borrowernumber);
61 foreach my $issue ( @$issues ) {
62 my $vevent = Data::ICal::Entry::Event->new();
63 my ($year,$month,$day)=Parse_Date($issue->{'date_due'});
64 ($year,$month,$day)=split /-|\/|\.|:/,$issue->{'date_due'} unless ($year && $month);
65 # Decode_Date_EU2($string))
66 my $datestart = DateTime->new(
67 day => $day,
68 month => $month,
69 year => $year,
70 hour => 9,
71 minute => 0,
72 second => 0
74 my $dateend = DateTime->new(
75 day => $day,
76 month => $month,
77 year => $year,
78 hour => 10,
79 minute => 0,
80 second => 0
82 $vevent->add_properties(
83 summary => "$issue->{'title'} Due",
84 description =>
85 "Your copy of $issue->{'title'} barcode $issue->{'barcode'} is due back at the library today",
86 dtstart => DateTime::Format::ICal->format_datetime($datestart),
87 dtend => DateTime::Format::ICal->format_datetime($dateend),
89 $calendar->add_entry($vevent);
92 print $query->header(
93 -type => 'application/octet-stream',
94 -attachment => 'koha.ics'
98 print $calendar->as_string;