Fix participant issue in event shifting

This commit is contained in:
Jörg Lehrke 2010-06-16 10:41:45 +00:00
parent 71b91ab69b
commit b53e7ccbcc

View File

@ -237,12 +237,13 @@ class calendar_uiforms extends calendar_ui
unset($event['alarm']['delete_alarm']); unset($event['alarm']['delete_alarm']);
unset($event['duration']); unset($event['duration']);
if (in_array($button,array('ignore','freetime','reedit','confirm_edit_single'))) if (in_array($button,array('ignore','freetime','reedit')))
{ {
// no conversation necessary, event is already in the right format // no conversation necessary, event is already in the right format
} }
elseif (isset($content['participants'])) // convert content => event else
{ {
// convert content => event
if ($content['whole_day']) if ($content['whole_day'])
{ {
$event['start'] = $this->bo->date2array($event['start']); $event['start'] = $this->bo->date2array($event['start']);
@ -258,83 +259,86 @@ class calendar_uiforms extends calendar_ui
{ {
$event['recur_data'] = 1 << (int)date('w',$event['start']); $event['recur_data'] = 1 << (int)date('w',$event['start']);
} }
$event['participants'] = $event['participant_types'] = array(); if (isset($content['participants']))
foreach($content['participants'] as $key => $data)
{ {
switch($key)
$event['participants'] = $event['participant_types'] = array();
foreach($content['participants'] as $key => $data)
{ {
case 'delete': // handled in default switch($key)
case 'quantity': // handled in new_resource {
case 'role': // handled in add, account or resource case 'delete': // handled in default
case 'cal_resources': case 'quantity': // handled in new_resource
case 'status_date': case 'role': // handled in add, account or resource
break; case 'cal_resources':
case 'status_date':
case 'add': break;
// email or rfc822 addresse (eg. "Ralf Becker <ralf@domain.com>") in the search field
// ToDo: get eTemplate to return that field case 'add':
if (($email = $_POST['exec']['participants']['resource']['query']) && // email or rfc822 addresse (eg. "Ralf Becker <ralf@domain.com>") in the search field
(preg_match('/^(.*<)?([a-z0-9_.-]+@[a-z0-9_.-]{5,})>?$/i',$email,$matches))) // ToDo: get eTemplate to return that field
{ if (($email = $_POST['exec']['participants']['resource']['query']) &&
$status = calendar_so::combine_status('U',$content['participants']['quantity'],$content['participants']['role']); (preg_match('/^(.*<)?([a-z0-9_.-]+@[a-z0-9_.-]{5,})>?$/i',$email,$matches)))
// check if email belongs to account or contact --> prefer them over just emails (if we are allowed to invite him)
if (($data = $GLOBALS['egw']->accounts->name2id($matches[2],'account_email')) && $this->bo->check_acl_invite($data))
{ {
$event['participants'][$data] = $event['participant_types']['u'][$data] = $status; $status = calendar_so::combine_status('U',$content['participants']['quantity'],$content['participants']['role']);
// check if email belongs to account or contact --> prefer them over just emails (if we are allowed to invite him)
if (($data = $GLOBALS['egw']->accounts->name2id($matches[2],'account_email')) && $this->bo->check_acl_invite($data))
{
$event['participants'][$data] = $event['participant_types']['u'][$data] = $status;
}
elseif ((list($data) = ExecMethod2('addressbook.addressbook_bo.search',array(
'email' => $matches[2],
'email_home' => $matches[2],
),true,'','','',false,'OR')))
{
$event['participants']['c'.$data['id']] = $event['participant_types']['c'][$data['id']] = $status;
}
else
{
$event['participants']['e'.$email] = $event['participant_types']['e'][$email] = $status;
}
} }
elseif ((list($data) = ExecMethod2('addressbook.addressbook_bo.search',array( elseif (!$content['participants']['account'] && !$content['participants']['resource'])
'email' => $matches[2],
'email_home' => $matches[2],
),true,'','','',false,'OR')))
{ {
$event['participants']['c'.$data['id']] = $event['participant_types']['c'][$data['id']] = $status; $msg = lang('You need to select an account, contact or resource first!');
}
break;
case 'resource':
if (is_array($data) && isset($data['current']) )
{
list($app,$id) = explode(':',$data['current']);
} }
else else
{ {
$event['participants']['e'.$email] = $event['participant_types']['e'][$email] = $status; list($app,$id) = explode(':',$data);
} }
} foreach($this->bo->resources as $type => $data) if ($data['app'] == $app) break;
elseif (!$content['participants']['account'] && !$content['participants']['resource']) $uid = $this->bo->resources[$type]['app'] == $app ? $type.$id : false;
{ // check if new entry is no account (or contact entry of an account)
$msg = lang('You need to select an account, contact or resource first!'); if ($app != 'addressbook' || !($data = $GLOBALS['egw']->accounts->name2id($id,'person_id')) || !$this->bo->check_acl_invite($data))
}
break;
case 'resource':
if (is_array($data) && isset($data['current']) )
{
list($app,$id) = explode(':',$data['current']);
}
else
{
list($app,$id) = explode(':',$data);
}
foreach($this->bo->resources as $type => $data) if ($data['app'] == $app) break;
$uid = $this->bo->resources[$type]['app'] == $app ? $type.$id : false;
// check if new entry is no account (or contact entry of an account)
if ($app != 'addressbook' || !($data = $GLOBALS['egw']->accounts->name2id($id,'person_id')) || !$this->bo->check_acl_invite($data))
{
if ($uid && $id)
{ {
$status = isset($this->bo->resources[$type]['new_status']) ? ExecMethod($this->bo->resources[$type]['new_status'],$id) : 'U'; if ($uid && $id)
if ($status)
{ {
$event['participants'][$uid] = $event['participant_types'][$type][$id] = $status = isset($this->bo->resources[$type]['new_status']) ? ExecMethod($this->bo->resources[$type]['new_status'],$id) : 'U';
calendar_so::combine_status($status,$content['participants']['quantity'],$content['participants']['role']); if ($status)
} {
elseif(!$msg_permission_denied_added) $event['participants'][$uid] = $event['participant_types'][$type][$id] =
{ calendar_so::combine_status($status,$content['participants']['quantity'],$content['participants']['role']);
$msg .= lang('Permission denied!'); }
$msg_permission_denied_added = true; elseif(!$msg_permission_denied_added)
{
$msg .= lang('Permission denied!');
$msg_permission_denied_added = true;
}
} }
break;
} }
break; // fall-through for accounts entered as contact
} case 'account':
// fall-through for accounts entered as contact foreach(is_array($data) ? $data : explode(',',$data) as $uid)
case 'account': {
foreach(is_array($data) ? $data : explode(',',$data) as $uid)
{
if ($uid && $this->bo->check_acl_invite($uid)) if ($uid && $this->bo->check_acl_invite($uid))
{ {
$event['participants'][$uid] = $event['participant_types']['u'][$uid] = $event['participants'][$uid] = $event['participant_types']['u'][$uid] =
@ -345,14 +349,14 @@ class calendar_uiforms extends calendar_ui
$msg .= lang('Permission denied!'); $msg .= lang('Permission denied!');
$msg_permission_denied_added = true; $msg_permission_denied_added = true;
} }
} }
break; break;
default: // existing participant row default: // existing participant row
foreach(array('uid','status','quantity','role') as $name) foreach(array('uid','status','quantity','role') as $name)
{ {
$$name = $data[$name]; $$name = $data[$name];
} }
if ($content['participants']['delete'][$uid] || $content['participants']['delete'][md5($uid)]) if ($content['participants']['delete'][$uid] || $content['participants']['delete'][md5($uid)])
{ {
$uid = false; // entry has been deleted $uid = false; // entry has been deleted
@ -408,6 +412,7 @@ class calendar_uiforms extends calendar_ui
} }
} }
break; break;
}
} }
} }
} }
@ -461,7 +466,8 @@ class calendar_uiforms extends calendar_ui
$event['owner'] = !(int)$this->owner || !$this->bo->check_perms(EGW_ACL_ADD,0,$this->owner) ? $this->user : $this->owner; $event['owner'] = !(int)$this->owner || !$this->bo->check_perms(EGW_ACL_ADD,0,$this->owner) ? $this->user : $this->owner;
// Clear participant stati // Clear participant stati
foreach($event['participant_types'] as $type => &$participants) { foreach($event['participant_types'] as $type => &$participants)
{
foreach($participants as $id => &$response) foreach($participants as $id => &$response)
{ {
if($type == 'u' && $id == $event['owner']) continue; if($type == 'u' && $id == $event['owner']) continue;
@ -566,19 +572,11 @@ class calendar_uiforms extends calendar_ui
if ($edit_series_confirmed) if ($edit_series_confirmed)
{ {
$orig_event = $event; $orig_event = $event;
if (!empty($event['whole_day']))
{
// Adjust start to 0:00
$time = new egw_time($event['start']);
$time->setTime(0, 0, 0);
$event['start'] = egw_time::to($time, 'ts');
$time = new egw_time($next_occurrence['start']);
$time->setTime(0, 0, 0);
$next_occurrence['start'] = egw_time::to($time, 'ts');
}
$offset = $event['start'] - $old_event['start']; $offset = $event['start'] - $old_event['start'];
$event['start'] = $next_occurrence['start'] + $offset; $event['start'] = $next_occurrence['start'] + $offset;
$event['end'] = $next_occurrence['end'] + $offset; $event['end'] = $next_occurrence['end'] + $offset;
$event['participants'] = $old_event['participants'];
foreach ($old_event['recur_exception'] as $key => $exdate) foreach ($old_event['recur_exception'] as $key => $exdate)
{ {
if ($exdate > $this->bo->now_su) if ($exdate > $this->bo->now_su)