function emailITticket($id, $scenario, $admin = false, $debug = false) { global $_josh, $page; $ticket = db_grab('SELECT u.id, (SELECT COUNT(*) FROM users_to_modules a WHERE a.user_id = u.id AND a.module_id = 3) isUserAdmin, t.title, t.created_user, t.description, t.departmentID, ISNULL(u.nickname, u.firstname) first, u.lastname last, u.email, ' . db_updated('u') . ', t.created_date, t.priorityID, t.statusID, d.shortName department, t.type_id, y.description type, u2.email as ownerEmail, t.ownerID, ISNULL(u2.nickname, u2.firstname) as ownerName FROM helpdesk_tickets t LEFT JOIN helpdesk_tickets_types y ON t.type_id = y.id JOIN users u ON t.created_user = u.id JOIN departments d ON t.departmentID = d.departmentID LEFT JOIN users u2 ON t.ownerID = u2.id WHERE t.id = ' . $id); //yellow box if ($scenario == "followup") { $subject = "Followup On Your Helpdesk Ticket"; $message = drawMessage('There\'s been followup on your Helpdesk ticket - please see below. <b>Don\'t reply to this email!</b> Instead, please ' . draw_link('/helpdesk/ticket.php?id=' . $id, 'view your ticket') . ' in the intranet ticketing system.<br><br><b>Note:</b> if you add this sender to your "safe senders list," pictures will always download.'); } elseif ($scenario == "followupadmin") { $subject = "Admin Followup on Helpdesk Ticket"; $message = drawMessage(draw_link('/staff/view.php?id=' . user(), $_SESSION['full_name']) . ' just made an administrative followup on this Helpdesk ticket. Regular staff were not copied on this message.'); } elseif ($scenario == "closed") { $subject = "Your Ticket Has Been Closed"; $message = drawMessage('This is to let you know that your ticket has been closed. <b>Don\'t reply to this email!</b> You can still followup on this thread by ' . draw_link('/helpdesk/ticket.php?id=' . $id, 'viewing your ticket') . ' in the intranet ticketing system.<br><br><b>Note:</b> if you add this sender to your "safe senders list," pictures will always download.'); } elseif ($scenario == "assign") { $subject = "Your Ticket Has Been Assigned"; $message = drawMessage(draw_link('/staff/view.php?id=' . user(), $_SESSION["full_name"]) . ' has assigned this ticket to ' . draw_link('/staff/view.php?id=' . $ticket['ownerID'], $ticket["ownerName"]) . '<b>Don\'t reply to this email!</b> Instead, please ' . draw_link('/helpdesk/ticket.php?id=' . $id, 'view your ticket') . ' in the intranet ticketing system.<br><br><b>Note:</b> if you add this sender to your "safe senders list," pictures will always download.'); } elseif ($scenario == "new") { $subject = "New " . $ticket["department"] . " Ticket Posted"; $message = drawMessage('This is to let you know that a new ticket has just been posted to the Helpdesk. You can ' . draw_link('/helpdesk/ticket.php?id=' . $id, 'view the ticket') . ' in the intranet ticketing system.'); } elseif ($scenario == "critical") { $subject = "Critical " . $ticket["department"] . " Ticket Still Open"; $message = drawMessage('A ticket flagged "Critical" is open on the Helpdesk. You can ' . draw_link('/helpdesk/ticket.php?id=' . $id, 'view the ticket') . ' in the intranet ticketing system.'); } //$message .= drawtableStart() . drawHeaderRow(false, 2); //recipients arrays $users = array(); $admins = array(); if ($ticket["isUserAdmin"]) { $admins[] = $ticket["email"]; } else { $users[] = $ticket["email"]; } if ($page['is_admin']) { $admins[] = $_SESSION["email"]; } else { $users[] = $_SESSION["email"]; } //add owner if ticket is assigned if ($ticket["ownerEmail"]) { $admins[] = $ticket["ownerEmail"]; } //owner logically has to be admin $d_user = new display($page['breadcrumbs'] . $ticket['title'], false, false, 'thread'); $d_admin = new display($page['breadcrumbs'] . $ticket['title'], false, false, 'thread'); $d_user->row(drawName($ticket['created_user'], $ticket['first'] . ' ' . $ticket['last'], $ticket['created_date'], true, BR, $ticket['updated']), draw_h1($ticket['title']) . $ticket['description']); $d_admin->row(drawName($ticket['created_user'], $ticket['first'] . ' ' . $ticket['last'], $ticket['created_date'], true, BR, $ticket['updated']), draw_h1($ticket['title']) . $ticket['description']); //get followups $followups = db_query('SELECT u.id, f.message, (SELECT COUNT(*) FROM users_to_modules u2m WHERE u2m.user_id = u.id AND u2m.module_id = 3 AND u2m.is_admin = 1) isUserAdmin, ISNULL(u.nickname, u.firstname) firstname, u.lastname, u.email, f.created_date, f.is_admin, f.created_user, ' . db_updated('u') . ' FROM helpdesk_tickets_followups f INNER JOIN users u ON f.created_user = u.id WHERE f.ticketID = ' . $id . ' ORDER BY f.created_date'); while ($f = db_fetch($followups)) { $d_admin->row(drawName($f['created_user'], $f['firstname'] . ' ' . $f['lastname'], $f['created_date'], true, BR, $f['updated']), $f['message']); if (!$f['is_admin']) { $d_user->row(drawName($f['created_user'], $f['firstname'] . ' ' . $f['lastname'], $f['created_date'], true, BR, $f['updated']), $f['message']); } if ($f['isUserAdmin']) { $admins[] = $f['email']; } else { $users[] = $f['email']; } } $admins = array_remove($_SESSION['email'], array_unique($admins)); $users = array_remove($_SESSION['email'], array_unique($users)); if ($debug) { die(drawEmail($message . $d_admin->draw())); } //special codes for email //todo: put this in db, possibly by adding something to the users table or something if ($scenario == "new" && $ticket["departmentID"] == 3) { $admins = array('*****@*****.**', '*****@*****.**', '*****@*****.**'); } if ($scenario == "new" && $ticket["departmentID"] == 13) { $admins = array('*****@*****.**', '*****@*****.**'); } if ($scenario == "new" && $ticket["departmentID"] == 2) { $admins = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); } if ($scenario == "critical" && $ticket["departmentID"] == 8) { $admins = array('*****@*****.**'); } if (count($admins)) { //$admins = join(", ", $admins); email($admins, drawEmail($message . $d_admin->draw()), $subject); error_debug('admin message emailed to ' . implode(', ', $admins) . ' admins', __FILE__, __LINE__); } if (count($users) && $scenario != "followupadmin" && !$admin) { //$users = join(", ", $users); email($users, drawEmail($message . $d_user->draw()), $subject); error_debug('user message emailed to ' . implode(', ', $users) . ' users', __FILE__, __LINE__); } }
<?php include 'include.php'; if ($posting) { error_debug('handling bb post', __FILE__, __LINE__); format_post_bits('is_admin'); langTranslatePost('title,description'); $id = db_save('bb_topics'); db_query('UPDATE bb_topics SET thread_date = GETDATE(), replies = (SELECT COUNT(*) FROM bb_followups WHERE topic_id = ' . $id . ') WHERE id = ' . $id); if (getOption('channels')) { db_checkboxes('channels', 'bb_topics_to_channels', 'topic_id', 'channel_id', $id); } //notification if ($_POST['is_admin'] == '1') { //get addresses of everyone & send with message emailUser(db_array('SELECT email FROM users WHERE is_active = 1'), $_POST['title'], drawEmail(bbDrawTopic($id, true))); } elseif (getOption('bb_notifypost') && getOption('channels') && getOption('languages')) { //get addresses of everyone with indicated interests and send $channels = array_post_checkboxes('channels'); $languages = db_table('SELECT id, code FROM languages'); foreach ($languages as $l) { $addresses = db_array('SELECT DISTINCT u.email FROM users u JOIN users_to_channels_prefs u2cp ON u.id = u2cp.user_id WHERE u.is_active = 1 AND u.language_id = ' . $l['id'] . ' AND u2cp.channel_id IN (' . implode(',', $channels) . ')'); $topic = db_grab('SELECT ISNULL(u.nickname, u.firstname) firstname, u.lastname, t.title' . langExt($l['code']) . ' title, t.description' . langExt($l['code']) . ' description, y.title' . langExt($l['code']) . ' type, t.created_date FROM bb_topics t LEFT JOIN bb_topics_types y ON t.type_id = y.id