Skip to content
Snippets Groups Projects
Commit a361e75b authored by Peter Rotich's avatar Peter Rotich
Browse files

Add email recepients as collaborators

parent 4275fe33
No related branches found
No related tags found
No related merge requests found
...@@ -457,34 +457,23 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -457,34 +457,23 @@ class TicketsAjaxAPI extends AjaxController {
|| !$ticket->checkStaffAccess($thisstaff)) || !$ticket->checkStaffAccess($thisstaff))
Http::response(404, 'No such ticket'); Http::response(404, 'No such ticket');
//If not a post then assume new collaborator form
if(!$_POST)
return self::_addcollaborator($ticket);
$user = $form = null;
if (isset($_POST['id']) && $_POST['id']) { //Existing user/
$user = User::lookup($_POST['id']);
} else { //We're creating a new user!
$form = UserForm::getUserForm()->getForm($_POST);
$user = User::fromForm($form);
}
$errors = $info = array(); $errors = $info = array();
$user = null;
$form = UserForm::getInstance();
if ($form->isValid())
$user = User::fromForm($form->getClean());
if ($user && ($c=$ticket->addCollaborator($user, $errors))) { if ($user && ($c=$ticket->addCollaborator($user, $errors))) {
$info =array('msg' => sprintf('%s added as a collaborator', $info +=array('msg' => sprintf('%s added as a collaborator',
$c->getName())); $c->getName()));
$form = null;
return self::_collaborators($ticket, $info); } elseif($errors && $errors['err']) {
} $info +=array('add_error' => $errors['err']);
if($errors && $errors['err']) {
$info +=array('error' => $errors['err']);
} else { } else {
$info +=array('error' =>'Unable to add collaborator - try again'); $info +=array('add_error' =>'Errors occurred - try again');
} }
return self::_collaborators($ticket, $form, $info);
return self::_addcollaborator($ticket, $user, $form, $info);
} }
function updateCollaborator($cid) { function updateCollaborator($cid) {
...@@ -504,7 +493,7 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -504,7 +493,7 @@ class TicketsAjaxAPI extends AjaxController {
$info = array('msg' => sprintf('%s updated successfully', $info = array('msg' => sprintf('%s updated successfully',
$c->getName())); $c->getName()));
return self::_collaborators($ticket, $info); return self::_collaborators($ticket, null, $info);
} }
function viewCollaborator($cid) { function viewCollaborator($cid) {
...@@ -525,22 +514,7 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -525,22 +514,7 @@ class TicketsAjaxAPI extends AjaxController {
|| !$ticket->checkStaffAccess($thisstaff)) || !$ticket->checkStaffAccess($thisstaff))
Http::response(404, 'No such ticket'); Http::response(404, 'No such ticket');
if($ticket->getCollaborators()) return self::_collaborators($ticket);
return self::_collaborators($ticket);
return self::_addcollaborator($ticket);
}
function _addcollaborator($ticket, $user=null, $form=null, $info=array()) {
$info += array(
'title' => sprintf('Ticket #%s: Add a collaborator', $ticket->getNumber()),
'action' => sprintf('#tickets/%d/add-collaborator', $ticket->getId())
);
return self::_userlookup($user, $form, $info);
} }
...@@ -558,26 +532,22 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -558,26 +532,22 @@ class TicketsAjaxAPI extends AjaxController {
$info +=array('error' => $errors['err']); $info +=array('error' => $errors['err']);
} }
return self::_collaborators($ticket, $info); return self::_collaborators($ticket, null, $info);
} }
function _collaborator($collaborator, $form=null, $info=array()) { function _collaborator($collaborator, $form=null, $errors=array()) {
$info += array('action' => '#collaborators/'.$collaborator->getId());
$user = $collaborator->getUser();
ob_start(); ob_start();
include(STAFFINC_DIR . 'templates/user.tmpl.php'); include(STAFFINC_DIR . 'templates/collaborator.tmpl.php');
$resp = ob_get_contents(); $resp = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $resp; return $resp;
} }
function _collaborators($ticket, $info=array()) { function _collaborators($ticket, $form=null, $info=array()) {
ob_start(); ob_start();
include(STAFFINC_DIR . 'templates/collaborators.tmpl.php'); include(STAFFINC_DIR . 'templates/collaborators.tmpl.php');
...@@ -586,86 +556,5 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -586,86 +556,5 @@ class TicketsAjaxAPI extends AjaxController {
return $resp; return $resp;
} }
function viewUser($tid) {
global $thisstaff;
if(!$thisstaff
|| !($ticket=Ticket::lookup($tid))
|| !$ticket->checkStaffAccess($thisstaff))
Http::response(404, 'No such ticket');
if(!($user = $ticket->getOwner()))
Http::response(404, 'Unknown user');
$info = array(
'title' => sprintf('Ticket #%s: %s', $ticket->getNumber(), $user->getName())
);
ob_start();
include(STAFFINC_DIR . 'templates/user.tmpl.php');
$resp = ob_get_contents();
ob_end_clean();
return $resp;
}
function updateUser($tid) {
global $thisstaff;
if(!$thisstaff
|| !($ticket=Ticket::lookup($tid))
|| !$ticket->checkStaffAccess($thisstaff)
|| ! ($user = $ticket->getOwner()))
Http::response(404, 'No such ticket/user');
$errors = array();
if($user->updateInfo($_POST, $errors))
Http::response(201, $user->to_json());
$forms = $user->getForms();
$info = array(
'title' => sprintf('Ticket #%s: %s', $ticket->getNumber(), $user->getName())
);
ob_start();
include(STAFFINC_DIR . 'templates/user.tmpl.php');
$resp = ob_get_contents();
ob_end_clean();
return $resp;
}
function changeUserForm($tid) {
global $thisstaff;
if(!$thisstaff
|| !($ticket=Ticket::lookup($tid))
|| !$ticket->checkStaffAccess($thisstaff))
Http::response(404, 'No such ticket');
$user = $ticket->getOwner();
$info = array(
'title' => sprintf('Change user for ticket #%s', $ticket->getNumber())
);
return self::_userlookup($user, $info);
}
function _userlookup($user, $form, $info) {
ob_start();
include(STAFFINC_DIR . 'templates/user-lookup.tmpl.php');
$resp = ob_get_contents();
ob_end_clean();
return $resp;
}
} }
?> ?>
...@@ -40,7 +40,7 @@ class TicketApiController extends ApiController { ...@@ -40,7 +40,7 @@ class TicketApiController extends ApiController {
$supported = array_merge($supported, array('header', 'mid', $supported = array_merge($supported, array('header', 'mid',
'emailId', 'ticketId', 'reply-to', 'reply-to-name', 'emailId', 'ticketId', 'reply-to', 'reply-to-name',
'in-reply-to', 'references', 'in-reply-to', 'references',
'collaborators' => array("*" => array("name", "email")) 'recipients' => array("*" => array("name", "email"))
)); ));
$supported['attachments']['*'][] = 'cid'; $supported['attachments']['*'][] = 'cid';
......
...@@ -290,10 +290,10 @@ class MailFetcher { ...@@ -290,10 +290,10 @@ class MailFetcher {
if($headerinfo->cc) if($headerinfo->cc)
$tolist = array_merge($tolist, $headerinfo->cc); $tolist = array_merge($tolist, $headerinfo->cc);
$header['collaborators'] = array(); $header['recipients'] = array();
foreach($tolist as $addr) { foreach($tolist as $addr) {
if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) {
$header['collaborators'][] = array( $header['recipients'][] = array(
'name' => $this->mime_decode(@$addr->personal), 'name' => $this->mime_decode(@$addr->personal),
'email' => strtolower($addr->mailbox).'@'.$addr->host); 'email' => strtolower($addr->mailbox).'@'.$addr->host);
} elseif(!$header['emailId']) { } elseif(!$header['emailId']) {
...@@ -303,12 +303,12 @@ class MailFetcher { ...@@ -303,12 +303,12 @@ class MailFetcher {
//BCCed? //BCCed?
if(!$header['emailId']) { if(!$header['emailId']) {
unset($header['collaborators']); //Nuke the recipients - we were bcced unset($header['recipients']); //Nuke the recipients - we were bcced
if($headerinfo->bcc) if ($headerinfo->bcc) {
foreach($headerinfo->bcc as $addr) foreach($headerinfo->bcc as $addr)
if(!$header['emailId'] if (($header['emailId'] = Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host)))
&& ($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) break;
$header['emailId'] = $emailId; }
} }
// Ensure we have a message-id. If unable to read it out of the // Ensure we have a message-id. If unable to read it out of the
......
...@@ -386,7 +386,7 @@ class EmailDataParser { ...@@ -386,7 +386,7 @@ class EmailDataParser {
//TO Address:Try to figure out the email address... associated with the incoming email. //TO Address:Try to figure out the email address... associated with the incoming email.
$data['emailId'] = 0; $data['emailId'] = 0;
$data['collaborators'] = array(); $data['recipients'] = array();
$tolist = array(); $tolist = array();
if(($to = $parser->getToAddressList())) if(($to = $parser->getToAddressList()))
$tolist = array_merge($tolist, $to); $tolist = array_merge($tolist, $to);
...@@ -396,7 +396,7 @@ class EmailDataParser { ...@@ -396,7 +396,7 @@ class EmailDataParser {
foreach ($tolist as $addr) { foreach ($tolist as $addr) {
if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) { if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) {
$data['collaborators'][] = array( $data['recipients'][] = array(
'name' => trim(@$addr->personal, '"'), 'name' => trim(@$addr->personal, '"'),
'email' => strtolower($addr->mailbox).'@'.$addr->host); 'email' => strtolower($addr->mailbox).'@'.$addr->host);
} elseif(!$data['emailId']) { } elseif(!$data['emailId']) {
...@@ -406,7 +406,7 @@ class EmailDataParser { ...@@ -406,7 +406,7 @@ class EmailDataParser {
//maybe we got BCC'ed?? //maybe we got BCC'ed??
if(!$data['emailId']) { if(!$data['emailId']) {
unset($data['collaborators']); unset($data['recipients']);
$emailId = 0; $emailId = 0;
if($bcc = $parser->getBccAddressList()) if($bcc = $parser->getBccAddressList())
foreach ($bcc as $addr) { foreach ($bcc as $addr) {
......
...@@ -1456,6 +1456,13 @@ class Ticket { ...@@ -1456,6 +1456,13 @@ class Ticket {
$this->setLastMsgId($message->getId()); $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(!$alerts) return $message; //Our work is done... if(!$alerts) return $message; //Our work is done...
$autorespond = true; $autorespond = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment