From 98a543262029e4e31fad23b08a027d729751b295 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Fri, 10 Jan 2014 17:08:38 +0000 Subject: [PATCH] Log internal note whenever a collaborators are added or removed. --- include/ajax.tickets.php | 4 ++++ include/class.collaborator.php | 9 +++++++++ include/class.ticket.php | 34 +++++++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 1b901041a..e9bca0f6a 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 e04d85712..9ba0e2764 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 9d0b621af..4596e33a4 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... -- GitLab