// do the ticket processing. // assign a new status? if ((int) $_SESSION['ticket_bulk_status_id'] > 0) { update_insert('ticket_id', $ticket_id, 'ticket', array('status_id' => $_SESSION['ticket_bulk_status_id'])); } if ($_SESSION['ticket_bulk_send_message'] && $_SESSION['ticket_bulk_send_message_content']) { // send our reply! tricky! // who from? just like the admin is writing it I guess. // hack: so that the tickets do not loose their positions in the queue we want to keep the same 'last message' timestamp on the thread. $ticket_data = module_ticket::get_ticket($ticket_id); $from_user_id = $ticket_data['assigned_user_id'] ? $ticket_data['assigned_user_id'] : 1; // the <br> is a hack so that our script knows this is html. $message = $_SESSION['ticket_bulk_send_message_content'] . '<br><br>'; // replace our values. $to_user = module_user::get_user($ticket_data['user_id'], false); $replace = array('name' => $to_user['name'], 'ticket_id' => module_ticket::ticket_number($ticket_id), 'ticket_url' => module_ticket::link_public($ticket_id), 'ticket_url_cancel' => module_ticket::link_public_status($ticket_id, 7), 'ticket_url_resolved' => module_ticket::link_public_status($ticket_id, 6), 'ticket_url_inprogress' => module_ticket::link_public_status($ticket_id, 5)); foreach ($replace as $key => $val) { $message = str_replace('{' . strtoupper($key) . '}', $val, $message); $message = str_replace('{' . $key . '}', $val, $message); } $ticket_message_id = module_ticket::send_reply($ticket_id, $message, $from_user_id, $ticket_data['user_id'], 'admin'); if ($ticket_message_id) { // success! // do the timestamp. update_insert('ticket_message_id', $ticket_message_id, 'ticket_message', array('message_time' => $ticket_data['last_message_timestamp'] + 1)); update_insert('ticket_id', $ticket_id, 'ticket', array('last_message_timestamp' => $ticket_data['last_message_timestamp'] + 1)); } } ?> <script type="text/javascript"> window.parent.document.getElementById('ticket_<?php
public static function send_admin_alert($ticket_id, $message = '', $allow_to_cc_bcc = false) { module_cache::clear('ticket'); $ticket_data = self::get_ticket($ticket_id); $ticket_account_data = self::get_ticket_account($ticket_data['ticket_account_id']); $ticket_number = self::ticket_number($ticket_id); if ($ticket_data['last_ticket_message_id']) { $last_message = self::get_ticket_message($ticket_data['last_ticket_message_id']); if (!$message) { $htmlmessage = trim($last_message['htmlcontent']); if ($htmlmessage) { $message = $htmlmessage; } else { $message = nl2br(htmlspecialchars(trim($last_message['content']))); } } } else { $last_message = false; } $to = module_config::c('ticket_admin_email_alert', _ERROR_EMAIL); $to_user_id = 0; $cc = false; if (module_config::c('ticket_auto_notify_staff', 0) && $ticket_data['assigned_user_id']) { $staff = module_user::get_user($ticket_data['assigned_user_id'], false); if ($staff && $staff['user_id'] == $ticket_data['assigned_user_id'] && $staff['email']) { $cc = $to; $to = $staff['email']; $to_user_id = $staff['user_id']; } } if (strlen($to) < 4) { return; } // do we only send this on first emails or not ? $first_only = module_config::c('ticket_admin_alert_first_only', 0); if ($first_only && $ticket_data['message_count'] > 1) { return; } $s = self::get_statuses(); $reply_line = module_config::s('ticket_reply_line', '----- (Please reply above this line) -----'); // autoreplies go back to the user - not our admin system: $from_user_a = module_user::get_user($ticket_data['user_id'], false); $reply_to_address = $from_user_a['email']; $reply_to_name = $from_user_a['name']; $template = module_template::get_template_by_key('ticket_admin_email'); $template->assign_values(self::get_replace_fields($ticket_id, $ticket_data)); $template->assign_values(array('ticket_number' => self::ticket_number($ticket_id), 'ticket_status' => $s[$ticket_data['status_id']], 'message' => $message, 'subject' => $ticket_data['subject'], 'position_current' => $ticket_data['position'], 'position_all' => $ticket_data['total_pending'], 'reply_line' => $reply_line, 'days' => module_config::c('ticket_turn_around_days', 5), 'url' => self::link_public($ticket_id), 'url_admin' => self::link_open($ticket_id), 'message_count' => $ticket_data['message_count'], 'ticket_url_cancel' => module_ticket::link_public_status($ticket_id, 7), 'ticket_url_resolved' => module_ticket::link_public_status($ticket_id, _TICKET_STATUS_RESOLVED_ID), 'ticket_url_inprogress' => module_ticket::link_public_status($ticket_id, 5), 'faq_product_id' => $ticket_data['faq_product_id'])); $content = $template->replace_content(); $email = module_email::new_email(); $email->replace_values = $template->values; if ($to_user_id) { $email->set_to('user', $to_user_id); } else { $email->set_to_manual($to); } if ($cc) { $email->set_cc_manual($cc); } if ($ticket_account_data && $ticket_account_data['email']) { $email->set_from_manual($ticket_account_data['email'], $ticket_account_data['name']); $email->set_bounce_address($ticket_account_data['email']); } else { $email->set_from_manual($to, module_config::s('admin_system_name')); $email->set_bounce_address($to); } //$email->set_from('user',$from_user_id); //$email->set_from('foo','foo',$to,'Admin'); $headers = $last_message ? @unserialize($last_message['cache']) : false; if ($allow_to_cc_bcc && $headers && is_array($headers)) { // we're right to do our cc/bcc hack if ($headers && isset($headers['to_emails'])) { foreach ($headers['to_emails'] as $to_emails) { if (isset($to_emails['address']) && strlen($to_emails['address'])) { $email->set_to_manual($to_emails['address'], isset($to_emails['name']) ? $to_emails['name'] : ''); } } } if ($headers && isset($headers['cc_emails'])) { foreach ($headers['cc_emails'] as $cc_emails) { if (isset($cc_emails['address']) && strlen($cc_emails['address'])) { $email->set_cc_manual($cc_emails['address'], isset($cc_emails['name']) ? $cc_emails['name'] : ''); } } } if ($headers && isset($headers['bcc_emails'])) { foreach ($headers['bcc_emails'] as $bcc_emails) { if (isset($bcc_emails['address']) && strlen($bcc_emails['address'])) { $email->set_bcc_manual($bcc_emails['address'], isset($bcc_emails['name']) ? $bcc_emails['name'] : ''); } } } } // do we reply to the user who created this, or to our ticketing system? if (module_config::c('ticket_admin_alert_postback', 1) && $ticket_account_data && $ticket_account_data['email']) { $email->set_reply_to($ticket_account_data['email'], $ticket_account_data['name']); } else { $email->set_reply_to($reply_to_address, $reply_to_name); } if ($last_message && $last_message['private_message']) { $email->set_subject(sprintf(module_config::c('ticket_private_message_email_subject', 'Private Support Ticket Message: [TICKET:%s]'), $ticket_number)); } else { $email->set_subject(sprintf(module_config::c('ticket_admin_alert_subject', 'Support Ticket Updated: [TICKET:%s]'), $ticket_number)); } $email->set_html($content); // check attachments: $attachments = self::get_ticket_message_attachments($ticket_data['last_ticket_message_id']); foreach ($attachments as $attachment) { $file_path = 'includes/plugin_ticket/attachments/' . $attachment['ticket_message_attachment_id']; $file_name = $attachment['file_name']; $email->AddAttachment($file_path, $file_name); } $email->send(); }