diff --git a/include/class.organization.php b/include/class.organization.php index 908638685511bee16b87fdff82d3234f296c874a..5592aa95f8799a19067e79cb8f79ae9562f5ac29 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -44,6 +44,18 @@ class OrganizationModel extends VerySimpleModel { return $this->staff_id; } + function autoAddCollabs() { + return $this->check(self::COLLAB_ALL_MEMBERS | self::COLLAB_PRIMARY_CONTACT); + } + + function autoAddPrimaryContactsAsCollabs() { + return $this->check(self::COLLAB_PRIMARY_CONTACT); + } + + function autoAddMembersAsCollabs() { + return $this->check(self::COLLAB_ALL_MEMBERS); + } + function getUpdateDate() { return $this->updated; } diff --git a/include/class.ticket.php b/include/class.ticket.php index 57235d31b55a62bda807599d087983734f2e1c9e..663ecc57ff633a3a49ff5af83d7701330310ed51 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2415,6 +2415,28 @@ class Ticket { $dept = $ticket->getDept(); + // Add organizational collaborators + if ($org && $org->autoAddCollabs()) { + $pris = $org->autoAddPrimaryContactsAsCollabs(); + $members = $org->autoAddMembersAsCollabs(); + $settings = array('isactive' => true); + $collabs = array(); + foreach ($org->allMembers() as $u) { + if ($members || ($pris && $u->isPrimaryContact())) { + if ($c = $this->addCollaborator($u, $settings, $errors)) { + $collabs[] = (string) $c; + } + } + } + //TODO: Can collaborators add others? + if ($collabs) { + //TODO: Change EndUser to name of user. + $this->logNote(sprintf('Collaborators for %s organization added', + $org->getName()), + implode("<br>", $collabs), $org->getName(), false); + } + } + //post the message. unset($vars['cannedattachments']); //Ticket::open() might have it set as part of open & respond. $vars['title'] = $vars['subject']; //Use the initial subject as title of the post.