# iCalcreator 2.8

iCalcreator class v2.8
copyright (c) 2007-2011 Kjell-Inge Gustafsson, kigkonsult
www.kigkonsult.se/iCalcreator
ical@kigkonsult.se
iCalcreator is a PHP class managing iCal formatted files for non-calendar systems like CMS, project management systems and other applications able to process calendar information like agendas, tasks, reports, totos, journaling data and for communication with calendar systems and applications.
This is a short summary how to use iCalcreator; create, parse, edit, select and output functionality.
iCalcreator is built of a class file with support of a function class file and are calendar component property oriented. Development environment is PHP version 5.x but coding is done to meet 4.x backward compatibility and may work.

#### iCal

A short iCal description is found at Wikipedia. If You are not familiar with iCal, read this first!
Knowledge of calendar protocol rfc2445/rfc2446 is to recommend;
rfc2445 - Internet Calendaring and Scheduling Core Object Specification (iCalendar)
rfc2446 - iCalendar Transport-Independent Interoperability Protocol (iTIP) Scheduling Events, BusyTime, To-dos and Journal Entries
All functions calls are made as simple as possible BUT (, !!!,) read these rfc's properly!

#### Downloads

Download complete manual and coding samples. from www.kigkonsult.se/iCalcreator.

#### INSTALL

Unpack to any folder
- add this folder to your include-path
- or unpack to your application-(include)-folder
Add "require_once [folder/]iCalcreator.class.php;" to your php-script.
If using php version 5.1 or higher, the default timezone need to be set/altered, now "Europe/Stockholm", line 50 in the iCalcreator.class.php file.
When creating a new calendar/component instance, review config settings.

## CREATE

require_once( 'iCalcreator.class.php' ); $config = array( 'unique_id' => 'icaldomain.com' ); // set Your unique id $v = new vcalendar( $config ); // create a new calendar instance $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software .. . $vevent = & $v->newComponent( 'vevent' ); // create an event calendar component $vevent->setProperty( 'dtstart', array( 'year'=>2007, 'month'=>4, 'day'=>1, 'hour'=>19, 'min'=>0, 'sec'=>0 )); $vevent->setProperty( 'dtend', array( 'year'=>2007, 'month'=>4, 'day'=>1, 'hour'=>22, 'min'=>30, 'sec'=>0 )); $vevent->setProperty( 'LOCATION', 'Central Placa' ); // property name - case independent $vevent->setProperty( 'summary', 'PHP summit' ); $vevent->setProperty( 'description', 'This is a description' ); $vevent->setProperty( 'comment', 'This is a comment' ); $vevent->setProperty( 'attendee', 'attendee1@icaldomain.net' ); .. . $vevent = & $v->newComponent( 'vevent' ); // create next event calendar component $vevent->setProperty( 'dtstart', '20070401', array('VALUE' => 'DATE'));// alt. date format, now for an all-day event $vevent->setProperty( "organizer" , 'boss@icaldomain.com' ); $vevent->setProperty( 'summary', 'ALL-DAY event' ); $vevent->setProperty( 'description', 'This is a description for an all-day event' ); $vevent->setProperty( 'resources', 'COMPUTER PROJECTOR' ); $vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// weekly, four occasions $vevent->parse( 'LOCATION:1CP Conference Room 4350' ); // supporting parse of strict rfc2445 formatted text .. . .. .// all calendar components are described in rfc2445 .. .// a complete iCalcreator function list (ex. setProperty) in iCalcreator manual .. . $v->returnCalendar(); // redirect calendar file to browser

## PARSE

require_once( 'iCalcreator.class.php' ); $config = array( 'unique_id', 'icaldomain.com' ); // set Your unique id, required if any component UID is missing $v = new vcalendar( $config ); // create a new calendar instance /* start parse of local file */ $config = array( 'directory' => 'calendar', 'filename' => 'file.ics' ); $v->setConfig( $config ); // set directory and file name $v->parse(); /* start parse of remote file */ $v->setConfig( 'url', 'http://www.aDomain.net/file.ics' ); // iCalcreator also support parse from or write to remote files $v->parse(); $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software .. . $v->sort(); // ensure start date order .. .

## EDIT

require_once( 'iCalcreator.class.php' ); $config = array( 'unique_id' => 'icaldomain.com', 'directory' => 'calendar', 'filename' => 'file.ics' ); // set Your unique id, import directory and file name $v = new vcalendar( $config ); // create a new calendar instance $v->parse(); $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software while( $vevent = $v->getComponent( 'vevent' )) { // read events, one by one $uid = $vevent->getProperty( 'uid' ); // uid required, one occurence (unique id/key for component) .. . $dtstart = $vevent->getProperty( 'dtstart' ); // dtstart required, one occurence .. . if( $description = $vevent->getProperty( 'description', 1 )) { // description optional, first occurence .. . // edit the description $vevent->setProperty( 'description', $description, FALSE, 1 ); // update/replace the description } while( $comment = $vevent->getProperty( 'comment' )) { // comment optional, may occur more than once .. . // manage comments } .. . while( $vevent->deleteProperty( 'attendee' )) continue; // remove all ATTENDEE properties .. . .. . $v->setComponent ( $vevent, $uid ); // update/replace event in calendar with uid as key } .. . .. .// a complete iCalcreator function list (ex. getProperty, deleteProperty) in iCalcreator manual .. .

## SELECT

require_once( 'iCalcreator.class.php' ); $config = array( 'unique_id' => 'icaldomain.com' ); // set Your unique id $v = new vcalendar( $config ); // create a new calendar instance $v->setConfig( 'url', 'http://www.aDomain.net/file.ics' ); // iCalcreator also support remote files $v->parse(); $v->sort(); // ensure start date order $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software $eventArray = $v->selectComponents(); // select components occuring today // (including components with recurrence pattern) foreach( $eventArray as $year => $yearArray) { foreach( $yearArray as $month => $monthArray ) { foreach( $monthArray as $day => $dailyEventsArray ) { foreach( $dailyEventsArray as $vevent ) { $currddate = $event->getProperty( 'x-current-dtstart' ); // if member of a recurrence set (2nd occurence etc) // returns array( 'x-current-dtstart' // , <(string) date("Y-m-d [H:i:s][timezone/UTC offset]")>) $dtstart = $vevent->getProperty( 'dtstart' ); // dtstart required, one occurence, (orig. start date) $summary = $vevent->getProperty( 'summary' ); $description = $vevent->getProperty( 'description' ); .. . .. .

## OUTPUT

require_once( 'iCalcreator.class.php' ); $config = array( 'unique_id' => 'icaldomain.com' ); // set Your unique id $v = new vcalendar( $config ); // create a new calendar instance $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software .. . .. .// parse calendar file(s) and/or edit/create calendar components.. . .. .

#### // opt 1

.. . $v->returnCalendar(); // redirect calendar file to browser

#### // opt 2

.. . $config = array( 'directory' => 'depot', 'filename' => 'calendar.ics' ); $v->setConfig( $config ); // set output directory and file name $v->saveCalendar(); // save calendar to (local) file

#### // opt 3

.. . $config = array( 'url' => 'http://www.aDomain.net/file.ics' ); $v->setConfig( $config ); // set output url $v->saveCalendar(); // save calendar to remote url

## COPYRIGHT AND LICENSE

#### Copyright

iCalcreator class
copyright (c) 2007-2011 Kjell-Inge Gustafsson, kigkonsult
www.kigkonsult.se/iCalcreator
ical@kigkonsult.se

#### License

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or download it here.