2014-06-15 10:12:27 -04:00
< ? php
/*******************************************************************************
* Title : Help Desk Software HESK
2015-06-23 23:33:03 -04:00
* Version : 2.6 . 4 from 22 nd June 2015
2014-06-15 10:12:27 -04:00
* Author : Klemen Stirn
* Website : http :// www . hesk . com
********************************************************************************
* COPYRIGHT AND TRADEMARK NOTICE
2015-02-22 22:17:56 -05:00
* Copyright 2005 - 2015 Klemen Stirn . All Rights Reserved .
2014-06-15 10:12:27 -04:00
* HESK is a registered trademark of Klemen Stirn .
* The HESK may be used and modified free of charge by anyone
* AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT .
* By using this code you agree to indemnify Klemen Stirn from any
* liability that might arise from it ' s use .
* Selling the code for this program , in part or full , without prior
* written consent is expressly forbidden .
* Using this code , in part or full , to create derivate work ,
* new scripts or products is expressly forbidden . Obtain permission
* before redistributing this software over the Internet or in
* any other medium . In all cases copyright and header must remain intact .
* This Copyright is in full effect in any country that has International
* Trade Agreements with the United States of America or
* with the European Union .
* Removing any of the copyright notices without purchasing a license
* is expressly forbidden . To remove HESK copyright notice you must purchase
* a license for this script . For more information on how to obtain
* a license please visit the page below :
* https :// www . hesk . com / buy . php
*******************************************************************************/
define ( 'IN_SCRIPT' , 1 );
define ( 'HESK_PATH' , './' );
// 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
$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
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsClosedByClient` = 1' );
$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?
if ( ! $hesk_settings [ 'custclose' ])
{
hesk_error ( $hesklang [ 'attempt' ]);
}
2015-06-23 23:29:16 -04:00
$status = $closedStatus ;
2014-06-15 10:12:27 -04:00
$action = $hesklang [ 'closed' ];
$revision = sprintf ( $hesklang [ 'thist3' ], hesk_date (), $hesklang [ 'customer' ]);
if ( $hesk_settings [ 'custopen' ] != 1 )
{
$locked = 1 ;
}
2015-01-12 12:48:48 -05:00
// Mark that customer resolved the ticket
$closedby_sql = ' , `closedat`=NOW(), `closedby`=0 ' ;
2014-06-15 10:12:27 -04:00
}
elseif ( $status == 2 ) // Opened
{
// Is customer reopening tickets enabled?
if ( ! $hesk_settings [ 'custopen' ])
{
hesk_error ( $hesklang [ 'attempt' ]);
}
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
$statusRes = hesk_dbQuery ( 'SELECT `ID` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'statuses` WHERE `IsDefaultStaffReplyStatus` = 1' );
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
2014-06-15 10:12:27 -04:00
$action = $hesklang [ 'opened' ];
$revision = sprintf ( $hesklang [ 'thist4' ], hesk_date (), $hesklang [ 'customer' ]);
// 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 ' ;
2014-06-15 10:12:27 -04:00
}
else
{
die ( " $hesklang[int_error] : $hesklang[status_not_valid] . " );
}
// Connect to database
hesk_dbConnect ();
// Verify email address match if needed
hesk_verifyEmailMatch ( $trackingID );
2015-06-23 23:29:16 -04:00
// Lets make status assignment a bit smarter when reopening tickets
if ( $oldStatus == 2 )
{
// Get number of replies and last replier (customer or staff)
$ticket = hesk_dbFetchAssoc ( hesk_dbQuery ( " SELECT `staffreplies`, `lastreplier` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `trackid`=' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " ) );
// 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' );
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
}
// 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' );
$statusRow = hesk_dbFetchAssoc ( $statusRes );
$status = $statusRow [ 'ID' ];
}
// If nothing matches: last reply was from staff, keep status "Waiting reply from customer"
}
2014-06-15 10:12:27 -04:00
// Modify values in the database
2015-01-12 12:48:48 -05: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' LIMIT 1 " );
2014-06-15 10:12:27 -04:00
// Did we modify anything*
if ( hesk_dbAffectedRows () != 1 )
{
hesk_error ( $hesklang [ 'elocked' ]);
}
// Show success message
2015-06-23 23:29:16 -04:00
if ( $status != $closedStatus )
2014-06-15 10:12:27 -04:00
{
hesk_process_messages ( $hesklang [ 'wrepo' ], 'ticket.php?track=' . $trackingID . $hesk_settings [ 'e_param' ] . '&Refresh=' . rand ( 10000 , 99999 ), 'NOTICE' );
}
else
{
hesk_process_messages ( $hesklang [ 'your_ticket_been' ] . ' ' . $action , 'ticket.php?track=' . $trackingID . $hesk_settings [ 'e_param' ] . '&Refresh=' . rand ( 10000 , 99999 ), 'SUCCESS' );
}