/** * @param Model_DevblocksEvent $event */ function handleEvent(Model_DevblocksEvent $event) { switch ($event->id) { case 'cron.maint': DAO_TicketAuditLog::maint(); break; case 'ticket.merge': // Listen for ticket merges and update our internal ticket_id records @($new_ticket_id = $event->params['new_ticket_id']); @($old_ticket_ids = $event->params['old_ticket_ids']); if (empty($new_ticket_id) || empty($old_ticket_ids)) { return; } $fields = array(DAO_TicketAuditLog::TICKET_ID => $new_ticket_id); DAO_TicketAuditLog::updateWhere($fields, sprintf("%s IN (%s)", DAO_TicketAuditLog::TICKET_ID, implode(',', $old_ticket_ids))); break; case 'ticket.property.pre_change': @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); // Filter out any mandatory changes we could care less about unset($changed_fields[DAO_Ticket::UPDATED_DATE]); unset($changed_fields[DAO_Ticket::MASK]); unset($changed_fields[DAO_Ticket::FIRST_MESSAGE_ID]); unset($changed_fields[DAO_Ticket::FIRST_WROTE_ID]); unset($changed_fields[DAO_Ticket::LAST_WROTE_ID]); unset($changed_fields[DAO_Ticket::INTERESTING_WORDS]); @($tickets = DAO_Ticket::getTickets($ticket_ids)); // Is a worker around to invoke this change? 0 = automatic @($worker_id = null != ($active_worker = CerberusApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0); if (is_array($tickets) && !empty($tickets) && is_array($changed_fields) && !empty($changed_fields)) { foreach ($tickets as $ticket_id => $ticket) { /* @var $ticket CerberusTicket */ foreach ($changed_fields as $changed_field => $changed_value) { if (is_array($changed_value)) { $changed_value = implode("\r\n", $changed_value); } // If different if (isset($ticket->{$changed_field}) && 0 != strcmp($ticket->{$changed_field}, $changed_value)) { $fields = array(DAO_TicketAuditLog::TICKET_ID => $ticket_id, DAO_TicketAuditLog::WORKER_ID => $worker_id, DAO_TicketAuditLog::CHANGE_DATE => time(), DAO_TicketAuditLog::CHANGE_FIELD => $changed_field, DAO_TicketAuditLog::CHANGE_VALUE => substr($changed_value, 0, 128)); $log_id = DAO_TicketAuditLog::create($fields); } } } } break; } }
private function _workerAssigned($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); if (empty($ticket_ids) || empty($changed_fields)) { return; } @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]); // Make sure a next worker was assigned if (empty($next_worker_id)) { return; } @($active_worker = CerberusApplication::getActiveWorker()); // Make sure we're not assigning work to ourselves, if so then bail if (null != $active_worker && $active_worker->id == $next_worker_id) { return; } $url_writer = DevblocksPlatform::getUrlService(); $mail_service = DevblocksPlatform::getMailService(); $mailer = null; // lazy load $settings = DevblocksPlatform::getPluginSettingsService(); $default_from = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, ''); $default_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''); // Loop through all assigned tickets $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ // If the next worker value didn't change, skip if ($ticket->next_worker_id == $next_worker_id) { continue; } // Find all our matching filters if (empty($ticket) || false == ($matches = Model_WatcherMailFilter::getMatches($ticket, 'ticket_assignment', $next_worker_id))) { return; } // (Action) Send Notification $this->_sendNotifications($matches, $url_writer->write('c=display&mask=' . $ticket->mask, true, false), sprintf("[Ticket] %s", $ticket->subject)); // (Action) Forward Email To: // Sanitize and combine all the destination addresses $notify_emails = $this->_getMailingListFromMatches($matches); if (empty($notify_emails)) { return; } if (null == @($last_message = end($ticket->getMessages()))) { /* @var $last_message CerberusMessage */ continue; } if (null == @($last_headers = $last_message->getHeaders())) { continue; } $reply_to = $default_from; $reply_personal = $default_personal; // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM)); if (!empty($group_from)) { $reply_to = $group_from; } @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL)); if (!empty($group_personal)) { $reply_personal = $group_personal; } } if (is_array($notify_emails)) { foreach ($notify_emails as $send_to) { try { if (null == $mailer) { $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); } // Create the message $mail = $mail_service->createMessage(); $mail->setTo(array($send_to)); $mail->setFrom(array($reply_to => $reply_personal)); $mail->setReplyTo($reply_to); $mail->setSubject(sprintf("[assignment #%s]: %s", $ticket->mask, $ticket->subject)); $headers = $mail->getHeaders(); if (false !== @($in_reply_to = $last_headers['in-reply-to'])) { $headers->addTextHeader('References', $in_reply_to); $headers->addTextHeader('In-Reply-To', $in_reply_to); } $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $headers->addTextHeader('Precedence', 'List'); $headers->addTextHeader('Auto-Submitted', 'auto-generated'); $mail->setBody($last_message->getContent()); $result = $mailer->send($mail); } catch (Exception $e) { // } } } } }
private function _workerAssigned($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); if (empty($ticket_ids) || empty($changed_fields)) { return; } @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]); // Make sure a next worker was assigned if (empty($next_worker_id)) { return; } @($active_worker = CerberusApplication::getActiveWorker()); @($workers = DAO_Worker::getAllActive()); // Make sure we're not assigning work to ourselves, if so then bail if (null != $active_worker && $active_worker->id == $next_worker_id) { return; } // Make sure the worker exists and is not disabled if (!isset($workers[$next_worker_id])) { return; } $helpdesk_senders = CerberusApplication::getHelpdeskSenders(); $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $settings = CerberusSettings::getInstance(); $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''); $default_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, ''); @($worker_notify_email = DAO_WorkerPref::get($next_worker_id, ChWatchersPlugin::WORKER_PREF_ASSIGN_EMAIL, '')); // If our next worker doesn't have an assignment pref if (empty($worker_notify_email)) { return; } // Don't allow silly workers to use the inbound addresses as their watchers if (isset($helpdesk_senders[$worker_notify_email])) { return; } // Send notifications to this worker for each ticket $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ // If the next worker value didn't change, skip if ($ticket->next_worker_id == $next_worker_id) { continue; } if (null == @($last_message = end($ticket->getMessages()))) { /* @var $last_message CerberusMessage */ continue; } if (null == @($last_headers = $last_message->getHeaders())) { continue; } $reply_to = $default_from; $reply_personal = $default_personal; // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM)); if (!empty($group_from)) { $reply_to = $group_from; } @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL)); if (!empty($group_personal)) { $reply_personal = $group_personal; } } try { // Create the message $rcpt_to = new Swift_RecipientList(); $a_rcpt_to = array(); $mail_from = new Swift_Address($reply_to, $reply_personal); $rcpt_to->addTo($worker_notify_email); $a_rcpt_to = new Swift_Address($worker_notify_email); $mail = $mail_service->createMessage(); $mail->setTo($a_rcpt_to); $mail->setFrom($mail_from); $mail->setReplyTo($reply_to); $mail->setSubject(sprintf("[assignment #%s]: %s", $ticket->mask, $ticket->subject)); if (false !== @($in_reply_to = $last_headers['in-reply-to'])) { $mail->headers->set('References', $in_reply_to); $mail->headers->set('In-Reply-To', $in_reply_to); } $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mail->headers->set('Precedence', 'List'); $mail->headers->set('Auto-Submitted', 'auto-generated'); $mail->attach(new Swift_Message_Part($last_message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE)); $mailer->send($mail, $rcpt_to, $mail_from); } catch (Exception $e) { // } } }
function showBatchPanelAction() { @($ids = DevblocksPlatform::importGPC($_REQUEST['ids'])); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'])); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('view_id', $view_id); $unique_sender_ids = array(); $unique_subjects = array(); if (!empty($ids)) { $ticket_ids = DevblocksPlatform::parseCsvString($ids); if (empty($ticket_ids)) { break; } $tickets = DAO_Ticket::getTickets($ticket_ids); if (is_array($tickets)) { foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ $ptr =& $unique_sender_ids[$ticket->first_wrote_address_id]; $ptr = intval($ptr) + 1; $ptr =& $unique_subjects[$ticket->subject]; $ptr = intval($ptr) + 1; } } arsort($unique_subjects); // sort by occurrences $senders = DAO_Address::getWhere(sprintf("%s IN (%s)", DAO_Address::ID, implode(',', array_keys($unique_sender_ids)))); foreach ($senders as $sender) { $ptr =& $unique_senders[$sender->email]; $ptr = intval($ptr) + 1; } arsort($unique_senders); unset($senders); unset($unique_sender_ids); @$tpl->assign('ticket_ids', $ticket_ids); @$tpl->assign('unique_senders', $unique_senders); @$tpl->assign('unique_subjects', $unique_subjects); } // Teams $teams = DAO_Group::getAll(); $tpl->assign('teams', $teams); // Categories $team_categories = DAO_Bucket::getTeams(); // [TODO] Cache these $tpl->assign('team_categories', $team_categories); $workers = DAO_Worker::getAllActive(); $tpl->assign('workers', $workers); // Custom Fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID); $tpl->assign('custom_fields', $custom_fields); $tpl->display('file:' . $this->_TPL_PATH . 'tickets/rpc/batch_panel.tpl'); }
private function _workerAssigned($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); if (empty($ticket_ids) || empty($changed_fields)) { return; } @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]); // Make sure a next worker was assigned if (empty($next_worker_id)) { return; } $url_writer = DevblocksPlatform::getUrlService(); $mail_service = DevblocksPlatform::getMailService(); $mailer = null; // lazy load $settings = CerberusSettings::getInstance(); $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''); $default_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, ''); // Loop through all assigned tickets $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ // If the next worker value didn't change, skip if ($ticket->next_worker_id == $next_worker_id) { continue; } // (Action) Forward Email To: // Sanitize and combine all the destination addresses $next_worker = DAO_Worker::getAgent($next_worker_id); $notify_emails = $next_worker->email; if (empty($notify_emails)) { return; } if (null == @($last_message = end($ticket->getMessages()))) { /* @var $last_message CerberusMessage */ continue; } if (null == @($last_headers = $last_message->getHeaders())) { continue; } $reply_to = $default_from; $reply_personal = $default_personal; // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM)); if (!empty($group_from)) { $reply_to = $group_from; } @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL)); if (!empty($group_personal)) { $reply_personal = $group_personal; } } try { if (null == $mailer) { $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); } // Create the message $mail = $mail_service->createMessage(); $mail->setTo(array($notify_emails)); $mail->setFrom(array($reply_to => $reply_personal)); $mail->setReplyTo($reply_to); $mail->setSubject(sprintf("[RW: assignment #%s]: %s", $ticket->mask, $ticket->subject)); $headers = $mail->getHeaders(); if (false !== @($in_reply_to = $last_headers['in-reply-to'])) { $headers->addTextHeader('References', $in_reply_to); $headers->addTextHeader('In-Reply-To', $in_reply_to); } $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $headers->addTextHeader('Precedence', 'List'); $headers->addTextHeader('Auto-Submitted', 'auto-generated'); $mail->setBody($last_message->getContent()); $result = $mailer->send($mail); } catch (Exception $e) { if (!empty($message_id)) { $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR); DAO_MessageNote::create($fields); } } } }
private function _handleTicketClosed($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); // for anything other than setting is_closed = 1, we don't need to do anything // also don't send if the ticket is being deleted if (!isset($changed_fields[DAO_Ticket::IS_CLOSED]) || 1 != $changed_fields[DAO_Ticket::IS_CLOSED] || isset($changed_fields[DAO_Ticket::IS_DELETED]) && 1 == $changed_fields[DAO_Ticket::IS_DELETED]) { return; } $group_settings = DAO_GroupSettings::getSettings(); if (!empty($ticket_ids)) { $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ if (!isset($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY_ENABLED])) { continue; } if (1 == $ticket->is_deleted) { continue; } if ($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY_ENABLED] && !empty($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY])) { if (null != ($msg_first = DAO_Ticket::getMessage($ticket->first_message_id))) { // First sender $ticket_sender = ''; $ticket_sender_first = ''; if (null != ($sender_first = DAO_Address::get($msg_first->address_id))) { $ticket_sender = $sender_first->email; $ticket_sender_first = $sender_first->first_name; } // First body $ticket_body = $msg_first->getContent(); } CerberusMail::sendTicketMessage(array('ticket_id' => $ticket->id, 'message_id' => $ticket->first_message_id, 'content' => str_replace(array('#ticket_id#', '#mask#', '#subject#', '#timestamp#', '#sender#', '#sender_first#', '#orig_body#'), array($ticket->id, $ticket->mask, $ticket->subject, date('r'), $ticket_sender, $ticket_sender_first, ltrim($ticket_body)), $group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY]), 'is_autoreply' => false, 'dont_keep_copy' => true)); } } } }
private function _workerAssigned($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); if (empty($ticket_ids) || empty($changed_fields)) { return; } @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]); // Make sure a next worker was assigned if (empty($next_worker_id)) { return; } @($active_worker = CerberusApplication::getActiveWorker()); // Make sure we're not assigning work to ourselves, if so then bail if (null != $active_worker && $active_worker->id == $next_worker_id) { return; } // Make sure the worker exists and is not disabled // if(!isset($workers[$next_worker_id])) // return; $mail_service = DevblocksPlatform::getMailService(); $mailer = null; // lazy load $settings = CerberusSettings::getInstance(); $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''); $default_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, ''); // Loop through all assigned tickets $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ // If the next worker value didn't change, skip if ($ticket->next_worker_id == $next_worker_id) { continue; } // Find all our matching filters if (false == ($matches = Model_WatcherMailFilter::getMatches($ticket, 'ticket_assignment', $next_worker_id))) { return; } // Sanitize and combine all the destination addresses $notify_emails = $this->_getMailingListFromMatches($matches); if (empty($notify_emails)) { return; } if (null == @($last_message = end($ticket->getMessages()))) { /* @var $last_message CerberusMessage */ continue; } if (null == @($last_headers = $last_message->getHeaders())) { continue; } $reply_to = $default_from; $reply_personal = $default_personal; // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM)); if (!empty($group_from)) { $reply_to = $group_from; } @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL)); if (!empty($group_personal)) { $reply_personal = $group_personal; } } if (is_array($notify_emails)) { foreach ($notify_emails as $send_to) { try { if (null == $mailer) { $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); } // Create the message $rcpt_to = new Swift_RecipientList(); $a_rcpt_to = array(); $mail_from = new Swift_Address($reply_to, $reply_personal); $rcpt_to->addTo($send_to); $a_rcpt_to = new Swift_Address($send_to); $mail = $mail_service->createMessage(); $mail->setTo($a_rcpt_to); $mail->setFrom($mail_from); $mail->setReplyTo($reply_to); $mail->setSubject(sprintf("[assignment #%s]: %s", $ticket->mask, $ticket->subject)); if (false !== @($in_reply_to = $last_headers['in-reply-to'])) { $mail->headers->set('References', $in_reply_to); $mail->headers->set('In-Reply-To', $in_reply_to); } $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mail->headers->set('Precedence', 'List'); $mail->headers->set('Auto-Submitted', 'auto-generated'); $mail->attach(new Swift_Message_Part($last_message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE)); $mailer->send($mail, $rcpt_to, $mail_from); } catch (Exception $e) { // } } } } }