mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-03-18 08:50:13 +00:00
added types schedule-inbox and -outbox at creation of initial home collections
This commit is contained in:
parent
fc4f6013db
commit
3fecb0908a
@ -92,13 +92,13 @@ function CreateHomeCollections( $username, $default_timezone = null ) {
|
||||
);
|
||||
if( !empty($c->home_out_calendar_name) )
|
||||
$c->default_collections[] = array(
|
||||
'type' => 'calendar',
|
||||
'type' => 'schedule-outbox',
|
||||
'name' => $c->home_out_calendar_name,
|
||||
'displayname_suffix' => ' Outbox'
|
||||
);
|
||||
if( !empty($c->home_in_calendar_name) )
|
||||
$c->default_collections[] = array(
|
||||
'type' => 'calendar',
|
||||
'type' => 'schedule-inbox',
|
||||
'name' => $c->home_in_calendar_name,
|
||||
'displayname_suffix' => ' Inbox'
|
||||
);
|
||||
@ -113,7 +113,7 @@ function CreateHomeCollections( $username, $default_timezone = null ) {
|
||||
|
||||
if ( !is_array($c->default_collections) || !count($c->default_collections) ) return true;
|
||||
|
||||
$principal = new Principal('username',$username);
|
||||
$principal = new Principal('username', $username);
|
||||
|
||||
$user_fullname = $principal->fullname; // user fullname
|
||||
$user_rfullname = implode(' ', array_reverse(explode(' ', $principal->fullname))); // user fullname in reverse order
|
||||
@ -122,80 +122,91 @@ function CreateHomeCollections( $username, $default_timezone = null ) {
|
||||
$sql .= 'VALUES( :user_no, :parent_container, :collection_path, :dav_etag, :displayname, :is_calendar, :is_addressbook, :privileges::BIT(24), current_timestamp, current_timestamp, :resourcetypes );';
|
||||
|
||||
foreach( $c->default_collections as $v ) {
|
||||
if ( $v['type'] == 'calendar' || $v['type']=='addressbook' ) {
|
||||
if ( $v['type'] == 'calendar' || $v['type']=='addressbook' || $v['type']=='schedule-outbox' || $v['type']=='schedule-inbox' ) {
|
||||
if ( !empty($v['name']) ) {
|
||||
$qry = new AwlQuery( 'SELECT 1 FROM collection WHERE dav_name = :dav_name', array( ':dav_name' => $principal->dav_name().$v['name'].'/') );
|
||||
$qry = new AwlQuery(
|
||||
'SELECT 1 FROM collection WHERE dav_name = :dav_name AND resourcetypes LIKE :type',
|
||||
array(
|
||||
':dav_name' => $principal->dav_name().$v['name'].'/',
|
||||
':type' => '%'.$v['type'].'%'
|
||||
)
|
||||
);
|
||||
if ( !$qry->Exec() ) {
|
||||
$c->messages[] = i18n('There was an error reading from the database.');
|
||||
return false;
|
||||
}
|
||||
if ( $qry->rows() > 0 ) {
|
||||
$c->messages[] = i18n('Home '.( $v['type']=='calendar' ? 'calendar' : 'addressbook' ).' already exists.');
|
||||
return true;
|
||||
$c->messages[] = i18n('Home ') . $v['type'] . i18n(' already exists');
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$params[':user_no'] = $principal->user_no();
|
||||
$params[':parent_container'] = $principal->dav_name();
|
||||
$params[':dav_etag'] = '-1';
|
||||
$params[':collection_path'] = $principal->dav_name().$v['name'].'/';
|
||||
if ( isset($v['displayname']) && ! empty($v['displayname']) ) {
|
||||
$params[':displayname'] = str_replace(array('%fn', '%rfn'), array($user_fullname, $user_rfullname), $v['displayname']);
|
||||
} elseif ( isset($v['displayname_suffix']) && ! empty($v['displayname_suffix']) ) {
|
||||
$params[':displayname'] = $user_fullname . $v['displayname_suffix'];
|
||||
} else {
|
||||
$params[':displayname'] = $user_fullname . ($v['type']=='calendar' ? ' calendar' : ' addressbook');
|
||||
$params[':user_no'] = $principal->user_no();
|
||||
$params[':parent_container'] = $principal->dav_name();
|
||||
$params[':dav_etag'] = '-1';
|
||||
$params[':collection_path'] = $principal->dav_name().$v['name'].'/';
|
||||
if ( isset($v['displayname']) && ! empty($v['displayname']) ) {
|
||||
$params[':displayname'] = str_replace(array('%fn', '%rfn'), array($user_fullname, $user_rfullname), $v['displayname']);
|
||||
} elseif ( isset($v['displayname_suffix']) && ! empty($v['displayname_suffix']) ) {
|
||||
$params[':displayname'] = $user_fullname . $v['displayname_suffix'];
|
||||
} else {
|
||||
$typeLabels = [
|
||||
'calendar' => ' calendar',
|
||||
'addressbook' => ' addressbook',
|
||||
'schedule-outbox' => ' Outbox', // capitalized for consistency with CalDAVRequest (line 396)
|
||||
'schedule-inbox' => ' Inbox'
|
||||
];
|
||||
$suffix = isset($typeLabels[$v['type']]) ? $typeLabels[$v['type']] : '';
|
||||
$params[':displayname'] = $user_fullname . $suffix;
|
||||
}
|
||||
$params[':resourcetypes'] = "<DAV::collection/><urn:ietf:params:xml:ns:caldav:{$v['type']}/>";
|
||||
$params[':is_calendar'] = ( $v['type'] === 'calendar' );
|
||||
$params[':is_addressbook'] = ( $v['type'] === 'addressbook' );
|
||||
$params[':privileges'] = ( !isset($v['privileges']) || $v['privileges']===null ? null : privilege_to_bits($v['privileges']) );
|
||||
|
||||
$qry = new AwlQuery( $sql, $params );
|
||||
if ( $qry->Exec() ) {
|
||||
$c->messages[] = i18n('Home ') . $v['type'] . i18n(' added. ') . $v['name'];
|
||||
dbg_error_log("User", ":Write: Created user's home '%s' at '%s'", $v['type'], $params[':collection_path']);
|
||||
|
||||
// create value for urn:ietf:params:xml:ns:caldav:supported-calendar-component-set property
|
||||
if($v['type'] == 'calendar' && isset($v['calendar_components']) && $v['calendar_components'] != null && is_array($v['calendar_components']) && count($v['calendar_components'])) {
|
||||
// convert the array to uppercase and allow only real calendar components
|
||||
$components_clean=array_intersect(array_map("strtoupper", $v['calendar_components']), array('VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE', 'VFREEBUSY', 'VPOLL', 'VAVAILABILITY'));
|
||||
|
||||
// convert the $components_clean array to XML string
|
||||
$result_xml='';
|
||||
foreach($components_clean as $curr)
|
||||
$result_xml.=sprintf('<comp name="%s" xmlns="urn:ietf:params:xml:ns:caldav"/>', $curr);
|
||||
|
||||
// handle the components XML string as user defined property (see below)
|
||||
if($result_xml!='')
|
||||
$v['default_properties']['urn:ietf:params:xml:ns:caldav:supported-calendar-component-set']=$result_xml;
|
||||
}
|
||||
$params[':resourcetypes'] = ( $v['type']=='calendar' ? '<DAV::collection/><urn:ietf:params:xml:ns:caldav:calendar/>' : '<DAV::collection/><urn:ietf:params:xml:ns:carddav:addressbook/>' );
|
||||
$params[':is_calendar'] = ( $v['type']=='calendar' ? true : false );
|
||||
$params[':is_addressbook'] = ( $v['type']=='addressbook' ? true : false );
|
||||
$params[':privileges'] = ( !isset($v['privileges']) || $v['privileges']===null ? null : privilege_to_bits($v['privileges']) );
|
||||
|
||||
$qry = new AwlQuery( $sql, $params );
|
||||
if ( $qry->Exec() ) {
|
||||
$c->messages[] = i18n('Home '.( $v['type']=='calendar' ? 'calendar' : 'addressbook' ).' added.') . " " . $v['name'];
|
||||
dbg_error_log("User",":Write: Created user's home ".( $v['type']=='calendar' ? 'calendar' : 'addressbook' )." at '%s'", $params[':collection_path'] );
|
||||
// store all user defined properties (note: it also handles 'calendar_components' - see above)
|
||||
if(isset($v['default_properties']) && $v['default_properties'] != null && is_array($v['default_properties']) && count($v['default_properties'])) {
|
||||
$sql2='INSERT INTO property (dav_name, property_name, property_value, changed_on, changed_by) ';
|
||||
$sql2.='VALUES (:collection_path, :property_name, :property_value, current_timestamp, :user_no);';
|
||||
$params2[':user_no'] = $principal->user_no();
|
||||
$params2[':collection_path'] = $principal->dav_name().$v['name'].'/';
|
||||
|
||||
// create value for urn:ietf:params:xml:ns:caldav:supported-calendar-component-set property
|
||||
if($v['type'] == 'calendar' && isset($v['calendar_components']) && $v['calendar_components'] != null && is_array($v['calendar_components']) && count($v['calendar_components'])) {
|
||||
// convert the array to uppercase and allow only real calendar compontents
|
||||
$components_clean=array_intersect(array_map("strtoupper", $v['calendar_components']), array('VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE', 'VFREEBUSY', 'VPOLL', 'VAVAILABILITY'));
|
||||
foreach( $v['default_properties'] AS $key => $val ) {
|
||||
$params2[':property_name'] = $key;
|
||||
$params2[':property_value'] = $val;
|
||||
|
||||
// convert the $components_clean array to XML string
|
||||
$result_xml='';
|
||||
foreach($components_clean as $curr)
|
||||
$result_xml.=sprintf('<comp name="%s" xmlns="urn:ietf:params:xml:ns:caldav"/>', $curr);
|
||||
|
||||
// handle the components XML string as user defined property (see below)
|
||||
if($result_xml!='')
|
||||
$v['default_properties']['urn:ietf:params:xml:ns:caldav:supported-calendar-component-set']=$result_xml;
|
||||
}
|
||||
|
||||
// store all user defined properties (note: it also handles 'calendar_components' - see above)
|
||||
if(isset($v['default_properties']) && $v['default_properties'] != null && is_array($v['default_properties']) && count($v['default_properties'])) {
|
||||
$sql2='INSERT INTO property (dav_name, property_name, property_value, changed_on, changed_by) ';
|
||||
$sql2.='VALUES (:collection_path, :property_name, :property_value, current_timestamp, :user_no);';
|
||||
$params2[':user_no'] = $principal->user_no();
|
||||
$params2[':collection_path'] = $principal->dav_name().$v['name'].'/';
|
||||
|
||||
foreach( $v['default_properties'] AS $key => $val ) {
|
||||
$params2[':property_name'] = $key;
|
||||
$params2[':property_value'] = $val;
|
||||
|
||||
$qry2 = new AwlQuery( $sql2, $params2 );
|
||||
if ( $qry2->Exec() ) {
|
||||
dbg_error_log("User",":Write: Created property '%s' for ".( $v['type']=='calendar' ? 'calendar' : 'addressbook' )." at '%s'", $params2[':property_name'], $params2[':collection_path'] );
|
||||
}
|
||||
else {
|
||||
$c->messages[] = i18n("There was an error writing to the database.");
|
||||
return false;
|
||||
}
|
||||
$qry2 = new AwlQuery( $sql2, $params2 );
|
||||
if ( $qry2->Exec() ) {
|
||||
dbg_error_log("User", ":Write: Created property '%s' for '%s' at '%s'", $params2[':property_name'], $v['type'], $params2[':collection_path']);
|
||||
}
|
||||
else {
|
||||
$c->messages[] = i18n("There was an error writing to the database.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$c->messages[] = i18n("There was an error writing to the database.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$c->messages[] = i18n("There was an error writing to the database.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user