SQL Backend for SquirrelMail Calendar plugin
============================================
Ver 1.0, 2005/03/19


Copyright (c) 2005 Paul Lesneiwski <pdontthink@angrynerds.com>



Description
===========

This plugin implements a SQL-compliant database backend for user 
calendar data for the SquirrelMail Calendar plugin.



License
=======

This plugin is released under the GNU General Public
License (see COPYING for details).



Requirements
============

 - Pear PHP extension with database package (comes standard with 
   most PHP installations)



TODO
====

 - Implement TODO/Task, Holiday and other event types



Migrating From Other Backends
=============================

There is currently no automated support for migrating your calendar
data from one backend to another.  You will have to manually export
the calendars you want to migrate using "export" links on the main
calendar list page (click "Calendar" at the top of the main SquirrelMail
interface), and then re-import them when you have installed and 
activated the new backend.



Data Schema
===========

What follows is the recommended DDL for the calendar tables.  You may
change this at will, but be sure to update the needed SQL queries in
the config.php file.  This is a MySQL DDL, but should be easily adapted
to your database of choice.


CREATE DATABASE squirrelmail_calendar;
GRANT SELECT, UPDATE, INSERT, DELETE on squirrelmail_calendar.* TO 'user'@'localhost';

CREATE TABLE calendars (
  id varchar(250) NOT NULL,
  type varchar(30) NOT NULL,
  name varchar(255) default '',
  domain varchar(128) default '',
  created_on datetime,
  last_modified_on datetime,
  ical_raw text NOT NULL,
  PRIMARY KEY (id),  
  UNIQUE KEY id (id),
  KEY type (type)
) TYPE=MyISAM;

CREATE TABLE calendar_owners (
  calendar_id varchar(250) NOT NULL,
  owner_name varchar(128) NOT NULL,
  PRIMARY KEY (calendar_id, owner_name),  
  UNIQUE KEY cal_owner (calendar_id, owner_name)
) TYPE=MyISAM;

CREATE TABLE calendar_readers (
  calendar_id varchar(250) NOT NULL,
  reader_name varchar(128) NOT NULL,
  PRIMARY KEY (calendar_id, reader_name),  
  UNIQUE KEY cal_reader (calendar_id, reader_name)
) TYPE=MyISAM;

CREATE TABLE calendar_writers (
  calendar_id varchar(250) NOT NULL,
  writer_name varchar(128) NOT NULL,
  PRIMARY KEY (calendar_id, writer_name),  
  UNIQUE KEY cal_writer (calendar_id, writer_name)
) TYPE=MyISAM;

CREATE TABLE events (
  id int(11) NOT NULL AUTO_INCREMENT,
  event_id varchar(250) NOT NULL,
  calendar_id varchar(250) NOT NULL,
  domain varchar(128) default '',
  start datetime,
  end datetime,
  isAllDay enum('YES', 'NO') NOT NULL,
  isRecurring enum('YES', 'NO') NOT NULL,
  isTask enum('YES', 'NO') NOT NULL,
  isHoliday enum('YES', 'NO') NOT NULL,
  priority tinyint(3) unsigned default 5,  -- default NORMAL priority
  created_on datetime,
  last_modified_on datetime,
  ical_raw text NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY id (id),
  UNIQUE KEY event_id (event_id, calendar_id),
  KEY isRecurring (isRecurring),
  KEY isTask (isTask),
  KEY isHoliday (isHoliday),
  KEY start (start),
  KEY end (end)        -- TODO: should create some sensible composite keys
) TYPE=MyISAM;

CREATE TABLE event_parent_calendars (
  event_key int(11) NOT NULL,
  parent_calendar_id varchar(250) NOT NULL,
  PRIMARY KEY (event_key, parent_calendar_id),
  UNIQUE KEY event_parent (event_key, parent_calendar_id)
) TYPE=MyISAM;

CREATE TABLE event_owners (
  event_key int(11) NOT NULL,
  owner_name varchar(128) NOT NULL,
  PRIMARY KEY (event_key, owner_name),
  UNIQUE KEY event_owner (event_key, owner_name)
) TYPE=MyISAM;

CREATE TABLE event_readers (
  event_key int(11) NOT NULL,
  reader_name varchar(128) NOT NULL,
  PRIMARY KEY (event_key, reader_name),
  UNIQUE KEY event_reader (event_key, reader_name)
) TYPE=MyISAM;

CREATE TABLE event_writers (
  event_key int(11) NOT NULL,
  writer_name varchar(128) NOT NULL,
  PRIMARY KEY (event_key, writer_name),
  UNIQUE KEY event_writer (event_key, writer_name)
) TYPE=MyISAM;



Change Log
==========

  v1.0  2005/03/19  Paul Lesneiwski <pdontthink@angrynerds.com>
    * Initial version

