use check_perms() on ical export and merge categories on import

This commit is contained in:
Christian Binder 2009-11-18 14:46:25 +00:00
parent 91e694e79d
commit 16538f4f9d
2 changed files with 47 additions and 11 deletions

View File

@ -1065,11 +1065,38 @@ class calendar_boupdate extends calendar_bo
var $categories;
function find_or_add_categories($catname_list)
/**
* Find existing categories in database by name or add categories that do not exist yet
* currently used for ical/sif import
*
* @param array $catname_list names of the categories which should be found or added
* @param int $cal_id=-1 match against existing event and expand the returned category ids
* by the ones the user normally does not see due to category permissions - used to preserve categories
* @return array category ids (found, added and preserved categories)
*/
function find_or_add_categories($catname_list, $cal_id=-1)
{
if (!is_object($this->categories))
{
$this->categories = CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
$this->categories = new categories($this->user,'calendar');
}
if($cal_id && $cal_id > 0)
{
// preserve categories without users read access
$old_event = $this->read($cal_id);
$old_categories = explode(',',$old_event['category']);
$old_cats_preserve = array();
if(is_array($old_categories) && count($old_categories) > 0)
{
foreach($old_categories as $cat_id)
{
if(!$this->categories->check_perms(EGW_ACL_READ, $cat_id))
{
$old_cats_preserve[] = $cat_id;
}
}
}
}
$cat_id_list = array();
@ -1077,9 +1104,11 @@ class calendar_boupdate extends calendar_bo
{
$cat_name = trim($cat_name);
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
if (strncmp($cat_name, "X-", 2) == 0)
// some SyncML clients (mostly phones) add an X- to the category names
if (strncmp($cat_name, 'X-', 2) == 0)
{
$cat_name = substr($cat_name, 2);
}
@ -1091,12 +1120,18 @@ class calendar_boupdate extends calendar_bo
$cat_id_list[] = $cat_id;
}
}
if(is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
{
$cat_id_list = array_merge($cat_id_list, $old_cats_preserve);
}
if (count($cat_id_list) > 1)
{
$cat_id_list = array_unique($cat_id_list);
sort($cat_id_list, SORT_NUMERIC);
}
return $cat_id_list;
}
@ -1104,20 +1139,20 @@ class calendar_boupdate extends calendar_bo
{
if (!is_object($this->categories))
{
$this->categories = CreateObject('phpgwapi.categories',$GLOBALS['egw_info']['user']['account_id'],'calendar');
$this->categories = new categories($this->user,'calendar');
}
if (!is_array($cat_id_list))
{
$cat_id_list = explode(',',$cat_id_list);
}
$cat_list = array();
foreach($cat_id_list as $cat_id)
{
if ($cat_data = $this->categories->return_single($cat_id))
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
{
$cat_list[] = $cat_data[0]['name'];
$cat_list[] = $cat_name;
}
}

View File

@ -1363,7 +1363,7 @@ class calendar_ical extends calendar_boupdate
{
if (is_a($component, 'Horde_iCalendar_vevent'))
{
if ($event = $this->vevent2egw($component, $version, $this->supportedFields))
if ($event = $this->vevent2egw($component, $version, $this->supportedFields, $cal_id))
{
//common adjustments
if ($this->productManufacturer == '' && $this->productName == ''
@ -1424,10 +1424,11 @@ class calendar_ical extends calendar_boupdate
* @param array $component VEVENT
* @param string $version vCal version (1.0/2.0)
* @param array $supportedFields supported fields of the device
* @param int $cal_id id of existing event in the content (only used to merge categories)
*
* @return array|boolean event on success, false on failure
*/
function vevent2egw(&$component, $version, $supportedFields)
function vevent2egw(&$component, $version, $supportedFields, $cal_id=-1)
{
if (!is_a($component, 'Horde_iCalendar_vevent')) return false;
@ -1790,11 +1791,11 @@ class calendar_ical extends calendar_boupdate
{
if($version == '1.0')
{
$vcardData['category'] = $this->find_or_add_categories(explode(';',$attributes['value']));
$vcardData['category'] = $this->find_or_add_categories(explode(';',$attributes['value']), $cal_id);
}
else
{
$vcardData['category'] = $this->find_or_add_categories(explode(',',$attributes['value']));
$vcardData['category'] = $this->find_or_add_categories(explode(',',$attributes['value']), $cal_id);
}
}
else