iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Number of replies: 52
People seem keen on having an iCal export feature for Moodle's calendar, so here's a first stab at it.

Take the attached file and drop it into /moodle/calendar/ and then see how it works for you just by accessing http://......./moodle/calendar/ical.php - you should be able to download the upcoming 60 days' events (max of 1000 events) in iCal format.

DISCLAIMER: This is not guaranteed in any sense! In particular, although the data loads perfectly well into "PHPicalendar", I can't get it to load into Oracle Calendar (which claims to be able to load iCal data). I don't have a phone/PDA to test it on. I believe that the output is perfectly valid iCal 2.0 data, though.

If anyone feels like reporting back on how well this works on phones/PDAs/Apple iCal, please do.
Average of ratings: -
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Mike Jackson -

I just tried installing this, but get a file download window starting and an error:

Internet explorer cannot download ical.php from ...

Any thoughts?

In reply to Mike Jackson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
It must be a temporary error - try again?

I just tried downloading from a completely different computer and it worked fine.

In fact, the computer was a Mac so I tested how Apple's iCal software handled it... and it works nicely!

If anyone can diagnose the reason that the data can't be imported into Oracle Calendar / Microsoft Outlook, I'd be grateful for the input.
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Mike Jackson -

Sorry, I had no trouble downloading it, just it did not work on my moodle 1.5.3 installation.

I'll try again later and see if there is any change. I just put it in the \calendar folder of my moodle folder. Anything else needed to register it or activate it?

In reply to Mike Jackson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Nope. Should work straight away.

You might need to make sure it has the same file permissions as other Moodle files (typically, it needs to be "world-readable" as well as readable by you)...
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Mike Jackson -

I tried again and discovered that it was an Internet explorer problem. When I used firefox, I got a page of text that could be saved as an ical file.

However, I have not been able to find a program I can import it into... I use a program called Time and Chaos. I will tinker with the file to see what i can do.

I tried importing it as a .ics file into outlook with no success - claims that it is not valid... will continue to experiment

Thanks - at least the export format is working for me.

In reply to Mike Jackson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Mike Jackson -

I was able to import the text file output into brown bear software's ical 3.1 for windows, so the file export worked for me if I use firefox for the download/processing of ical.php and I can import it into some vcal compatible applications. Outlook did not like it and neither did time and chaos.

I would love to be able to import and export calendar entries... or interate a calendar into moodle that I can do that with.

In reply to Mike Jackson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
OK, thanks for the reports, Mike. There's a change I can probably make to enable the download to work correctly in IE.

But I wish it was possible to find out why Outlook/T&C don't like the file... Can *anyone* help?
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by John Papaioannou -
Dan, I 'm 99% sure it's because you are missing a "method: publish" property from the VCALENDAR object.

I was working on this feature lately (need to get it off the ground before I get that nice letter from the army recruitment office), and your effort has woken me up suddenly...

I 'm going to commit stuff in /calendar/ and /lib/bennu/ to facilitate the import/export procedure. Stay tuned!
In reply to John Papaioannou

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Hmm. Although this may or may not be the reason for failed import, it shouldn't be, since "method" is an optional property...

You're right, though! Adding that fixes the problem. Thanks - I'll publish an updated version of the script.

