Add support for automatically creating a user's home calendar.

This commit is contained in:
Andrew McMillan 2007-05-23 08:11:29 +12:00
parent a1708463f9
commit 5b715dc3eb
3 changed files with 40 additions and 2 deletions

View File

@ -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();
/***************************************************************************

View File

@ -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'] );

View File

@ -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?