From fada2d433e466e7087d8e710dd1e4d2c1b94b487 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 12 Jul 2016 11:22:25 -0600 Subject: [PATCH] When adding a mailing list as participant, immediately expand it to contacts --- calendar/inc/class.calendar_bo.inc.php | 61 ++++++++++++++------ calendar/inc/class.calendar_boupdate.inc.php | 22 ------- calendar/inc/class.calendar_uiforms.inc.php | 20 +++++++ 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index 8f41ca3e22..609c69166a 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -362,6 +362,45 @@ class calendar_bo return $data; } + /** + * Enumerates the contacts in a contact list, and returns the list of contact IDs + * + * This is used to enable mailing lists as owner/participant + * + * @param string $id Mailing list participant ID, which is the mailing list + * ID prefixed with 'l' + * @param boolean $ignore_acl = false Flag to skip ACL checks + * @param boolean $use_freebusy =true should freebusy rights are taken into account, default true, can be set to false eg. for a search + * + * @return array + */ + public function enum_mailing_list($id, $ignore_acl= false, $use_freebusy = true) + { + $contact_list = array(); + $contacts = new Api\Contacts(); + if($contacts->check_list((int)substr($id,1), ACL::READ)) + { + $options = array('list' => substr($id,1)); + $lists = $contacts->search('',true,'','','',false,'AND',false,$options); + if(!$lists) + { + return $contact_list; + } + foreach($lists as &$contact) + { + $contact = 'c'.$contact['id']; + if ($ignore_acl || $this->check_perms(ACL::READ|self::ACL_READ_FOR_PARTICIPANTS|($use_freebusy?self::ACL_FREEBUSY:0),0,$contact)) + { + if ($contact && !in_array($contact,$contact_list)) // already added? + { + $contact_list[] = $contact; + } + } + } + } + return $contact_list; + } + /** * Add group-members as participants with status 'G' * @@ -413,27 +452,11 @@ class calendar_bo // Handle email lists if(!is_numeric($user) && $user[0] == 'l') { - $contacts = new Api\Contacts(); - if($contacts->check_list((int)substr($user,1), ACL::READ)) + foreach($this->enum_mailing_list($user, $ignore_acl, $use_freebusy) as $contact) { - $users[] = $user; - - $options = array('list' => substr($user,1)); - $lists = $contacts->search('',true,'','','',false,'AND',false,$options); - if(!$lists) + if ($contact && !in_array($contact,$users)) // already added? { - continue; - } - foreach($lists as &$contact) - { - $contact = 'c'.$contact['id']; - if ($ignore_acl || $this->check_perms(ACL::READ|self::ACL_READ_FOR_PARTICIPANTS|($use_freebusy?self::ACL_FREEBUSY:0),0,$contact)) - { - if ($contact && !in_array($contact,$users)) // already added? - { - $users[] = $contact; - } - } + $users[] = $contact; } } continue; diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index 630e92e667..d2f1018f1b 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -839,28 +839,6 @@ class calendar_boupdate extends calendar_bo } } } - // Mailing lists - else if (!is_numeric($userid) && $userid[0] == 'l') - { - if(!$contact_obj) - { - $contact_obj = new Api\Contacts(); - } - $options = array('list' => substr($user,1)); - $contacts = $contact_obj->search('',true,'','','',false,'AND',false,$options); - if(!$contacts) - { - continue; - } - foreach($contacts as &$contact) - { - $contact = 'c'.$contact['id']; - if ($contact && !isset($to_notify[$contact])) // already added? - { - $to_notify[$contact] = 'G'; - } - } - } } $user_prefs = $GLOBALS['egw_info']['user']['preferences']; $startdate = new Api\DateTime($event['start']); diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index e5f104d071..be14c82d13 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -158,6 +158,16 @@ class calendar_uiforms extends calendar_ui } elseif (is_array($this->bo->resources[$uid[0]])) { + // Expand mailing lists + if($uid[0] == 'l') + { + foreach($this->bo->enum_mailing_list($uid) as $contact) + { + $participants[$contact] = $participant_types['c'][substr($contact,1)] = + calendar_so::combine_status('U',1,'REQ-PARTICIPANT'); + } + continue; + } // if contact is a user, use the user instead (as the GUI) if ($uid[0] == 'c' && ($account_id = $GLOBALS['egw']->accounts->name2id(substr($uid,1),'person_id'))) { @@ -419,6 +429,16 @@ class calendar_uiforms extends calendar_ui ExecMethod($this->bo->resources[$type]['new_status'],$id) : ($uid == $this->bo->user ? 'A' : 'U'); + // Expand mailing lists + if($type == 'l') + { + foreach($this->bo->enum_mailing_list($participant) as $contact) + { + $event['participants'][$contact] = $event['participant_types']['c'][substr($contact,1)] = + calendar_so::combine_status($status,$content['participants']['quantity'],$content['participants']['role']); + } + continue; + } if ($status) { $res_info = $this->bo->resource_info($uid);