In reply to Mike Jackson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Philip Zeigler -
My site uses https and I get this same issue with IE.  Other browsers work fine.  If I disable https (I don't want to) it will work for IE.  Is there a way to strip out the https and replace with http on the export?
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Rob Butner -

Is there an easy way to allow the ical export function to include events that occurred before the current day? Example-- If I want to include events from last month....etc??

In reply to Rob Butner

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Yes, it's entirely possible to do that. But the (experimental) version I've posted here uses one simple query to retrieve the calendar data. If someone wants to develop this further, it could easily be part of an "export" function which allows the user to choose which range of dates they want to export.
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Will Taylor -
This is an excellent feature - thanks!
Ideas for anyone who might pick this up for further development -
  • Discrimination between Global, Course, & Individual events
  • Date ranges
  • (& of course, iCal data Import as well as Export !)
- will

In reply to Will Taylor

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Yes, the ability to specify which events and which date range you're interested in would be good. The "default" should still be the list of "upcoming" events for convenient import into calendar software etc.

Import is a separate issue, really. Of course it would be great to be able to do, but none of the functionality in my script would help anyone with the import task...

But I'm still irked by the fact that the data files don't work in all calendar software - that's the biggest issue we need to address!
In reply to Will Taylor

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Bob Rossa -
Sorry if this is old news because I'm a total noob here but has a Moodle iCal import function been created?
We have a bunch of stuff in an Oracle calendar we'd like to Moodlize.
I'm encouraged by how long ago people were talking about doing it but discouraged by my inability to find anything about it anywhere.
Again sorry about my noobish question clown
In reply to Dan Stowell

VERSION 0.2 - iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Attached is an updated version. Only a couple of changes - I added the "method" property which seems to be required in order to import into Outlook and into Oracle Calendar, and I also set the headers correctly so that the downloaded file takes a nice filename (MoodleCal.ics).

The next really massive problem to solve is... Why does Internet Explorer refuse to download the file? (Is it unable to handle the MIME type "text/calendar", perhaps? Not sure.)
In reply to Dan Stowell

Re: VERSION 0.2 - iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Melissa Fernandez -
Odd, firefox downloads it but it downloads it as  a php file instead of a MoodleCal.ics file.  Ideas?
Average of ratings: Useful (1)
In reply to Dan Stowell

Re: VERSION 0.2 - iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by a hutton -
Hi,
I have a question about ical and the Moodle calendar. I can download the Moodle calendar and open the ics file in iCal, but the time of each event is off by 4 hours. (they appear in iCal 4 hours earlier) I checked the Moodle and the time is correct in both the variables and calendar settings. It is also correct on the computer the file is downloaded to. (including the time zone) Any idea how to fix this so the times are the same (automatically)?

Thanks.
In reply to a hutton

Re: VERSION 0.2 - iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by John Moon -

My time is out by 10 hours as well. It seems as though the file does not take into account the server time (I'm in Melbourne Australia where it's +10 GMT).

It would be great if someone could come up with a fix for this smile

JM

In reply to Dan Stowell

Re: VERSION 0.2 - iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by peshala amarasingha -

I did add this to moodle/calender folder everuthing goes well , except , outlook doesn't seem to find appointments...

any suggestions?

In reply to Dan Stowell

iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by John Papaioannou -
For people who have 1.6dev installed only:

I 've just added a bunch of scripts that can be used to export calendar events to iCal format. You can access the scripts by manually typing this URL:

http://yoursite.com/calendar/export.php

It's still quite raw, but does work. I would appreciate people giving feedback on anything, from obvious bugs to the user interface to the actual code.

Specifically for Dan, and other people who are interested in contributing to the code:
  • The general idea is to break down the files as follows:
    • export.php is the "driver" script. Everything that has a UI goes through this. It's this script's responsibility to include or redirect to other files as necessary.
    • export_execute.php is the "worker" script. It takes parameters from the URL in a well-defined format and does the export. Afterwards it redirects back to export.php (the UI).
    • export_basic.html is the UI for the screen you see when first visiting export.php.
    • export_advanced.html does not exist yet, but if you take a look at the UI it's obvious what it will be for.
    • /lib/bennu/ contains the library that will do the actual translation to iCal format. In other words, the worker script is responsible for translating the data from Moodle's database format to the format that Bennu recognizes. Bennu is then responsible for translating the data from its own format to iCal. This nicely encapsulates all iCal-specific stuff in /lib/bennu/, freeing up developers from actually needing to know anything about iCal.

  • The code that does the actual work is very simple; the UI-related code is much more complicated. The reason for this is that I was thinking of pushing a little on the quality of the UI that Moodle offers. For example: you want to export your calendar. Here's a list of common tasks you might want to do, populated intelligently (for example, if today it's Sunday it makes more sense to give you a "next week" option rather than a "this week" option). If that's not good enough, then you can define your own export parameters (date range etc.). Then, next time you come back these options will have been "saved" and presented ready for use without your lifting a finger. Much room for novelty here, and the feedback could be very interesting.

  • I 'd very much appreciate it if anyone wants to give a hand in coding /lib/bennu. The current version should be quite sufficient to do what we want to do right now, but obviously there are lots of things more to be done (e.g. to import stuff from iCal). Coding Bennu is the hard part; the actual Moodle UI doesn't involve going through RFC 2445 with a magnifying glass late at night. wink

