\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\part{Horde\_Kolab\_Format}
The \texttt{Horde\_Kolab\_Format} package allows you to easily read and write the Kolab format using PHP.

\section{Installation}
The package is being distributed as a standard PEAR\footnote{http://pear.php.net} package by the Horde project. As long as you have PEAR\footnote{http://pear.php.net} installed, installation should be straight forward.

\begin{verbatim}

 pear channel-discover pear.horde.org
 pear install horde/Horde_Kolab_Format
\end{verbatim}

\section{Using the package}
This section will present a short example script to demonstrate reading/writing an event in the Kolab XML format. The following assumes you have a working \textbf{PSR-0} compliant autoloader setup.\newline
This will automatically pull in all required classes. You can of course use the default Horde setup:

\begin{verbatim}

 require_once 'Horde/Autoloader/Default.php';
\end{verbatim}

Make sure you have the \textbf{\texttt{Horde\_Autoloader}} package installed (\textbf{\texttt{pear install horde/Horde\_Autoloader}}).

The API provided by the central \textbf{\texttt{Horde\_Kolab\_Format}} interface is very simple: it only provides a \textbf{\texttt{load()}} and a \textbf{\texttt{save()}} function.

In order to have access to these methods it is necessary to create a parser implementing the \textbf{\texttt{Horde\_Kolab\_Format}} interface. The \textbf{\texttt{Horde\_Kolab\_Format\_Factory}} object is the helper that will generate a parser for you. The required calls look like this:

\begin{verbatim}

 $factory = new Horde_Kolab_Format_Factory();
 $format = $factory->create('Xml', 'event', array('version' => 1));
\end{verbatim}

The first argument indicates the \textbf{format type}: Currently only \textbf{Xml} is supported here. The second argument specifies the desired type of object that should be read or written. The package currently implements \textbf{contact}, \textbf{distributionlist}, \textbf{event}, \textbf{note}, \textbf{task} and \textbf{hprefs}. The third argument holds a set of optional parameters for the parser. Here we specify that we expect the parser to adhere to the internal data API version 1.

The \textbf{\texttt{\$format}} variable created above now provides the means to save and load events in Kolab XML format. In order to save an event we need to prepare an array with all relevant information about this event:

\begin{verbatim}

 $object = array(
     'uid' => 1,
     'summary' => 'test event',
     'start-date' => time(),
     'end-date' => time() + 24 * 60 * 60,
 );
\end{verbatim}

This is an event that has the \textbf{UID} of \textbf{1} and carries the title \textbf{test event}. It starts right now (\textbf{\texttt{time()}}) and ends in a day (\textbf{\texttt{time() + 24 * 60 * 60}}).

This event can now be saved using the \textbf{\texttt{save()}} function of the format handler:

\begin{verbatim}

 $xml = $format->save($object);
\end{verbatim}

The function returns the Kolab XML format as a result. This string can be fed back into the \textbf{\texttt{load()}} function:

\begin{verbatim}

 $read_object = $format->load($xml);
\end{verbatim}

If we dump the contents of the two variables \textbf{\texttt{\$xml}} and \textbf{\texttt{\$read\_object}} this will be the result:

\begin{verbatim}

 var_dump($xml);
 string(438) "<?xml version="1.0"?>
 <event version="1.0">
   <uid>1</uid>
   <body></body>
   <categories></categories>
   <creation-date>2008-07-10T12:51:51Z</creation-date>
   <last-modification-date>2008-07-10T12:51:51Z</last-modification-date>
   <sensitivity>public</sensitivity>
   <product-id>Horde::Kolab</product-id>
   <summary>test event</summary>
   <start-date>2008-07-10T12:51:51Z</start-date>
   <end-date>2008-07-11T12:51:51Z</end-date>
 </event>
 "
 
 var_dump($read_object);
 array(11) {
   ["uid"]=>
   string(1) "1"
   ["body"]=>
   string(0) ""
   ["categories"]=>
   string(0) ""
   ["creation-date"]=>
   int(1215694311)
   ["last-modification-date"]=>
   int(1215694311)
   ["sensitivity"]=>
   string(6) "public"
   ["product-id"]=>
   string(12) "Horde::Kolab"
   ["summary"]=>
   string(10) "test event"
   ["start-date"]=>
   int(1215694311)
   ["attendee"]=>
   array(0) {
   }
   ["end-date"]=>
   int(1215780711)
 }
\end{verbatim}

We see that the format stores a lot more information than we originally provided. The resulting XML string does not only contain the \textbf{uid}, \textbf{summary}, \textbf{start-date}, and \textbf{end-date}. Several additional attributes have been added. These were either calculated or set to a default value.

\begin{itemize}
\item{\textbf{body}: holds the event description. We did not specify an event description so this value has been set to an empty string.}
\item{\textbf{sensitivity}: events may be \textbf{public} or \textbf{private} - with \textbf{public} being the default}
\item{\textbf{categories}: Any Kolab object may be member of different categories. As we didn't specify a category this value is also empty.}
\item{\textbf{creation-date}: The time stamp of the moment the object was created.}
\item{\textbf{last-modification-date}: The time stamp of the moment the object was last modified.}
\item{\textbf{product-id}: The ID of the product that last touched this object. If we use the \textbf{Horde\_Kolab\_Format} package it will always be \textbf{Horde::Kolab}.}
\end{itemize}
If we read the XML data back into an array all these new informations are available within that array.

\section{Creating your own Kolab XML format}
Currently the \textbf{Horde\_Kolab\_Format} implements the object types \textbf{contact}, \textbf{distributionslist}, \textbf{event}, \textbf{note}, \textbf{task} as they are defined within the [[Kolab Format]] specification. In addition the Horde specific \textbf{hprefs} type is available. It is used for storing Horde user preferences in the IMAP store provided by the Kolab server.

Depending on the web application you might wish to connect with the Kolab server these object types may not be enough. Do not hesitate to define your own new type in that case. If you want it to find wider distribution you should of course discuss it on the Kolab Format mailing list\footnote{http://kolab.org/pipermail/kolab-format/} to get some feedback on the new type.

The \textbf{Horde\_Kolab\_Format} packages makes the definition of a new object type rather straight forward. The following will explain the creation of a very simple new object that only saves a single string value.

This time it will be necessary to load the XML format definition, too. Any new object type will extend this XML definition:

\begin{verbatim}

 require_once 'Horde/Kolab/Format.php';
 require_once 'Horde/Kolab/Format/XML.php';
\end{verbatim}

A new object type is represented by a class that extends \textbf{Horde\_Kolab\_Format\_XML}:

\begin{verbatim}

 class Horde_Kolab_Format_XML_string extends Horde_Kolab_Format_XML {
 
     var $_fields_specific;
 
     function Horde_Kolab_Format_XML_string()
     {
         $this->_root_name = 'string';
  
         /** Specific fields of this object type                           
          */
         $this->_fields_specific = array(
             'string' => array(
                 'type' => HORDE_KOLAB_XML_TYPE_STRING,
                 'value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING,
             ),
         );
          
         parent::Horde_Kolab_Format_XML();
     }
 }
\end{verbatim}

The class needs to end with the name of the object type. Here it is just \textbf{string}.

The declaration \textbf{var \$\_fields\_specific;} indicates that the new object type has attributes beyond the basic set required for any Kolab object. So this part may not be missing for a declaration of a new type.

The function creating the class (\textbf{Horde\_Kolab\_Format\_XML\_string()}) needs to do three things:

\begin{itemize}
\item{Declaring the XML root name which will be \textbf{string} here. It should always match the type name.}
\item{Declaring the specific attributes of the object. This part populates the \textbf{\_fields\_specific} variable with an array describing the possible object attributes. This will be described in more detail [[Horde\_Kolab\_Format\#Allowed fields|further below]].}
\item{Calling the parent constructor using \textbf{parent::Horde\_Kolab\_Format\_XML()}.}
\end{itemize}
The new format can now be used as demonstrated in the initial event example:

\begin{verbatim}

 $format = Horde_Kolab_Format::factory('XML', 'string');
 $object = array(
     'uid' => 1,
     'string' => 'test string',
 );
 $xml = $format->save($object);
 $read_object = $format->load($xml);
 var_dump($xml);
 var_dump($read_object);
\end{verbatim}

The result looks like this:

\begin{verbatim}

 string(347) "<?xml version="1.0"?>
 <string version="1.0">
   <uid>1</uid>
   <body></body>
   <categories></categories>
   <creation-date>2008-07-10T13:28:36Z</creation-date>
   <last-modification-date>2008-07-10T13:28:36Z</last-modification-date>
   <sensitivity>public</sensitivity>
   <product-id>Horde::Kolab</product-id>
   <string>test string</string>
 </string>
 "
 
 array(8) {
   ["uid"]=>
   string(1) "1"
   ["body"]=>
   string(0) ""
   ["categories"]=>
   string(0) ""
   ["creation-date"]=>
   int(1215696516)
   ["last-modification-date"]=>
   int(1215696516)
   ["sensitivity"]=>
   string(6) "public"
   ["product-id"]=>
   string(12) "Horde::Kolab"
   ["string"]=>
   string(11) "test string"
 }
\end{verbatim}

\section{Allowed fields}
There are only a number of valid entries available to specify the attributes a new object type may contain.

Each entry in the field list will look like this

\begin{verbatim}

 'attribute_name' => array(
     'type' => HORDE_KOLAB_XML_TYPE_*,
     'value' => HORDE_KOLAB_XML_VALUE_*,
 ),
\end{verbatim}

\textbf{attribute\_name} should be a short name describing the value that should be stored. '\textbf{type}' must be set to one of the following \textbf{HORDE\_KOLAB\_XML\_TYPE\_*} type values:

\begin{itemize}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_STRING}: A string.}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_INTEGER}: A number}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_BOOLEAN}: True or false.}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_DATE}: A date (e.g. 2008/08/08)}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_DATETIME}: A time and a date.}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_DATE\_OR\_DATETIME}: A date or a time and a date.}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_COLOR}: A color (\#00BBFF).}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_COMPOSITE}: A composite element that combines several attributes.}
\item{\textbf{HORDE\_KOLAB\_XML\_TYPE\_MULTIPLE}: Wrapper for an element that may occur several times.}
\end{itemize}
Examples for \textbf{HORDE\_KOLAB\_XML\_TYPE\_COMPOSITE} and \textbf{HORDE\_KOLAB\_XML\_TYPE\_MULTIPLE} can be found in the definitions currently provided by the \textbf{Horde\_Kolab\_Format} package.

The following '\textbf{value}' settings are allowed:

\begin{itemize}
\item{\textbf{HORDE\_KOLAB\_XML\_VALUE\_DEFAULT}: An attribute with a default value.}
\item{\textbf{HORDE\_KOLAB\_XML\_VALUE\_MAYBE\_MISSING}: An attribute that may be left undefined.}
\item{\textbf{HORDE\_KOLAB\_XML\_VALUE\_NOT\_EMPTY}: An attribute that will cause an error if it is left undefined.}
\item{\textbf{HORDE\_KOLAB\_XML\_VALUE\_CALCULATE}: A complex attribute that gets its own function for calculating the correct value.}
\end{itemize}
Examples for \textbf{HORDE\_KOLAB\_XML\_VALUE\_CALCULATE} can again be found in the current object types implemented in \textbf{Horde\_Kolab\_Format}.

\section{Internal API versions}
TODO

\section{External API versions}
TODO

\section{Xml attribute types}
TODO

\section{Detailed package documentation}
A detailed documentation based on the code comments and extracted via phpDocumentor can be found here\footnote{http://dev.horde.org/api/framework/}. Simply select the package \texttt{Horde\_Kolab\_Format} in the package selection box in the upper right corner.

\end{document}
