When I sought out to use PHPiCalendar I didn't want to make my zimbra calendars public, I also wanted to compile several calendars (we use this for our room scheduling).CURL seemed to be the best answer way to authenticate and retrieve the calendars. I created a php script that pulls all of the calendars that I want into the calendars folder on PHPiCalendar, and I set a cron job to run that script every 5 minutes.
Using this method I don't notice the issue that is presented in bug
11254 .
The only problem with the way that I wrote this is that you have to make the .ics files in your PHPiCalendar folder publically writeable, a problem I intent to look into soon.
I also edited the template.php file in PHPiCalendar so that it won't show cancelled events or declined events, I can't attach it, it is too large, but if anyone is interested contact me through this forums contact system.
Here is the code that I put into my GetCals.php file(replace 'myserver' with your server and 'mycal' with your calendar names:
<?php
/* Remember to change is 'myServer', 'password', and 'myCal'
* The files you intent to write to must exist and be publically writeable
* I left various echo statements to help you during testing, comment those out as necessary */
function get_content($url, $name)
{
$url = 'http://myServer/zimbra/home/'.$name.'/calendar.ics';
$target = 'calendars/'.$name.'.ics';
$ch = curl_init($url);
/* the next setting allows curl to follow zimbra re-directs */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
/* now you have to set your username and password, I used the admin account */
curl_setopt($ch, CURLOPT_USERPWD, "admin:password");
$result = curl_exec($ch);
/*echo "Received data: <hr>$result<hr>\n"; */
curl_close ($ch);
/* Let's make sure the file exists and is writable first. */
if (is_writable($target)) {
/* Open the target file, this is set to 'w' so that it
* will overwite the contents
* Comment out the echo statments once testing is complete */
if (!$handle = fopen($target, 'w')) {
echo "Cannot open file ($target) \n";
exit;
}
/* Write $result to our opened file. */
if (fwrite($handle, $result) === FALSE) {
echo "Cannot write to file ($target) \n";
exit;
}
echo "Success, wrote to file ($target) \n";
fclose($handle);
} else {
echo "The file $target is not writable \n";
}
}
/* repeat the following step for all of the calendars you want to retrieve *
* Remember the calendar must exist and be writeable */
$name = 'myCal';
get_content($url, $name);
echo "<br />";
/* The following is just a sample repeat*/
$name = 'myCal';
get_content($url, $name);
?>