diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 68aaf24ae5180137412e5f05cad11a23b2e9c0f8..626f51af081721166e0d728e88cd615adc05423c 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -504,7 +504,8 @@ class TicketsAjaxAPI extends AjaxController { if ($user->getId() == $ticket->getOwnerId()) $errors['err'] = sprintf('Ticket owner, %s, is a collaborator by default!', $user->getName()); - elseif (($c=$ticket->addCollaborator($user, $errors))) { + elseif (($c=$ticket->addCollaborator($user, + array('isactive'=>1), $errors))) { $note = Format::htmlchars(sprintf('%s <%s> added as a collaborator', $c->getName(), $c->getEmail())); $ticket->logNote('New Collaborator Added', $note, diff --git a/include/api.tickets.php b/include/api.tickets.php index 45cbc2db97eccb120b0f22f7f47ba97ec8026ced..daa7ffe431a17d43d39227347f4b3efc0ac8053b 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -40,7 +40,7 @@ class TicketApiController extends ApiController { $supported = array_merge($supported, array('header', 'mid', 'emailId', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', - 'recipients' => array("*" => array("name", "email")) + 'recipients' => array('*' => array('name', 'email', 'source')) )); $supported['attachments']['*'][] = 'cid'; diff --git a/include/class.collaborator.php b/include/class.collaborator.php index bf57617d70b6f7555cae73db9403b5b79d47d8f7..bf823dacdb366279ec88b5de9657843283f72ba9 100644 --- a/include/class.collaborator.php +++ b/include/class.collaborator.php @@ -101,16 +101,17 @@ class Collaborator { static function add($info, &$errors) { - if(!$info || !$info['ticketId'] || !$info['userId']) + if (!$info || !$info['ticketId'] || !$info['userId']) $errors['err'] = 'Invalid or missing information'; - elseif(($c=self::lookup($info))) + elseif (($c=self::lookup($info))) $errors['err'] = sprintf('%s is already a collaborator', $c->getName()); - if($errors) return false; + if ($errors) return false; $sql='INSERT INTO '.TICKET_COLLABORATOR_TABLE - .' SET isactive=1, updated=NOW() ' + .' SET updated=NOW() ' + .' ,isactive='.db_input(isset($info['isactive']) ? $info['isactive'] : 0) .' ,ticket_id='.db_input($info['ticketId']) .' ,user_id='.db_input($info['userId']); diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 2b05c3a593fbaef7620f5259bc1728f065834153..9184ea8d146f6b1e4c683d8cc159d3d6a12ec27d 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -286,18 +286,21 @@ class MailFetcher { // Put together a list of recipients $tolist = array(); if($headerinfo->to) - $tolist = array_merge($tolist, $headerinfo->to); + $tolist['to'] = $headerinfo->to; if($headerinfo->cc) - $tolist = array_merge($tolist, $headerinfo->cc); + $tolist['cc'] = $headerinfo->cc; $header['recipients'] = array(); - foreach($tolist as $addr) { - if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { - $header['recipients'][] = array( - 'name' => $this->mime_decode(@$addr->personal), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); - } elseif(!$header['emailId']) { - $header['emailId'] = $emailId; + foreach($tolist as $source => $list) { + foreach($list as $addr) { + if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { + $header['recipients'][] = array( + 'source' => "Email ($source)", + 'name' => $this->mime_decode(@$addr->personal), + 'email' => strtolower($addr->mailbox).'@'.$addr->host); + } elseif(!$header['emailId']) { + $header['emailId'] = $emailId; + } } } diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 42d4abe242eb9e6b4e202a83d589076e3b858995..fc865d4de2c333738ea107f73b450cb1cdcbff30 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -393,18 +393,21 @@ class EmailDataParser { $data['recipients'] = array(); $tolist = array(); if(($to = $parser->getToAddressList())) - $tolist = array_merge($tolist, $to); + $tolist['to'] = $to; if(($cc = $parser->getCcAddressList())) - $tolist = array_merge($tolist, $cc); - - foreach ($tolist as $addr) { - if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { - $data['recipients'][] = array( - 'name' => trim(@$addr->personal, '"'), - 'email' => strtolower($addr->mailbox).'@'.$addr->host); - } elseif(!$data['emailId']) { - $data['emailId'] = $emailId; + $tolist['cc'] = $cc; + + foreach ($tolist as $source => $list) { + foreach($list as $addr) { + if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { + $data['recipients'][] = array( + 'source' => "Email ($source)", + 'name' => trim(@$addr->personal, '"'), + 'email' => strtolower($addr->mailbox).'@'.$addr->host); + } elseif(!$data['emailId']) { + $data['emailId'] = $emailId; + } } } @@ -412,8 +415,8 @@ class EmailDataParser { if(!$data['emailId']) { unset($data['recipients']); $emailId = 0; - if($bcc = $parser->getBccAddressList()) - foreach ($bcc as $addr) { + if($bcc = $parser->getBccAddressList()) { + foreach ($bcc as $addr) if(($emailId=Email::getIdByEmail($addr->mailbox.'@'.$addr->host))) break; } diff --git a/include/class.ticket.php b/include/class.ticket.php index 5f829a86533c90aacb99dbf137a9f3d35b792da7..1a1a822cc8b6865c2326a1ac2ae08c63ff5699dd 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -586,15 +586,15 @@ class Ticket { return $this->collaborators; } - function addCollaborator($user, &$errors) { + function addCollaborator($user, $vars, &$errors) { - if(!$user || $user->getId()==$this->getOwnerId()) + if (!$user || $user->getId()==$this->getOwnerId()) return null; - $vars = array( + $vars = array_merge(array( 'ticketId' => $this->getId(), - 'userId' => $user->getId()); - if(!($c=Collaborator::add($vars, $errors))) + 'userId' => $user->getId()), $vars); + if (!($c=Collaborator::add($vars, $errors))) return null; $this->collaborators = null; @@ -966,8 +966,8 @@ class Ticket { $options['references'] = $vars['references']; foreach($collaborators as $collaborator) { - $msg = $this->replaceVars($msg, array('recipient' => $collaborator)); - $email->send($collaborator->getEmail(), $msg['subj'], $msg['body'], $attachments, + $notice = $this->replaceVars($msg, array('recipient' => $collaborator)); + $email->send($collaborator->getEmail(), $notice['subj'], $notice['body'], $attachments, $options); } @@ -1459,15 +1459,22 @@ class Ticket { //Add email recipients as collaborators if ($vars['recipients']) { + //TODO: Disable collaborators added by other collaborator + // staff approval will be required. + $info = array('isactive' => 1); $collabs = array(); foreach ($vars['recipients'] as $recipient) { if (($user=User::fromVars($recipient))) - if ($c=$this->addCollaborator($user, $errors)) - $collabs[] = $c; + if ($c=$this->addCollaborator($user, $info, $errors)) + $collabs[] = sprintf('%s%s', + (string) $c, + $recipient['source'] ? " via {$recipient['source']}" : '' + ); } //TODO: Can collaborators add others? if ($collabs) { - $this->logNote('Collaborators CCed by enduser', + //TODO: Change EndUser to name of user. + $this->logNote('Collaborators added by enduser', implode("<br>", $collabs), 'EndUser', false); } } diff --git a/include/staff/templates/collaborators-preview.tmpl.php b/include/staff/templates/collaborators-preview.tmpl.php index 45cfecca268ddca8e8c2d9dfc91ef432613ab419..f41150b7b6f29e8786802b497bbaa71f603deb8a 100644 --- a/include/staff/templates/collaborators-preview.tmpl.php +++ b/include/staff/templates/collaborators-preview.tmpl.php @@ -6,7 +6,7 @@ if (($users=$ticket->getCollaborators())) {?> <?php foreach($users as $user) { echo sprintf('<tr><td %s><i class="icon-%s"></i> %s <em><%s></em></td></tr>', - ($user->isActive()? 'class="faded"' : ''), + ($user->isActive()? '' : 'class="faded"'), ($user->isActive()? 'comments' : 'comment-alt'), $user->getName(), $user->getEmail()); diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 1415ce76d059cb8617c26f7f66456e51ba9bf4b9..bbd837c9ce8b94f5cd292854f13e85950a47be18 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -265,11 +265,15 @@ while ($row = db_fetch_array($res)) { // Fetch attachment and thread entry counts if ($results) { - $counts_sql = 'SELECT ticket.ticket_id, count(attach.attach_id) as attachments, - count(DISTINCT thread.id) as thread_count + $counts_sql = 'SELECT ticket.ticket_id, + count(DISTINCT attach.attach_id) as attachments, + count(DISTINCT thread.id) as thread_count, + count(DISTINCT collab.id) as collaborators FROM '.TICKET_TABLE.' ticket LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (ticket.ticket_id=attach.ticket_id) ' .' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON ( ticket.ticket_id=thread.ticket_id) ' + .' LEFT JOIN '.TICKET_COLLABORATOR_TABLE.' collab + ON ( ticket.ticket_id=collab.ticket_id) ' .' WHERE ticket.ticket_id IN ('.implode(',', db_input(array_keys($results))).') GROUP BY ticket.ticket_id'; $ids_res = db_query($counts_sql); @@ -404,11 +408,17 @@ if ($results) { <a class="Icon <?php echo strtolower($row['source']); ?>Ticket ticketPreview" title="Preview Ticket" href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $tid; ?></a></td> <td align="center" nowrap><?php echo Format::db_datetime($row['effective_date']); ?></td> - <td><a <?php if($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?> + <td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?> href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a> - - <?php echo ($threadcount>1)?" <small>($threadcount)</small> ":''?> - <?php echo $row['attachments']?"<span class='Icon file'> </span>":''; ?> + <?php + if ($threadcount>1) + echo "<small>($threadcount)</small> ".'<i + class="icon-fixed-width icon-comments-alt"></i> '; + if ($row['collaborators']) + echo '<i class="icon-fixed-width icon-group faded"></i> '; + if ($row['attachments']) + echo '<i class="icon-fixed-width icon-paperclip"></i> '; + ?> </td> <td nowrap> <?php echo Format::truncate($row['name'],22,strpos($row['name'],'@')); ?> </td> <?php