diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 1b901041a9b983b2af497f70d82b2c70cb10a562..e9bca0f6a0b815372fdb528191e7f6951649e859 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -505,6 +505,10 @@ class TicketsAjaxAPI extends AjaxController { $errors['err'] = sprintf('Ticket owner, %s, is a collaborator by default!', $user->getName()); elseif (($c=$ticket->addCollaborator($user, $errors))) { + $note = Format::htmlchars(sprintf('%s <%s> added as a collaborator', + $c->getName(), $c->getEmail())); + $ticket->logNote('New Collaborator Added', $note, + $thisstaff, false); $info = array('msg' => sprintf('%s added as a collaborator', $c->getName())); return self::_collaborators($ticket, $info); diff --git a/include/class.collaborator.php b/include/class.collaborator.php index e04d8571226f539cf82546a0c641a87eb1a026e3..9ba0e2764509f8d8e3cc6b3bb5a4457bf904c2a6 100644 --- a/include/class.collaborator.php +++ b/include/class.collaborator.php @@ -85,6 +85,15 @@ class Collaborator { return $this->user; } + function remove() { + + $sql='DELETE FROM '.TICKET_COLLABORATOR_TABLE + .' WHERE id='.db_input($this->getId()) + .' LIMIT 1'; + + return (db_query($sql) && db_affected_rows()); + } + static function add($info, &$errors) { if(!$info || !$info['ticketId'] || !$info['userId']) diff --git a/include/class.ticket.php b/include/class.ticket.php index 9d0b621af858d68c0390a67ce4fbcdcaa0640173..4596e33a4a5611a5a8697cb8b7db22fea778acc3 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -609,15 +609,22 @@ class Ticket { //XXX: Ugly for now function updateCollaborators($vars, &$errors) { + global $thisstaff; + if (!$thisstaff) return; //Deletes if($vars['del'] && ($ids=array_filter($vars['del']))) { - $sql='DELETE FROM '.TICKET_COLLABORATOR_TABLE - .' WHERE ticket_id='.db_input($this->getId()) - .' AND id IN('.implode(',', db_input($ids)).')'; - if(db_query($sql)) - $this->ht['collaborators'] -= db_affected_rows(); + $collabs = array(); + foreach ($ids as $k => $cid) { + if (($c=Collaborator::lookup($cid)) + && $c->getTicketId() == $this->getId() + && $c->remove()) + $collabs[] = Format::htmlchars(sprintf('%s <%s>', $c->getName(), $c->getEmail())); + } + + $this->logNote('Collaborators Removed', + implode("\n", $collabs), $thisstaff, false); } //statuses @@ -1456,10 +1463,19 @@ class Ticket { $this->setLastMsgId($message->getId()); //Add email recipients as collaborators - if($vars['recipients']) { - foreach($vars['recipients'] as $recipient) - if(($user=User::fromVars($recipient))) - $this->addCollaborator($user, $errors); + if ($vars['recipients']) { + $collabs = array(); + foreach ($vars['recipients'] as $recipient) { + if (($user=User::fromVars($recipient))) + if ($this->addCollaborator($user, $errors)) + $collabs[] = Format::htmlchars(sprintf('%s <%s>', + $user->getName(), $user->getEmail())); + } + //TODO: Can collaborators add others? + if ($collabs) { + $this->logNote('Collaborators CCed by enduser', + implode("\n", $collabs), 'EndUser', false); + } } if(!$alerts) return $message; //Our work is done...