Cheers!
Jon
In reply to John Papaioannou

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
Oh! OK then. Looks good.

By the way, the WebCT import tool includes a function icalFileToEvents($file, $courseid) which does very simple parsing/importing of iCal data.

http://cvs.sourceforge.net/viewcvs.py/moodle/contrib/webctimport/lib.php?view=markup

You might or might not be able to salvage some useful code from that. It would be nice, in future, if the WebCT-importer can use Bennu for this part of the processing!

In reply to John Papaioannou

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
The "PHP iCalendar" project has a well-developed iCal parser too:
http://cvs.sourceforge.net/viewcvs.py/phpicalendar/phpicalendar/functions/ical_parser.php?view=markup

It's GPL licensed. Could easily be used in Moodle?
In reply to Dan Stowell

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by John Papaioannou -
Obviously before embarking on the time-consuming process of writing Bennu I did take a look around SourceForge. wink

Some points to take into account when evaluating solutions for this problem:
  • Exactly how can I reuse this piece of code? Take a moment to look at the (few and incomplete) examples included in Bennu. Then take a look at ical_parser.php. By the time you have grasped how things work in Bennu, you 'll be still scratching your head over ical_parser.
  • What does the solution, as a tool, offer me? Bennu offers a clean OO interface to the world. ical_parser seems to generate $master_array, and good luck reverse engineering the rules regarding its contents. In the worst case, you 'd end up writing a separate conversion layer just to hide these (irrelevant and dangerous, from the point of client code) implementation details from "your" export code.
  • Simply take a look at that code and ask yourself if you 'd want to maintain it. Hint: at some point it reaches 19 levels of tabs. surprise

