Bug 5187: Show place of publication (MARC21, 260$c), XSLT
[koha.git] / opac / opac-ics.pl
blob5a8512a24a0a9b3af60547194b3fb640ae8fb4e3
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 Date::ICal;
29 use Date::Calc qw (Parse_Date);
31 use C4::Auth;
32 use C4::Koha;
33 use C4::Circulation;
34 use C4::Members;
35 use C4::Dates;
37 my $query = new CGI;
38 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
40 template_name => "opac-user.tmpl",
41 query => $query,
42 type => "opac",
43 authnotrequired => 0,
44 flagsrequired => { borrow => 1 },
45 debug => 1,
49 # get borrower information ....
50 my ( $borr ) = GetMemberDetails( $borrowernumber );
52 # Create Calendar
53 my $calendar = Data::ICal->new();
55 # get issued items ....
56 my ($issues) = GetPendingIssues($borrowernumber);
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 = Date::ICal->new(
64 day => $day,
65 month => $month,
66 year => $year,
67 hour => 9,
68 min => 0,
69 sec => 0
70 )->ical;
71 my $dateend = Date::ICal->new(
72 day => $day,
73 month => $month,
74 year => $year,
75 hour => 10,
76 min => 0,
77 sec => 0
78 )->ical;
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 => $datestart,
84 dtend => $dateend,
86 $calendar->add_entry($vevent);
89 print $query->header(
90 -type => 'application/octet-stream',
91 -attachment => 'koha.ics'
95 print $calendar->as_string;