From 5b715dc3eba59e8d670c4c0c9dbee8ce263bffd2 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 23 May 2007 08:11:29 +1200 Subject: [PATCH] Add support for automatically creating a user's home calendar. --- config/example-config.php | 21 ++++++++++++++++++++- inc/RSCDSUser.php | 20 +++++++++++++++++++- inc/always.php | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/config/example-config.php b/config/example-config.php index 380ab1ec..b258391a 100644 --- a/config/example-config.php +++ b/config/example-config.php @@ -89,9 +89,28 @@ $c->admin_email ='calendar-admin@example.com'; * default (true) if people will be using Evolution or Sunbird / * Lightning against this because that software does not support the * creation of calendar collections. +* Default: true */ -$c->collections_always_exist = true; +// $c->collections_always_exist = true; +/** +* The name of a user's "home" calendar. This will be created for each +* new user. +* Default: 'home' +*/ +// $c->home_calendar_name = 'home'; + +/** +* An array of groups / permissions which should be automatically added +* for each new user created. This is a crude mechanism which we +* will hopefully manage to work out some better approach for in the +* future. For now, create an array that looks something like: +* array( 9 => 'R', 4 => 'A' ) +* to create a 'read' relationship to user_no 9 and an 'all' relation +* with user_no 4. +* Default: none +*/ +// $c->default_relationships = array(); /*************************************************************************** diff --git a/inc/RSCDSUser.php b/inc/RSCDSUser.php index 89e657db..9b504286 100644 --- a/inc/RSCDSUser.php +++ b/inc/RSCDSUser.php @@ -297,9 +297,27 @@ EOSQL; * Write the record to the file */ function Write( ) { - global $session; + global $session, $c; if ( parent::Write() ) { + if ( $this->WriteType == 'insert' ) { + if ( isset($c->home_calendar_name) && strlen($c->home_calendar_name) > 0 ) { + $parent_path = "/".$this->Get('username')."/"; + $calendar_path = $parent_path . $c->home_calendar_name."/"; + $dav_etag = md5($this->user_no . $calendar_path); + $sql = "INSERT INTO collection (user_no, parent_container, dav_name, dav_etag, dav_displayname, is_calendar, "; + $sql .= "created, modified) VALUES( ?, ?, ?, ?, ?, true, current_timestamp, current_timestamp );"; + $qry = new PgQuery( $sql, $this->user_no, $parent_path, $calendar_path, $dav_etag, $this->Get('fullname') ); + if ( $qry->Exec() ) { + $c->messages[] = i18n("Home calendar added."); + dbg_error_log("User",":Write: Created user's home calendar at '%s'", $calendar_path ); + } + else { + $c->messages[] = i18n("There was an error writing to the database."); + return false; + } + } + } if ( $this->AllowedTo("Admin") && isset($_POST['relate_to']) && isset($_POST['relate_as']) && isset($_POST['submit']) && $_POST['submit'] == htmlspecialchars(translate('Add Relationship')) ) { dbg_error_log("User",":Write: Adding relationship as %d to %d", $_POST['relate_as'], isset($_POST['relate_to'] ) ); $qry = new PgQuery("INSERT INTO relationship (from_user, to_user, rt_id ) VALUES( $this->user_no, ?, ? )", $_POST['relate_to'], $_POST['relate_as'] ); diff --git a/inc/always.php b/inc/always.php index cf714d3b..2ba4abb5 100644 --- a/inc/always.php +++ b/inc/always.php @@ -16,6 +16,7 @@ $c->system_name = "Really Simple CalDAV Store"; $c->domain_name = $_SERVER['SERVER_NAME']; $c->save_time_zone_defs = true; $c->collections_always_exist = true; +$c->home_calendar_name = 'home'; $c->enable_row_linking = true; // $c->default_locale = array('es_MX', 'es_MX.UTF-8', 'es'); // $c->local_tzid = 'Pacific/Auckland'; // Perhaps we should read from /etc/timezone - I wonder how standard that is?