I 'm not trying to say that this thing is good and that thing is bad. In software engineering there are lots of things you have to take into account, like available resources, timetables, the often disastrous effects of deciding to rewrite a working system from scratch, etc etc. I have no doubt that ical_parser works for the PHP iCalendar people and does the job just fine, even if the maintainers sometimes wish it wasn't written this way (I can say the same for Moodle code, and it's no shame!).

My point is that when you put everything up on the table, it can make sense to develop something from scratch. Especially if you don't have screaming deadlines, you 'll get a modern and clean system designed for the job instead of an adaptation of something designed for another task, and there's something to be given back to the community in the process. smile

Cheers!
Jon
In reply to John Papaioannou

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Dan Stowell -
OK, fair enough. Interesting link too, thanks.
In reply to John Papaioannou

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Dammit, I missed this!

I had no idea this "hidden" code was already in CVS for 1.6 tongueout

Unfortunately, it's not usable right now. To really get it working I think we need to expose a URL with GET parameters including a secret private code, so that tools like Google Calendar and iCal can subscribe to the calendar feed without too much risk of casual URL guessing, eg:

http://moodle.org/calendar/ical.php?course=5&code=68GJ68GHC5VJBB6767VHVGH


Any takers? See also the project on the student projects page:

http://docs.moodle.org/en/Student_projects
In reply to Martin Dougiamas

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Jason Askegreen -
What is the latest on this with the release of 1.6? Will there be a subscription process for the calendar?
In reply to Martin Dougiamas

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Philip Norton -
This will be excellent! Integration with Google Calendar will also be much appreciated.
In reply to Martin Dougiamas

Re: iCal export feature for calendar in 1.6dev (strictly for TEST PURPOSES ONLY!)

by Andrew Walbran -
I am currently tidying up and improving Jon Papaioannou's export code, and will try to add URLs of this form too.
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Nagalingam Kuhan -

Is it possible to incoprate with outlook exprees?

In reply to Nagalingam Kuhan

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Andrew Walbran -
What do you have in mind? As far as I know, Microsoft Outlook Express has no calendar functionality.
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Nagalingam Kuhan -

WHAT IS THE Further Research can be done in ICAL?

In reply to Nagalingam Kuhan

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Matt Gibson -
I've got the calendar into outlook, but how do I get a subscription working, not just export?
In reply to Matt Gibson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Jeff Wood -
Matt,

What version of Outlook? (I'm assuming 2007??)

Have you looked under Tools > Account setting > Internet calendar > new.

I believe (I've set it up) all you need to do is copy the info from moodle into outlook (Export - choose your info & Get calendar URL).

Jeff

In reply to Jeff Wood

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Matt Gibson -
Cool!

Thanks Jeff.
In reply to Matt Gibson

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Jeff Wood -
Matt,

Did it work for you?

After setting up mine at home, I am now getting an "error on page" when I try ot 'Get calendar URL'

Line: 140
Char: 5
Error: Object doesn't support this property or method
Code: 0
URL: http:mysite.com/calendar/export.php?

Anyone have an idea?

Jeff
In reply to Jeff Wood

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Matt Gibson -
Where is 'get calendar url'? I used the orange ical icon for the link (not the export button) and it works flawlessly.
In reply to Jeff Wood

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Link to student's iCal feed in Mentee block?

by Lael ... -

Matt,

did you get any further with this idea of placing a student's ical feed in the Mentee's block?

In reply to Dan Stowell

ical: day events

by Martin O'Mahony -
The iCal http-export to Kontact (PIM under KDE/Linux) works great. There is just one thing that makes the result look a little untidy.

All the events have a time associated, thus, Kontact displays these events in the time schedule. So far so good, but with events that take several days (the summer break for instance) those are also listed in the the time schedule while it would be a lot more comfortable to have them listed as day events like this:

[...]
DTSTART;VALUE=DATE:20070719
DTEND;VALUE=DATE:20070830
TRANSP:TRANSPARENT
[...]

Is there a way to incorporate this functionality into Moodle? Or it is already implemented and I didn't notice?


In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Zoe Bogner -
Is it possible to change this code so that when run, the .ics file is written to a directory on the server, instead of presenting itself as a downloadable file?

Since true .ics subscription doesn't seem to be available yet, my little work around is to have this file automatically written every so often (through the power of cron) to the PHP iCalendar directory on the same server. Is this crazy talk?
In reply to Dan Stowell

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: iCal subscription URL for course events rather than user events

by Sherry Brown -
Matt --

Could you post this fix for all to see? I know I will need this in the next few weeks.

-- Sherry
In reply to Deleted user

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Dan Stowell

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Dan Stowell

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by David Lawrence -
Is there any way to get past the 60 day/1000 event limit? I'd really like to export the entire school year's calendar. Any suggestions would be appreciated!

Also, can anyone explain why there is a seemingly arbitrary limit such as this? I'm sure there's a good reason -- I'd just like to understand it.
In reply to David Lawrence

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Terry Chaney -
I second this request. This would be EXTREMELY valuable to me. I too find it mysterious that ANY limit would be placed on one's ability to export the entire course calendar.
In reply to Terry Chaney

Re: iCal export feature for calendar (strictly for TEST PURPOSES ONLY!)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is fixed in the code. However if you find the right bit of code it is easy to change just be editing one number.

I am sure I wrote a post that explained how to do this in detail some time in the past. Hopefully that is findable with a bit of searching.