ticketactions.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:20k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: ticketactions.php,v $
- // | $Date: 2004/02/10 01:34:30 $
- // | $Revision: 1.72 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Ticket actions handler.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- // start file
- require("./../global.php");
- // globalise variables
- $global = array (
- array('id') // ticketid
- );
- rg($global);
- /***********************************************************
- MASS TICKET PROCESSING
- ************************************************************/
- ############################### PROCESS TICKETS ###############################
- $now_ = mktime();
- if ($_REQUEST['do'] == "process") {
- new_db_class('2');
- /***********************************************************
- GET SOME DATA
- ************************************************************/
- $db->query("SELECT id, name FROM ticket_cat");
- while ($result = $db->row_array()) {
- $cats[] = $result[id];
- $catsname[$result[id]] = $result[name];
- }
- $db->query("SELECT id, name FROM ticket_pri");
- while ($result = $db->row_array()) {
- $pris[] = $result[id];
- $prisname[$result[id]] = $result[name];
- }
- $db->query("SELECT id, username FROM tech");
- while ($result = $db->row_array()) {
- $techs[] = $result[id];
- $techsname[$result[id]] = $result[username];
- }
- /***********************************************************
- PROCESS TICKETS
- ************************************************************/
- // build up list of ticket ids
- foreach ($_REQUEST AS $key => $var) {
- $tmp = strpos($key, 'OPT');
- if (($tmp !== false) AND ($var != 'Select one')) {
- $ticketid = substr($key, 3); // get ticketid
- $tickets[] = $ticketid;
- $toprocess[$ticketid] = array(
- 'type' => $var,
- 'value' => $_REQUEST['SO' . $ticketid]
- );
- }
- }
- if (!is_array($tickets)) {
- form_jump('ticketsearch.php', 'You did not make any changes to tickets', array('searchtype' => $_REQUEST['searchtype'], 'variables' => $_REQUEST['variables']));
- }
- // get ticket data
- $tickets = $db->query_return_array("SELECT ticket.*, user.email AS email FROM ticket LEFT JOIN user ON user.id = ticket.userid WHERE ticket.id IN " . array2sql($tickets) . "");
- if ($db->num_rows()) {
- foreach($tickets AS $ticket) {
-
- if ($toprocess[$ticket[id]]['type'] == 'category') { // category
-
- if (p_ticket('edit') AND in_array($toprocess[$ticket[id]]['value'], $cats)) {
-
- $tlog = $db->query_return("SELECT category FROM ticket WHERE id = '$ticket[id]'");
- $db->query("UPDATE ticket SET category = '" . $toprocess[$ticket[id]]['value'] . "' WHERE id = '$ticket[id]'");
- if ($db->affected_rows()) {
- $message .= "Ticket $ticket[id] category changed to " . $catsname[$toprocess[$ticket[id]]['value']] . '\n';
- ticketlog($id, 'category', $tlog[category], $toprocess[$ticket[id]]['value']);
- } else {
- $message .= "Ticket $ticket[id] category already " . $catsname[$toprocess[$ticket[id]]['value']] . '\n';
- }
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'priority') { // priority
-
- if (p_ticket('edit') AND in_array($toprocess[$ticket[id]]['value'], $pris)) {
- $tlog = $db->query_return("SELECT priority FROM ticket WHERE id = '$ticket[id]'");
- $db->query("UPDATE ticket SET priority = '" . $toprocess[$ticket[id]]['value'] . "' WHERE id = '$ticket[id]'");
- if ($db->affected_rows()) {
- $message .= "Ticket $ticket[id] priority changed to " . $prisname[$toprocess[$ticket[id]]['value']] . '\n';
- ticketlog($id, 'priority', $tlog[priority], $toprocess[$ticket[id]]['value']);
- } else {
- $message .= "Ticket $ticket[id] priority already " . $prisname[$toprocess[$ticket[id]]['value']] . '\n';
- }
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'tech') { // tech
- if (p_ticket('edit') AND in_array($toprocess[$ticket[id]]['value'], $techs)) {
- $tlog = $db->query_return("SELECT tech FROM ticket WHERE id = '$ticket[id]'");
- $db->query("UPDATE ticket SET tech = '" . $toprocess[$ticket[id]]['value'] . "' WHERE id = '$ticket[id]'");
- if ($db->affected_rows()) {
- $message .= "Ticket $ticket[id] assigned to " . $techsname[$toprocess[$ticket[id]]['value']] . '\n';
- ticketlog($id, 'tech', $tlog[tech], $toprocess[$ticket[id]]['value']);
- notify_technicians('assigned', $ticket, $user, NULL, NULL);
- } else {
- $message .= "Ticket $ticket[id] is already assigned to " . $techsname[$toprocess[$ticket[id]]['value']]. '\n';
- }
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'open') { // open
- if (p_ticket('open')) {
- $open_tickets[] = $ticket[id];
- $message .= "Ticket $ticket[id] reopened\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'close') { // close
- if (p_ticket('close')) {
- $close_tickets[] = $ticket[id];
- $message .= "Ticket $ticket[id] closed\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'awaiting_user') { // awaiting_user
-
- if (p_ticket('edit')) {
- $awaiting_user[] = $ticket[id];
- $message .= "Ticket $ticket[id] set as awaiting user response\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'awaiting_tech') { // awaiting_tech
-
- if (p_ticket('edit')) {
- $awaiting_tech[] = $ticket[id];
- $message .= "Ticket $ticket[id] set as awaiting tech response\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'nospam') { // awaiting_tech
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET nodisplay = 0 WHERE id = '$ticket[id]'");
- $message .= "Ticket $ticket[id]'s spam flag removed\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'spam') { // awaiting_tech
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET nodisplay = 1 WHERE id = '$ticket[id]'");
- $message .= "Ticket $ticket[id]'s spam flag set\n";
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'delete') { // delete (permission check is done by ticket_delete())
- $delete_tickets[] = $ticket[id];
- if ($toprocess[$ticket[id]]['value'] == '2') { // Ban e-mail as well
- ban_email($_REQUEST['email']);
- }
- } elseif ($toprocess[$ticket[id]]['type'] == 'nuke') { // Delete ticket, delete user, and ban e-mail
- if (p_ticket('delete') AND ($user['p_delete_users'] OR $user['admin'])) {
- $nukes[] = array('userid' => $ticket[userid], 'email' => $ticket[email]);
- $message .= "$ticket[email] deleted/banned; tickets purged\n";
- }
-
- } elseif ($toprocess[$ticket[id]]['type'] == 'quickreply') { // awaiting_tech
- if (p_ticket('edit')) {
- if ($reply = $db->query_return("SELECT quickreply.*, quickreply_cat.global FROM quickreply LEFT JOIN quickreply_cat ON quickreply.category = quickreply_cat.id WHERE quickreply.id = '" . $toprocess[$ticket[id]]['value'] . "' AND (quickreply_cat.global OR quickreply.techid = '$user[id]')")) {
- $reply_body = $reply['response'] . iff($user['signature'], "nn--n$user[signature]");
-
- $db->query("INSERT INTO ticket_message SET
- ticketid = '$ticket[id]',
- message = '" . mysql_escape_string($reply_body) . "',
- date = '$now_',
- techid = '$user[id]'
- ");
- $db->query("UPDATE ticket SET
- date_lastreply_tech = '$now_',
- awaiting_tech = 0, date_awaiting_toggled = '" . mktime() . "'
- WHERE id = '$ticket[id]'");
- ticketlog($ticket[id], 'tech_replied');
- $user_data = $db->query_return("SELECT * FROM user WHERE id = '$ticket[userid]'");
- notify_user('reply_user', $ticket, $user_data, $reply_body);
-
- $replied = $ticket[id];
- $message .= "Replied to $ticket[id]\n";
- }
- }
- }
- }
- }
- /***********************************************************
- UPDATE TICKETS
- ************************************************************/
- // open / close / awaiting tech / awaiting user
- if (is_array($open_tickets)) {
- $db->query("UPDATE ticket SET is_open = '1' WHERE id IN " . array2sql($open_tickets) . "");
- foreach ($open_tickets AS $key => $val) {
- ticketlog($val, 'reopen');
- }
- }
- if (is_array($close_tickets)){
- $db->query("UPDATE ticket SET is_open = '0', date_closed = '" . mktime() . "' WHERE id IN " . array2sql($close_tickets) . "");
- foreach ($close_tickets AS $key => $val) {
- ticketlog($val, 'close');
- }
- }
- if (is_array($awaiting_tech)) {
- $db->query("UPDATE ticket SET awaiting_tech = '1', date_awaiting_toggled = '" . mktime() . "' WHERE id IN " . array2sql($awaiting_tech) . "");
- foreach ($awaiting_tech AS $key => $val) {
- ticketlog($val, 'awaiting_tech');
- }
- }
- if (is_array($awaiting_user)) {
- $db->query("UPDATE ticket SET awaiting_tech = '0', date_awaiting_toggled = '" . mktime() . "' WHERE id IN " . array2sql($awaiting_user) . "");
- foreach ($awaiting_user AS $key => $val) {
- ticketlog($val, 'awaiting_user');
- }
- }
-
- if (is_array($delete_tickets)) {
- $res = ticket_delete($delete_tickets);
- if (count($res[0])) {
- foreach ($res[0] AS $val) {
- $message .= "No permission to delete ticket #$val.\n";
- }
- }
- if (count($res[1])) {
- foreach ($res[1] AS $val) {
- $message .= "Ticket #$val deleted.\n";
- }
- } else {
- $message .= "No tickets deleted.\n";
- }
- }
- if (is_array($nukes)) {
- foreach ($nukes AS $key => $val) {
- ban_email($val['email']);
- $del_users[] = $val['userid'];
- }
- user_delete($del_users);
- }
- /***********************************************************
- FINISH UP & REDIRECT
- ************************************************************/
- form_jump('ticketsearch.php', $message, array('searchtype' => $_REQUEST['searchtype'], 'variables' => $_REQUEST['variables']));
- }
- /***********************************************************
- INDIVIDUAL TICKET PROCESSING
- ************************************************************/
- $ticket = $db->query_return("SELECT * FROM ticket WHERE id = '$id'");
- ############################### BAN E-MAIL ################################
- if ($_REQUEST['do'] == 'nuke') {
- if ($user['p_delete_users']) {
- $userdata = $db->query_return("SELECT * FROM user WHERE id = '$ticket[userid]'");
- user_delete($ticket['userid']);
- ban_email($userdata['email']);
- }
- jump("../home/main.php", "The user has been banned, deleted, and the user's tickets have been deleted.");
- }
- if ($_REQUEST['do'] == 'banmail' AND $_REQUEST['email']) {
- if (!$user['p_edit_users']) {
- mistake("You do not have permission to ban users.");
- exit;
- }
- ban_email($_REQUEST['email']);
- jump("ticketview.php?id=$id", "The e-mail address has been added to the banned list.");
- }
-
- ############################### STORE TICKET ###############################
- if ($_REQUEST['do'] == "store" AND p_ticket('view')) {
- $db->query("DELETE FROM tech_ticket_save WHERE ticketid = $id AND techid = '$user[id]'");
- $db->query("INSERT INTO tech_ticket_save (ticketid, techid) VALUES ('$id', '$user[id]')");
- jump("ticketview.php?id=$id", "Ticket has been saved in your saved list.");
- }
- ############################### UN-STORE TICKET ###############################
- if ($_REQUEST['do'] == "unstore" AND p_ticket('view')) {
- $db->query("DELETE FROM tech_ticket_save WHERE ticketid = '$id' AND techid = '$user[id]'");
- jump("ticketview.php?id=$id", "Ticket has been removed from your saved list.");
- }
- ############################### FLAG TICKET AS SPAM ###############################
- if ($_REQUEST['do'] == "spam" AND p_ticket('edit')) {
- $db->query("UPDATE ticket set nodisplay = 1 WHERE id = '$id'");
- ticketlog($id, 'spam');
- jump("ticketview.php?id=$id", "Ticket has been marked as spam.");
- }
- ############################### FLAG TICKET AS NOT SPAM ###############################
- if ($_REQUEST['do'] == "nospam" AND p_ticket('edit')) {
- $db->query("UPDATE ticket set nodisplay = 0 WHERE id = '$id'");
- ticketlog($id, 'nonspam');
- jump("ticketview.php?id=$id", "Ticket has been marked as non-spam.");
- }
- ############################### LOCK TICKET ###############################
- if ($_REQUEST['do'] == "lock" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("
- UPDATE ticket SET is_locked = 1,
- date_locked = '" . mktime() . "'
- WHERE id = '$id'
- ");
- ticketlog($id, 'lock');
- jump("ticketview.php?id=$id", "Ticket has been locked");
- } else {
- nopermission('to lock this ticket');
- }
- }
- ############################### UNLOCK TICKET ###############################
- if ($_REQUEST['do'] == "unlock" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET is_locked = 0, date_locked = 0 WHERE id = '$id'");
- ticketlog($id, 'unlock');
- jump("ticketview.php?id=$id", "Ticket has been unlocked");
- } else {
- nopermission('to lock this ticket');
- }
- }
- ############################### SET AS AWAITING TECH ###############################
- if ($_REQUEST['do'] == "awaiting_tech" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET awaiting_tech = 1, date_awaiting_toggled = '" . mktime() . "' WHERE id = '$id'");
- ticketlog($id, 'awaiting_tech');
- jump("ticketview.php?id=$id", "Ticket has been set as awaiting a technician's response");
- } else {
- nopermission('to edit this ticket');
- }
- }
- ############################### SET AS AWAITING USER ###############################
- if ($_REQUEST['do'] == "awaiting_user" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET awaiting_tech = 0, date_awaiting_toggled = '" . mktime() . "' WHERE id = '$id'");
- ticketlog($id, 'awaiting_user');
- jump("ticketview.php?id=$id", "Ticket has been set as awaiting a user's response");
- } else {
- nopermission('to edit this ticket');
- }
- }
- ############################### REMOVE OWNERSHIP ###############################
- if ($_REQUEST['do'] == "remove_ownership" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET tech = 0 WHERE id = '$id'");
- ticketlog($id, 'tech', $uuser[id], 0);
- jump("ticketview.php?id=$id", "Your ownership to this ticket has been removed");
- exit;
- } else {
- nopermission('to edit this ticket');
- }
- }
- ############################### TAKE OWNERSHIP ###############################
- if ($_REQUEST['do'] == "take_ownership" AND p_ticket('edit')) {
- if (p_ticket('edit')) {
- $db->query("UPDATE ticket SET tech = $user[id] WHERE id = '$id'");
- ticketlog($id, 'tech', $ticket[tech], $user[id]);
- jump("ticketview.php?id=$id", "You have been assigned ownership of this ticket");
- exit;
- } else {
- nopermission('to edit this ticket');
- }
- }
- ############################### CLOSE TICKET ###############################
- if ($_REQUEST['do'] == "close") {
- if (p_ticket('close')) {
- $db->query("UPDATE ticket SET is_open = 0, date_closed = '$now_' WHERE id = '$id'");
- ticketlog($id, 'close');
- if ($_REQUEST[email] == '1') {
- $ticket = $db->query_return("SELECT * FROM ticket WHERE id = '$id'");
- $user_details = $db->query_return("SELECT * FROM user WHERE id = '$ticket[userid]'");
- $user_details = update_user_details($user_details);
- eval(makeemaileval('message', 'BODY_question_closed', $subject, $ticket));
- dp_mail($user_details['email'], $subject, trim($message));
- ticketlog($ticket['id'], 'email_sent_to_user', NULL, NULL, "To: $user_details[email], Subject: $subject");
- }
- jump("ticketview.php?id=$id", "The ticket has been closed");
- }
- }
- ############################### OPEN TICKET ###############################
- if ($_REQUEST['do'] == "open") {
- if (p_ticket('close')) {
- ticketlog($id, 'reopen');
- $db->query("UPDATE ticket SET is_open = 1 WHERE id = '$id'");
- if ($_REQUEST[email] == '1') {
- $ticket = $db->query_return("SELECT * FROM ticket WHERE id = '$id'");
- $user_details = $db->query_return("SELECT * FROM user WHERE id = '$ticket[userid]'");
- unset($user_details['password']);
- $user_details = update_user_details($user_details);
- eval(makeemaileval('message', 'BODY_question_reopened', $subject, $ticket));
- dp_mail($user_details['email'], $subject, trim($message));
- ticketlog($ticket['id'], 'email_sent_to_user', NULL, NULL, "To: $user_details[email], Subject: $subject");
- }
- jump("ticketview.php?id=$id", "The ticket has been reopened");
- } else {
- jump("ticketview.php?id=$id", "You don't have permission to re-open this ticket.");
- }
- }
- ############################### DELETE ###############################
- if ($_REQUEST['do'] == "delete") {
- if (p_ticket('delete')) {
- ticket_delete(array($id));
- } else {
- nopermission('to delete this ticket');
- }
- jump("../home/main.php", 'The ticket has been deleted.');
- }
- ############################### MERGE TICKET ###############################
- if ($_REQUEST['do'] == "merge" ) {
- $fromticket = mysql_escape_string($_REQUEST['fromticket']);
- $toticket = mysql_escape_string($_REQUEST['toticket']);
- if ($fromticket AND $toticket) {
- $ticket_del = $db->query_return("SELECT * FROM ticket WHERE id = '$fromticket'");
- $ticket_stay = $db->query_return("SELECT * FROM ticket WHERE id = '$toticket'");
- } else {
- jump("ticketview.php?id=$ticket_stay[id]", 'Two tickets must be specified
- to merge.');
- }
- // need permission to edit both of these tickets.
- if (p_ticket('edit', $ticket_del) AND
- p_ticket('delete', $ticket_del) AND
- p_ticket('edit', $ticket_stay)) {
- // check that the user is the same, or error and jump back
- if ($ticket_del[userid] != $ticket_stay[userid]) {
- jump("ticketview.php?id=$ticket_stay[id]", 'The tickets belong to different
- users and cannot be merged.');
- }
- // update ticketids for various tables
- $db->query("UPDATE ticket_message SET ticketid = '$ticket_stay[id]'
- WHERE ticketid = '$ticket_del[id]'");
- $db->query("UPDATE ticket_attachments SET ticketid = '$ticket_stay[id]'
- WHERE ticketid = '$ticket_del[id]'");
- $db->query("UPDATE ticket_notes SET ticketid = '$ticket_stay[id]'
- WHERE ticketid = '$ticket_del[id]'");
- $db->query("UPDATE user_bill SET ticketid = '$ticket_stay[id]'
- WHERE ticketid = '$ticket_del[id]'");
- $db->query("UPDATE tech_ticket_watch SET ticketid = '$ticket_stay[id]' WHERE ticketid = '$ticket_del[id]'");
- $db->query("SELECT ticketid FROM tech_ticket_save WHERE ticketid = '$ticket_stay[id]'");
- if (!($db->num_rows())) { // Only move a saved ticket to the saved list if the receiving ticket isn't already saved
- $db->query("UPDATE tech_ticket_save SET ticketid = '$ticket_stay[id]' WHERE ticketid = '$ticket_del[id]'");
- }
- $db->query("INSERT INTO ticket_merge SET old_id = '$ticket_del[id]', old_ref = '$ticket_del[ref]', new_id = '$ticket_stay[id]', new_ref = '$ticket_stay[ref]'");
- // delete merged ticket
- $db->query("DELETE FROM ticket WHERE id = '$fromticket'");
- ticketlog($toticket, 'merge', $fromticket, $toticket);
- jump("ticketview.php?id=$ticket_stay[id]", 'Ticket Merged');
- } else {
- jump("ticketview.php?id=$ticket_stay[id]", 'You don't have permission to edit
- both tickets (or permission to delete the ticket to be merged');
- }
- }
- ######################### USER AUTORESPONDS TOGGLE #####################################
- if ($_REQUEST['do'] == 'autoresp') {
- if ($user['p_edit_users']) {
- if ($_REQUEST['userid']) {
- $db->query('UPDATE user SET autoresponds = ' . iff($_REQUEST['val'], 1, 0) . ' WHERE id = '' . $_REQUEST['userid'] . "'");
- jump("ticketview.php?id=$id", 'User updated.');
- } else {
- mistake('No user ID specified.');
- }
- } else {
- mistake('You do not have permission to edit users.');
- }
- }
- ?>