2014-06-14 21:50:59 -04:00
< ? php
2016-11-16 21:16:25 -05:00
/**
*
* This file is part of HESK - PHP Help Desk Software .
*
* ( c ) Copyright Klemen Stirn . All rights reserved .
2016-11-18 12:57:17 -05:00
* https :// www . hesk . com
2016-11-16 21:16:25 -05:00
*
* For the full copyright and license agreement information visit
2016-11-18 12:57:17 -05:00
* https :// www . hesk . com / eula . php
2016-11-16 21:16:25 -05:00
*
*/
2015-09-12 00:46:46 -04:00
define ( 'IN_SCRIPT' , 1 );
define ( 'HESK_PATH' , '../' );
2014-06-14 21:50:59 -04:00
/* Get all the required files and functions */
require ( HESK_PATH . 'hesk_settings.inc.php' );
require ( HESK_PATH . 'inc/common.inc.php' );
require ( HESK_PATH . 'inc/admin_functions.inc.php' );
hesk_load_database_functions ();
require ( HESK_PATH . 'inc/email_functions.inc.php' );
require ( HESK_PATH . 'inc/posting_functions.inc.php' );
2015-08-02 16:51:24 -04:00
require ( HESK_PATH . 'inc/htmLawed.php' );
2014-06-14 21:50:59 -04:00
// We only allow POST requests from the HESK form to this file
2015-09-12 00:46:46 -04:00
if ( $_SERVER [ 'REQUEST_METHOD' ] != 'POST' ) {
header ( 'Location: admin_main.php' );
exit ();
2014-06-14 21:50:59 -04:00
}
// Check for POST requests larger than what the server can handle
2015-09-12 00:46:46 -04:00
if ( empty ( $_POST ) && ! empty ( $_SERVER [ 'CONTENT_LENGTH' ])) {
hesk_error ( $hesklang [ 'maxpost' ]);
2014-06-14 21:50:59 -04:00
}
hesk_session_start ();
hesk_dbConnect ();
hesk_isLoggedIn ();
/* Check permissions for this feature */
2015-06-07 01:18:30 -04:00
if ( ! isset ( $_REQUEST [ 'isManager' ]) || ! $_REQUEST [ 'isManager' ]) {
hesk_checkPermission ( 'can_reply_tickets' );
}
2014-06-14 21:50:59 -04:00
/* A security check */
# hesk_token_check('POST');
/* Original ticket ID */
2015-09-12 00:46:46 -04:00
$replyto = intval ( hesk_POST ( 'orig_id' , 0 )) or die ( $hesklang [ 'int_error' ]);
2014-06-14 21:50:59 -04:00
/* Get details about the original ticket */
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`=' { $replyto } ' LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 1 ) {
hesk_error ( $hesklang [ 'ticket_not_found' ]);
2014-06-14 21:50:59 -04:00
}
$ticket = hesk_dbFetchAssoc ( $result );
$trackingID = $ticket [ 'trackid' ];
2016-10-03 20:44:42 -04:00
// Do we require owner before allowing to reply?
if ( $hesk_settings [ 'require_owner' ] && ! $ticket [ 'owner' ]) {
hesk_process_messages ( $hesklang [ 'atbr' ], 'admin_ticket.php?track=' . $ticket [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
}
2014-06-14 21:50:59 -04:00
$hesk_error_buffer = array ();
// Get the message
$message = hesk_input ( hesk_POST ( 'message' ));
2015-01-17 10:32:57 -05:00
// Submit as customer?
$submit_as_customer = isset ( $_POST [ 'submit_as_customer' ]) ? true : false ;
2015-09-02 22:04:32 -04:00
$modsForHesk_settings = mfh_getSettings ();
2015-09-12 00:46:46 -04:00
if ( strlen ( $message )) {
2015-01-17 10:32:57 -05:00
// Save message for later and ignore the rest?
2015-09-12 00:46:46 -04:00
if ( isset ( $_POST [ 'save_reply' ])) {
2015-01-17 10:32:57 -05:00
// Delete any existing drafts from this owner for this ticket
2016-10-03 20:44:42 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " reply_drafts` WHERE `owner`= " . intval ( $_SESSION [ 'id' ]) . " AND `ticket`= " . intval ( $ticket [ 'id' ]));
2015-01-17 10:32:57 -05:00
// Save the message draft
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " reply_drafts` (`owner`, `ticket`, `message`) VALUES ( " . intval ( $_SESSION [ 'id' ]) . " , " . intval ( $ticket [ 'id' ]) . " , ' " . hesk_dbEscape ( $message ) . " ') " );
2015-01-17 10:32:57 -05:00
/* Set reply submitted message */
$_SESSION [ 'HESK_SUCCESS' ] = TRUE ;
$_SESSION [ 'HESK_MESSAGE' ] = $hesklang [ 'reply_saved' ];
/* What to do after reply? */
2015-09-12 00:46:46 -04:00
if ( $_SESSION [ 'afterreply' ] == 1 ) {
2015-01-17 10:32:57 -05:00
header ( 'Location: admin_main.php' );
2015-09-12 00:46:46 -04:00
} elseif ( $_SESSION [ 'afterreply' ] == 2 ) {
2015-01-17 10:32:57 -05:00
/* Get the next open ticket that needs a reply */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `owner` IN ('0',' " . intval ( $_SESSION [ 'id' ]) . " ')
AND " . hesk_myCategories() . " AND `status` IN ( SELECT `ID` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses`
2015-01-25 00:57:58 -05:00
WHERE `IsNewTicketStatus` = 1 OR `IsCustomerReplyStatus` = 1 OR `IsStaffReopenedStatus` = 1 )
ORDER BY `owner` DESC , `priority` ASC LIMIT 1 " );
2015-01-17 10:32:57 -05:00
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) == 1 ) {
2015-01-17 10:32:57 -05:00
$row = hesk_dbFetchAssoc ( $res );
2015-09-12 00:46:46 -04:00
$_SESSION [ 'HESK_MESSAGE' ] .= '<br /><br />' . $hesklang [ 'rssn' ];
header ( 'Location: admin_ticket.php?track=' . $row [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
} else {
2015-01-17 10:32:57 -05:00
header ( 'Location: admin_main.php' );
}
2015-09-12 00:46:46 -04:00
} else {
header ( 'Location: admin_ticket.php?track=' . $ticket [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
2015-01-17 10:32:57 -05:00
}
exit ();
}
// Attach signature to the message?
2015-09-12 00:46:46 -04:00
if ( ! $submit_as_customer && ! empty ( $_POST [ 'signature' ])) {
2015-09-02 22:04:32 -04:00
if ( $modsForHesk_settings [ 'rich_text_for_tickets' ]) {
2015-10-18 22:09:05 -04:00
$signature = nl2br ( $_SESSION [ 'signature' ]);
$signature = hesk_htmlspecialchars ( $signature );
$message .= " <br><br> " . $signature . " <br> " ;
2015-07-09 22:13:16 -04:00
} else {
$message .= " \n \n " . addslashes ( $_SESSION [ 'signature' ]) . " \n " ;
}
2015-09-12 00:46:46 -04:00
}
2014-06-14 21:50:59 -04:00
2015-09-02 22:04:32 -04:00
if ( ! $modsForHesk_settings [ 'rich_text_for_tickets' ]) {
2015-07-09 22:13:16 -04:00
// Make links clickable
$message = hesk_makeURL ( $message );
2014-06-14 21:50:59 -04:00
2015-07-09 22:13:16 -04:00
// Turn newlines into <br /> tags
$message = nl2br ( $message );
}
2015-09-12 00:46:46 -04:00
} else {
2014-06-14 21:50:59 -04:00
$hesk_error_buffer [] = $hesklang [ 'enter_message' ];
}
/* Attachments */
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'attachments' ][ 'use' ]) {
2014-06-14 21:50:59 -04:00
require ( HESK_PATH . 'inc/attachments.inc.php' );
$attachments = array ();
2015-12-28 12:47:51 -05:00
$use_legacy_attachments = hesk_POST ( 'use-legacy-attachments' , 0 );
if ( $use_legacy_attachments ) {
for ( $i = 1 ; $i <= $hesk_settings [ 'attachments' ][ 'max_number' ]; $i ++ ) {
$att = hesk_uploadFile ( $i );
if ( $att !== false && ! empty ( $att )) {
$attachments [ $i ] = $att ;
}
}
} else {
// The user used the new drag-and-drop system.
$temp_attachment_ids = hesk_POST_array ( 'attachment-ids' );
foreach ( $temp_attachment_ids as $temp_attachment_id ) {
// Simply get the temp info and move it to the attachments table
$temp_attachment = mfh_getTemporaryAttachment ( $temp_attachment_id );
$attachments [] = $temp_attachment ;
mfh_deleteTemporaryAttachment ( $temp_attachment_id );
2014-06-14 21:50:59 -04:00
}
}
}
2015-09-12 00:46:46 -04:00
$myattachments = '' ;
2014-06-14 21:50:59 -04:00
/* Time spent working on ticket */
$time_worked = hesk_getTime ( hesk_POST ( 'time_worked' ));
/* Any errors? */
2015-09-12 00:46:46 -04:00
if ( count ( $hesk_error_buffer ) != 0 ) {
2014-06-14 21:50:59 -04:00
$_SESSION [ 'ticket_message' ] = hesk_POST ( 'message' );
$_SESSION [ 'time_worked' ] = $time_worked ;
2015-09-12 00:46:46 -04:00
// Remove any successfully uploaded attachments
if ( $hesk_settings [ 'attachments' ][ 'use' ]) {
hesk_removeAttachments ( $attachments );
}
2014-06-14 21:50:59 -04:00
$tmp = '' ;
2015-09-12 00:46:46 -04:00
foreach ( $hesk_error_buffer as $error ) {
2014-06-14 21:50:59 -04:00
$tmp .= " <li> $error </li> \n " ;
}
$hesk_error_buffer = $tmp ;
2015-09-12 00:46:46 -04:00
$hesk_error_buffer = $hesklang [ 'pcer' ] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>' ;
hesk_process_messages ( $hesk_error_buffer , 'admin_ticket.php?track=' . $ticket [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
2014-06-14 21:50:59 -04:00
}
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'attachments' ][ 'use' ] && ! empty ( $attachments )) {
foreach ( $attachments as $myatt ) {
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES (' " . hesk_dbEscape ( $trackingID ) . " ',' " . hesk_dbEscape ( $myatt [ 'saved_name' ]) . " ',' " . hesk_dbEscape ( $myatt [ 'real_name' ]) . " ',' " . intval ( $myatt [ 'size' ]) . " ') " );
$myattachments .= hesk_dbInsertID () . '#' . $myatt [ 'real_name' ] . '#' . $myatt [ 'saved_name' ] . ',' ;
2014-06-14 21:50:59 -04:00
}
}
2015-01-17 10:32:57 -05:00
// Add reply
2015-09-02 22:04:32 -04:00
$html = $modsForHesk_settings [ 'rich_text_for_tickets' ];
2015-09-12 00:46:46 -04:00
if ( $submit_as_customer ) {
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " replies` (`replyto`,`name`,`message`,`dt`,`attachments`,`html`) VALUES (' " . intval ( $replyto ) . " ',' " . hesk_dbEscape ( addslashes ( $ticket [ 'name' ])) . " ',' " . hesk_dbEscape ( $message . " <br /><br /><i> { $hesklang [ 'creb' ] } { $_SESSION [ 'name' ] } </i> " ) . " ',NOW(),' " . hesk_dbEscape ( $myattachments ) . " ', ' " . $html . " ') " );
} else {
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " replies` (`replyto`,`name`,`message`,`dt`,`attachments`,`staffid`,`html`) VALUES (' " . intval ( $replyto ) . " ',' " . hesk_dbEscape ( addslashes ( $_SESSION [ 'name' ])) . " ',' " . hesk_dbEscape ( $message ) . " ',NOW(),' " . hesk_dbEscape ( $myattachments ) . " ',' " . intval ( $_SESSION [ 'id' ]) . " ', ' " . $html . " ') " );
2015-01-17 10:32:57 -05:00
}
2014-06-14 21:50:59 -04:00
/* Track ticket status changes for history */
$revision = '' ;
/* Change the status of priority? */
2015-09-12 00:46:46 -04:00
if ( ! empty ( $_POST [ 'set_priority' ])) {
$priority = intval ( hesk_POST ( 'priority' ));
if ( $priority < 0 || $priority > 3 ) {
hesk_error ( $hesklang [ 'select_priority' ]);
2014-06-14 21:50:59 -04:00
}
2015-09-12 00:46:46 -04:00
$options = array (
2015-09-26 20:13:14 -04:00
0 => '<span class="critical">' . $hesklang [ 'critical' ] . '</span>' ,
1 => '<span class="important">' . $hesklang [ 'high' ] . '</span>' ,
2 => '<span class="medium">' . $hesklang [ 'medium' ] . '</span>' ,
2015-09-12 00:46:46 -04:00
3 => $hesklang [ 'low' ]
);
2014-06-14 21:50:59 -04:00
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist8' ], hesk_date (), $options [ $priority ], $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
2014-06-14 21:50:59 -04:00
2015-09-12 00:46:46 -04:00
$priority_sql = " ,`priority`=' $priority ', `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') " ;
} else {
2014-06-14 21:50:59 -04:00
$priority_sql = " " ;
}
/* Update the original ticket */
2015-09-12 00:46:46 -04:00
$defaultStatusReplyStatus = hesk_dbFetchAssoc ( hesk_dbQuery ( " SELECT `ID`, `IsClosed` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` WHERE `IsDefaultStaffReplyStatus` = 1 LIMIT 1 " ));
$staffClosedCheckboxStatus = hesk_dbFetchAssoc ( hesk_dbQuery ( " SELECT `ID`, `IsClosed` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` WHERE `IsStaffClosedOption` = 1 LIMIT 1 " ));
$lockedTicketStatus = hesk_dbFetchAssoc ( hesk_dbQuery ( " SELECT `ID` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` WHERE `LockedTicketStatus` = 1 LIMIT 1 " ));
2014-06-14 21:50:59 -04:00
2015-01-17 10:32:57 -05:00
// Get new ticket status
$sql_status = '' ;
2016-10-03 20:44:42 -04:00
$change_status = true ;
2015-01-17 10:32:57 -05:00
// -> If locked, keep it resolved
2015-09-12 00:46:46 -04:00
if ( $ticket [ 'locked' ]) {
$new_status = $lockedTicketStatus [ 'ID' ];
} elseif ( isset ( $_POST [ 'submit_as_status' ])) {
2015-01-17 10:32:57 -05:00
$new_status = $_POST [ 'submit_as_status' ];
2015-09-12 00:46:46 -04:00
if ( $ticket [ 'status' ] != $new_status ) {
2015-01-17 10:32:57 -05:00
// Does this status close the ticket?
2017-03-28 21:56:49 -04:00
$newStatusRs = hesk_dbQuery ( 'SELECT `IsClosed`, `Key` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `ID` = ' . intval ( $new_status ));
2015-01-17 10:32:57 -05:00
$newStatus = hesk_dbFetchAssoc ( $newStatusRs );
2016-10-03 20:44:42 -04:00
if ( $newStatus [ 'IsClosed' ] && hesk_checkPermission ( 'can_resolve' , 0 )) {
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist3' ], hesk_date (), $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
$sql_status = " , `closedat`=NOW(), `closedby`= " . intval ( $_SESSION [ 'id' ]) . " , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') " ;
2015-01-17 10:32:57 -05:00
// Lock the ticket if customers are not allowed to reopen tickets
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'custopen' ] != 1 ) {
2015-01-17 10:32:57 -05:00
$sql_status .= " , `locked`='1' " ;
}
2015-09-12 00:46:46 -04:00
} else {
2016-10-03 20:44:42 -04:00
// Ticket isn't being closed, just add the history to the sql query (or tried to close but doesn't have permission)
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist9' ], hesk_date (), $hesklang [ $newStatus [ 'Key' ]], $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
$sql_status = " , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') " ;
2015-01-17 10:32:57 -05:00
}
}
2015-09-12 00:46:46 -04:00
} // -> Submit as Customer reply
elseif ( $submit_as_customer ) {
2015-01-17 10:32:57 -05:00
//Get the status ID for customer replies
2015-09-12 00:46:46 -04:00
$customerReplyStatusRs = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsCustomerReplyStatus` = 1 LIMIT 1' );
2015-01-17 10:32:57 -05:00
$customerReplyStatus = hesk_dbFetchAssoc ( $customerReplyStatusRs );
$new_status = $customerReplyStatus [ 'ID' ];
2015-06-23 23:29:16 -04:00
2015-09-12 00:46:46 -04:00
if ( $ticket [ 'status' ] != $new_status ) {
$revision = sprintf ( $hesklang [ 'thist9' ], hesk_date (), $hesklang [ 'wait_reply' ], $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
$sql_status = " , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') " ;
}
} // -> Default: submit as "Replied by staff"
else {
2015-01-17 10:32:57 -05:00
//Get the status ID for staff replies
2015-09-12 00:46:46 -04:00
$staffReplyStatusRs = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsDefaultStaffReplyStatus` = 1 LIMIT 1' );
2015-01-17 10:32:57 -05:00
$staffReplyStatus = hesk_dbFetchAssoc ( $staffReplyStatusRs );
$new_status = $staffReplyStatus [ 'ID' ];
}
2015-09-12 00:46:46 -04:00
$sql = " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `status`=' { $new_status } ', " ;
$sql .= $submit_as_customer ? " `lastreplier`='0', `replierid`='0' " : " `lastreplier`='1', `replierid`=' " . intval ( $_SESSION [ 'id' ]) . " ' " ;
2014-06-14 21:50:59 -04:00
/* Update time_worked or force update lastchange */
2015-09-12 00:46:46 -04:00
if ( $time_worked == '00:00:00' ) {
$sql .= " , `lastchange` = NOW() " ;
} else {
$sql .= " ,`time_worked` = ADDTIME(`time_worked`,' " . hesk_dbEscape ( $time_worked ) . " ') " ;
2014-06-14 21:50:59 -04:00
}
2015-09-12 00:46:46 -04:00
if ( ! empty ( $_POST [ 'assign_self' ]) && ( hesk_checkPermission ( 'can_assign_self' , 0 ) || ( isset ( $_REQUEST [ 'isManager' ]) && $_REQUEST [ 'isManager' ]))) {
$revision = sprintf ( $hesklang [ 'thist2' ], hesk_date (), $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' , $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
$sql .= " , `owner`= " . intval ( $_SESSION [ 'id' ]) . " , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') " ;
2014-06-14 21:50:59 -04:00
}
$sql .= " $priority_sql " ;
2015-01-17 10:32:57 -05:00
$sql .= " $sql_status " ;
2014-06-14 21:50:59 -04:00
2015-09-12 00:46:46 -04:00
if ( ! $ticket [ 'firstreplyby' ]) {
$sql .= " , `firstreply`=NOW(), `firstreplyby`= " . intval ( $_SESSION [ 'id' ]) . " " ;
2014-06-14 21:50:59 -04:00
}
2015-01-17 10:32:57 -05:00
// Keep track of replies to this ticket for easier reporting
$sql .= " , `replies`=`replies`+1 " ;
$sql .= $submit_as_customer ? '' : " , `staffreplies`=`staffreplies`+1 " ;
// End and execute the query
2016-10-03 20:44:42 -04:00
$sql .= " WHERE `id`=' { $replyto } ' " ;
2014-06-14 21:50:59 -04:00
hesk_dbQuery ( $sql );
unset ( $sql );
/* Update number of replies in the users table */
2016-10-03 20:44:42 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` SET `replies`=`replies`+1 WHERE `id`=' " . intval ( $_SESSION [ 'id' ]) . " ' " );
2014-06-14 21:50:59 -04:00
// --> Prepare reply message
// 1. Generate the array with ticket info that can be used in emails
$info = array (
2015-09-12 00:46:46 -04:00
'email' => $ticket [ 'email' ],
'category' => $ticket [ 'category' ],
'priority' => $ticket [ 'priority' ],
'owner' => $ticket [ 'owner' ],
'trackid' => $ticket [ 'trackid' ],
'status' => $new_status ,
'name' => $ticket [ 'name' ],
'lastreplier' => ( $submit_as_customer ? $ticket [ 'name' ] : $_SESSION [ 'name' ]),
'subject' => $ticket [ 'subject' ],
'message' => stripslashes ( $message ),
'attachments' => $myattachments ,
'dt' => hesk_date ( $ticket [ 'dt' ], true ),
'lastchange' => hesk_date ( $ticket [ 'lastchange' ], true ),
'id' => $ticket [ 'id' ],
'language' => $ticket [ 'language' ]
2014-06-14 21:50:59 -04:00
);
// 2. Add custom fields to the array
2015-09-12 00:46:46 -04:00
foreach ( $hesk_settings [ 'custom_fields' ] as $k => $v ) {
$info [ $k ] = $v [ 'use' ] ? $ticket [ $k ] : '' ;
2014-06-14 21:50:59 -04:00
}
// 3. Make sure all values are properly formatted for email
$ticket = hesk_ticketToPlain ( $info , 1 , 0 );
2015-01-17 10:32:57 -05:00
// Notify the assigned staff?
2015-09-12 00:46:46 -04:00
if ( $submit_as_customer ) {
if ( $ticket [ 'owner' ] && $ticket [ 'owner' ] != $_SESSION [ 'id' ]) {
2015-09-03 21:58:05 -04:00
hesk_notifyAssignedStaff ( false , 'new_reply_by_customer' , $modsForHesk_settings , 'notify_reply_my' );
2015-01-17 10:32:57 -05:00
}
2015-09-12 00:46:46 -04:00
} // Notify customer?
elseif ( ! isset ( $_POST [ 'no_notify' ]) || intval ( hesk_POST ( 'no_notify' )) != 1 ) {
hesk_notifyCustomer ( $modsForHesk_settings , 'new_reply_by_staff' );
2014-06-14 21:50:59 -04:00
}
2015-01-17 10:32:57 -05:00
// Delete any existing drafts from this owner for this ticket
2016-10-03 20:44:42 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " reply_drafts` WHERE `owner`= " . intval ( $_SESSION [ 'id' ]) . " AND `ticket`= " . intval ( $ticket [ 'id' ]));
2015-01-17 10:32:57 -05:00
2014-06-14 21:50:59 -04:00
/* Set reply submitted message */
$_SESSION [ 'HESK_SUCCESS' ] = TRUE ;
$_SESSION [ 'HESK_MESSAGE' ] = $hesklang [ 'reply_submitted' ];
/* What to do after reply? */
2015-09-12 00:46:46 -04:00
if ( $_SESSION [ 'afterreply' ] == 1 ) {
header ( 'Location: admin_main.php' );
} elseif ( $_SESSION [ 'afterreply' ] == 2 ) {
/* Get the next open ticket that needs a reply */
$res = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `owner` IN ('0',' " . intval ( $_SESSION [ 'id' ]) . " ') AND " . hesk_myCategories () . " AND `status` IN (SELECT `ID` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses`
2015-01-25 00:57:58 -05:00
WHERE `IsNewTicketStatus` = 1 OR `IsCustomerReplyStatus` = 1 OR `IsStaffReopenedStatus` = 1 ) ORDER BY `owner` DESC , `priority` ASC LIMIT 1 " );
2014-06-14 21:50:59 -04:00
2015-09-12 00:46:46 -04:00
if ( hesk_dbNumRows ( $res ) == 1 ) {
$row = hesk_dbFetchAssoc ( $res );
$_SESSION [ 'HESK_MESSAGE' ] .= '<br /><br />' . $hesklang [ 'rssn' ];
header ( 'Location: admin_ticket.php?track=' . $row [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
} else {
header ( 'Location: admin_main.php' );
2014-06-14 21:50:59 -04:00
}
2015-09-12 00:46:46 -04:00
} else {
header ( 'Location: admin_ticket.php?track=' . $ticket [ 'trackid' ] . '&Refresh=' . rand ( 10000 , 99999 ));
2014-06-14 21:50:59 -04:00
}
exit ();
?>