2014-06-15 10:12:27 -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-15 10:12:27 -04:00
// Get all the required files and functions
require ( HESK_PATH . 'hesk_settings.inc.php' );
require ( HESK_PATH . 'inc/common.inc.php' );
2015-01-12 12:48:48 -05:00
// Are we in maintenance mode?
hesk_check_maintenance ();
hesk_load_database_functions ();
2014-06-15 10:12:27 -04:00
hesk_session_start ();
// A security check
hesk_token_check ();
// Get the tracking ID
$trackingID = hesk_cleanID () or die ( " $hesklang[int_error] : $hesklang[no_trackID] " );
// Get new status
2015-09-12 00:46:46 -04:00
$status = intval ( hesk_GET ( 's' , 0 ));
2015-06-23 23:29:16 -04:00
$oldStatus = $status ;
2014-06-15 10:12:27 -04:00
$locked = 0 ;
2014-06-25 08:37:51 -04:00
// Connect to database
hesk_dbConnect ();
2014-06-15 10:17:52 -04:00
2015-06-23 23:29:16 -04:00
// Get the close status. It'll be used later on
2015-09-12 00:46:46 -04:00
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsClosedByClient` = 1' );
2015-06-23 23:29:16 -04:00
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$closedStatus = $statusRow [ 'ID' ];
2014-06-15 10:17:52 -04:00
if ( $status == 3 ) // Closed
2014-06-15 10:12:27 -04:00
{
2015-01-12 12:48:48 -05:00
// Is customer closing tickets enabled?
2015-09-12 00:46:46 -04:00
if ( ! $hesk_settings [ 'custclose' ]) {
2015-01-12 12:48:48 -05:00
hesk_error ( $hesklang [ 'attempt' ]);
}
2015-06-23 23:29:16 -04:00
$status = $closedStatus ;
2015-09-12 00:46:46 -04:00
$action = $hesklang [ 'closed' ];
$revision = sprintf ( $hesklang [ 'thist3' ], hesk_date (), $hesklang [ 'customer' ]);
2014-06-15 10:12:27 -04:00
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'custopen' ] != 1 ) {
$locked = 1 ;
2014-06-15 10:12:27 -04:00
}
2015-01-12 12:48:48 -05:00
// Mark that customer resolved the ticket
$closedby_sql = ' , `closedat`=NOW(), `closedby`=0 ' ;
2015-09-12 00:46:46 -04:00
} elseif ( $status == 2 ) // Opened
2014-06-15 10:12:27 -04:00
{
2015-09-12 00:46:46 -04:00
// Is customer reopening tickets enabled?
if ( ! $hesk_settings [ 'custopen' ]) {
hesk_error ( $hesklang [ 'attempt' ]);
}
2014-06-15 10:12:27 -04:00
2015-06-23 23:29:16 -04:00
//-- They want to close the ticket, so get the status that is the default for client-side closes
2015-09-12 00:46:46 -04:00
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsDefaultStaffReplyStatus` = 1' );
2015-06-23 23:29:16 -04:00
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
2015-09-12 00:46:46 -04:00
$action = $hesklang [ 'opened' ];
$revision = sprintf ( $hesklang [ 'thist4' ], hesk_date (), $hesklang [ 'customer' ]);
2014-06-15 10:12:27 -04:00
2015-09-12 00:46:46 -04:00
// We will ask the customer why is the ticket being reopened
$_SESSION [ 'force_form_top' ] = true ;
2015-01-12 12:48:48 -05:00
// Ticket is not resolved
$closedby_sql = ' , `closedat`=NULL, `closedby`=NULL ' ;
2015-09-12 00:46:46 -04:00
} else {
die ( " $hesklang[int_error] : $hesklang[status_not_valid] . " );
2014-06-15 10:12:27 -04:00
}
// Connect to database
hesk_dbConnect ();
// Verify email address match if needed
hesk_verifyEmailMatch ( $trackingID );
2016-10-18 22:01:33 -04:00
// Setup required session vars
$_SESSION [ 't_track' ] = $trackingID ;
$_SESSION [ 't_email' ] = $hesk_settings [ 'e_email' ];
// Load statuses
require_once ( HESK_PATH . 'inc/statuses.inc.php' );
// Is current ticket status even changeable by customers?
$ticket = hesk_dbFetchAssoc ( hesk_dbQuery ( " SELECT `status`, `staffreplies`, `lastreplier` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `trackid`=' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " ) );
if ( ! hesk_can_customer_change_status ( $ticket [ 'status' ])) {
hesk_process_messages ( $hesklang [ 'scno' ], 'ticket.php' );
}
2015-06-23 23:29:16 -04:00
// Lets make status assignment a bit smarter when reopening tickets
2015-09-12 00:46:46 -04:00
if ( $oldStatus == 2 ) {
// If ticket has no staff replies set the status to "New"
if ( $ticket [ 'staffreplies' ] < 1 ) {
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsNewTicketStatus` = 1' );
2015-06-23 23:29:16 -04:00
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
2015-09-12 00:46:46 -04:00
} // If last reply was by customer set status to "Waiting reply from staff"
elseif ( $ticket [ 'lastreplier' ] == 0 ) {
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsCustomerReplyStatus` = 1' );
2015-06-23 23:29:16 -04:00
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
2015-09-12 00:46:46 -04:00
}
// If nothing matches: last reply was from staff, keep status "Waiting reply from customer"
2015-06-23 23:29:16 -04:00
}
2014-06-15 10:12:27 -04:00
// Modify values in the database
2016-10-18 22:01:33 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `status`=' { $status } ', `locked`=' { $locked } ' $closedby_sql , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') WHERE `trackid`=' " . hesk_dbEscape ( $trackingID ) . " ' AND `locked` != '1' " );
2014-06-15 10:12:27 -04:00
// Did we modify anything*
2015-09-12 00:46:46 -04:00
if ( hesk_dbAffectedRows () != 1 ) {
2016-10-18 22:01:33 -04:00
hesk_process_messages ( $hesklang [ 'elocked' ], 'ticket.php' );
2014-06-15 10:12:27 -04:00
}
// Show success message
2015-09-12 00:46:46 -04:00
if ( $status != $closedStatus ) {
2016-04-18 18:34:46 -04:00
hesk_process_messages ( $hesklang [ 'wrepo' ], 'ticket.php' , 'NOTICE' );
2015-09-12 00:46:46 -04:00
} else {
2016-04-18 18:34:46 -04:00
hesk_process_messages ( $hesklang [ 'your_ticket_been' ] . ' ' . $action , 'ticket.php' , 'SUCCESS' );
2014-06-15 10:12:27 -04:00
}