2014-11-23 00:20:28 -05:00
< ? php
/*******************************************************************************
2015-09-12 00:46:46 -04:00
* Title : Help Desk Software HESK
* Version : 2.6 . 5 from 28 th August 2015
* Author : Klemen Stirn
* Website : http :// www . hesk . com
********************************************************************************
* COPYRIGHT AND TRADEMARK NOTICE
* Copyright 2005 - 2015 Klemen Stirn . All Rights Reserved .
* 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' , '../' );
2014-11-23 00:20:28 -05: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 ();
hesk_session_start ();
hesk_dbConnect ();
hesk_isLoggedIn ();
2015-09-03 21:58:05 -04:00
$modsForHesk_settings = mfh_getSettings ();
2014-11-23 00:20:28 -05:00
/* Set correct return URL */
2015-09-12 00:46:46 -04:00
if ( isset ( $_SERVER [ 'HTTP_REFERER' ])) {
$url = hesk_input ( $_SERVER [ 'HTTP_REFERER' ]);
$url = str_replace ( '&' , '&' , $url );
if ( $tmp = strstr ( $url , 'show_tickets.php' )) {
$referer = $tmp ;
} elseif ( $tmp = strstr ( $url , 'find_tickets.php' )) {
$referer = $tmp ;
} elseif ( $tmp = strstr ( $url , 'admin_main.php' )) {
$referer = $tmp ;
} else {
$referer = 'admin_main.php' ;
2014-11-23 00:20:28 -05:00
}
2015-09-12 00:46:46 -04:00
} else {
$referer = 'admin_main.php' ;
2014-11-23 00:20:28 -05:00
}
/* Is this a delete ticket request from within a ticket ("delete" icon)? */
2015-09-12 00:46:46 -04:00
if ( isset ( $_GET [ 'delete_ticket' ])) {
2014-11-23 00:20:28 -05:00
/* Check permissions for this feature */
2015-09-12 00:46:46 -04:00
hesk_checkPermission ( 'can_del_tickets' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ();
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
// Tracking ID
$trackingID = hesk_cleanID () or die ( $hesklang [ 'int_error' ] . ': ' . $hesklang [ 'no_trackID' ]);
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* Get ticket info */
$result = hesk_dbQuery ( " SELECT `id`,`trackid`,`category` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `trackid`=' " . hesk_dbEscape ( $trackingID ) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 1 ) {
hesk_error ( $hesklang [ 'ticket_not_found' ]);
}
$ticket = hesk_dbFetchAssoc ( $result );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* Is this user allowed to delete tickets inside this category? */
hesk_okCategory ( $ticket [ 'category' ]);
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
hesk_fullyDeleteTicket ();
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
hesk_process_messages ( sprintf ( $hesklang [ 'num_tickets_deleted' ], 1 ), $referer , 'SUCCESS' );
2014-11-23 00:20:28 -05:00
}
/* This is a request from ticket list. Must be POST and id must be an array */
2015-09-12 00:46:46 -04:00
if ( ! isset ( $_POST [ 'id' ]) || ! is_array ( $_POST [ 'id' ])) {
hesk_process_messages ( $hesklang [ 'no_selected' ], $referer , 'NOTICE' );
} /* If not, then needs an action (a) POST variable set */
elseif ( ! isset ( $_POST [ 'a' ])) {
hesk_process_messages ( $hesklang [ 'invalid_action' ], $referer );
2014-11-23 00:20:28 -05:00
}
2015-09-12 00:46:46 -04:00
$i = 0 ;
2014-11-23 00:20:28 -05:00
2015-01-11 16:27:48 -05:00
// Possible priorities
$priorities = array (
2015-09-12 00:46:46 -04:00
'critical' => array ( 'value' => 0 , 'text' => $hesklang [ 'critical' ], 'formatted' => '<font class="critical">' . $hesklang [ 'critical' ] . '</font>' ),
'high' => array ( 'value' => 1 , 'text' => $hesklang [ 'high' ], 'formatted' => '<font class="important">' . $hesklang [ 'high' ] . '</font>' ),
'medium' => array ( 'value' => 2 , 'text' => $hesklang [ 'medium' ], 'formatted' => '<font class="medium">' . $hesklang [ 'medium' ] . '</font>' ),
'low' => array ( 'value' => 3 , 'text' => $hesklang [ 'low' ], 'formatted' => $hesklang [ 'low' ]),
2015-01-11 16:27:48 -05:00
);
// Change priority
2015-09-12 00:46:46 -04:00
if ( array_key_exists ( $_POST [ 'a' ], $priorities )) {
2015-01-11 16:27:48 -05:00
// A security check
hesk_token_check ( 'POST' );
// Priority info
$priority = $priorities [ $_POST [ 'a' ]];
2015-09-12 00:46:46 -04:00
foreach ( $_POST [ 'id' ] as $this_id ) {
if ( is_array ( $this_id )) {
2015-01-11 16:27:48 -05:00
continue ;
}
$this_id = intval ( $this_id ) or hesk_error ( $hesklang [ 'id_not_valid' ]);
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT `priority`, `category` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`= { $this_id } LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 1 ) {
2015-01-11 16:27:48 -05:00
continue ;
}
$ticket = hesk_dbFetchAssoc ( $result );
2015-09-12 00:46:46 -04:00
if ( $ticket [ 'priority' ] == $priority [ 'value' ]) {
2015-01-11 16:27:48 -05:00
continue ;
}
hesk_okCategory ( $ticket [ 'category' ]);
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist8' ], hesk_date (), $priority [ 'formatted' ], $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `priority`=' { $priority [ 'value' ] } ', `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') WHERE `id`= { $this_id } LIMIT 1 " );
2015-01-11 16:27:48 -05:00
$i ++ ;
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $hesklang [ 'pri_set_to' ] . ' ' . $priority [ 'formatted' ], $referer , 'SUCCESS' );
} /* DELETE */
elseif ( $_POST [ 'a' ] == 'delete' ) {
2014-11-23 00:20:28 -05:00
/* Check permissions for this feature */
2015-09-12 00:46:46 -04:00
hesk_checkPermission ( 'can_del_tickets' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-11-23 00:20:28 -05:00
2015-01-11 16:27:48 -05:00
// Will we need ticket notifications?
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'notify_closed' ]) {
2015-01-11 16:27:48 -05:00
require ( HESK_PATH . 'inc/email_functions.inc.php' );
}
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist3' ], hesk_date (), $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
2015-01-11 16:27:48 -05:00
2015-09-12 00:46:46 -04:00
foreach ( $_POST [ 'id' ] as $this_id ) {
if ( is_array ( $this_id )) {
continue ;
2014-11-23 00:20:28 -05:00
}
$this_id = intval ( $this_id ) or hesk_error ( $hesklang [ 'id_not_valid' ]);
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT `id`,`trackid`,`category` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`=' " . intval ( $this_id ) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 1 ) {
continue ;
}
2014-11-23 00:20:28 -05:00
$ticket = hesk_dbFetchAssoc ( $result );
hesk_okCategory ( $ticket [ 'category' ]);
hesk_fullyDeleteTicket ();
$i ++ ;
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( sprintf ( $hesklang [ 'num_tickets_deleted' ], $i ), $referer , 'SUCCESS' );
} /* MERGE TICKETS */
elseif ( $_POST [ 'a' ] == 'merge' ) {
2014-11-23 00:20:28 -05:00
/* Check permissions for this feature */
2015-09-12 00:46:46 -04:00
hesk_checkPermission ( 'can_merge_tickets' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* Sort IDs, tickets will be merged to the lowest ID */
2014-11-23 00:20:28 -05:00
sort ( $_POST [ 'id' ], SORT_NUMERIC );
/* Select lowest ID as the target ticket */
$merge_into = array_shift ( $_POST [ 'id' ]);
2015-09-12 00:46:46 -04:00
/* Merge tickets or throw an error */
if ( hesk_mergeTickets ( $_POST [ 'id' ], $merge_into )) {
hesk_process_messages ( $hesklang [ 'merged' ], $referer , 'SUCCESS' );
} else {
$hesklang [ 'merge_err' ] .= ' ' . $_SESSION [ 'error' ];
2014-11-23 00:20:28 -05:00
hesk_cleanSessionVars ( $_SESSION [ 'error' ]);
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $hesklang [ 'merge_err' ], $referer );
2014-11-23 00:20:28 -05:00
}
2015-09-12 00:46:46 -04:00
} /* TAG/UNTAG TICKETS */
elseif ( $_POST [ 'a' ] == 'tag' || $_POST [ 'a' ] == 'untag' ) {
2014-11-23 00:20:28 -05:00
/* Check permissions for this feature */
2015-09-12 00:46:46 -04:00
hesk_checkPermission ( 'can_add_archive' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
if ( $_POST [ 'a' ] == 'tag' ) {
$archived = 1 ;
2014-11-23 00:20:28 -05:00
$action = $hesklang [ 'num_tickets_tag' ];
2015-09-12 00:46:46 -04:00
} else {
$archived = 0 ;
2014-11-23 00:20:28 -05:00
$action = $hesklang [ 'num_tickets_untag' ];
}
2015-09-12 00:46:46 -04:00
foreach ( $_POST [ 'id' ] as $this_id ) {
if ( is_array ( $this_id )) {
continue ;
2014-11-23 00:20:28 -05:00
}
$this_id = intval ( $this_id ) or hesk_error ( $hesklang [ 'id_not_valid' ]);
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT `id`,`trackid`,`category` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`=' " . intval ( $this_id ) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 1 ) {
continue ;
}
2014-11-23 00:20:28 -05:00
$ticket = hesk_dbFetchAssoc ( $result );
hesk_okCategory ( $ticket [ 'category' ]);
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `archive`=' $archived ' WHERE `id`=' " . intval ( $this_id ) . " ' LIMIT 1 " );
2014-11-23 00:20:28 -05:00
$i ++ ;
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( sprintf ( $action , $i ), $referer , 'SUCCESS' );
} /* JUST CLOSE */
else {
2014-11-23 00:20:28 -05:00
/* Check permissions for this feature */
2015-09-12 00:46:46 -04:00
hesk_checkPermission ( 'can_view_tickets' );
2014-11-23 00:20:28 -05:00
hesk_checkPermission ( 'can_reply_tickets' );
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-11-23 00:20:28 -05:00
require ( HESK_PATH . 'inc/email_functions.inc.php' );
2015-09-12 00:46:46 -04:00
$revision = sprintf ( $hesklang [ 'thist3' ], hesk_date (), $_SESSION [ 'name' ] . ' (' . $_SESSION [ 'user' ] . ')' );
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
foreach ( $_POST [ 'id' ] as $this_id ) {
if ( is_array ( $this_id )) {
continue ;
2014-11-23 00:20:28 -05:00
}
2015-09-12 00:46:46 -04:00
$this_id = intval ( $this_id ) or hesk_error ( $hesklang [ 'id_not_valid' ]);
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`=' " . intval ( $this_id ) . " ' LIMIT 1 " );
2014-11-23 00:20:28 -05:00
$ticket = hesk_dbFetchAssoc ( $result );
hesk_okCategory ( $ticket [ 'category' ]);
2015-09-12 00:46:46 -04:00
$closedStatusRS = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " statuses` WHERE `IsStaffClosedOption` = 1 " );
2014-11-23 00:20:28 -05:00
$closedStatus = hesk_dbFetchAssoc ( $closedStatusRS );
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `status`=' " . $closedStatus [ 'ID' ] . " ', `closedat`=NOW(), `closedby`= " . intval ( $_SESSION [ 'id' ]) . " , `history`=CONCAT(`history`,' " . hesk_dbEscape ( $revision ) . " ') WHERE `id`=' " . intval ( $this_id ) . " ' LIMIT 1 " );
$i ++ ;
2015-01-11 16:27:48 -05:00
// Notify customer of closed ticket?
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'notify_closed' ]) {
2015-01-11 16:27:48 -05:00
$ticket [ 'dt' ] = hesk_date ( $ticket [ 'dt' ], true );
$ticket [ 'lastchange' ] = hesk_date ( $ticket [ 'lastchange' ], true );
2015-02-22 11:40:23 -05:00
$ticket = hesk_ticketToPlain ( $ticket , 1 , 0 );
2015-09-12 00:46:46 -04:00
hesk_notifyCustomer ( $modsForHesk_settings , 'ticket_closed' );
2015-01-11 16:27:48 -05:00
}
2015-09-12 00:46:46 -04:00
}
2014-11-23 00:20:28 -05:00
2015-09-12 00:46:46 -04:00
hesk_process_messages ( sprintf ( $hesklang [ 'num_tickets_closed' ], $i ), $referer , 'SUCCESS' );
2014-11-23 00:20:28 -05:00
}
/*** START FUNCTIONS ***/
function hesk_fullyDeleteTicket ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang , $ticket ;
2014-11-23 00:20:28 -05:00
/* Delete attachment files */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " attachments` WHERE `ticket_id`=' " . hesk_dbEscape ( $ticket [ 'trackid' ]) . " ' " );
if ( hesk_dbNumRows ( $res )) {
$hesk_settings [ 'server_path' ] = dirname ( dirname ( __FILE__ ));
while ( $file = hesk_dbFetchAssoc ( $res )) {
hesk_unlink ( $hesk_settings [ 'server_path' ] . '/' . $hesk_settings [ 'attach_dir' ] . '/' . $file [ 'saved_name' ]);
2014-11-23 00:20:28 -05:00
}
}
/* Delete attachments info from the database */
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " attachments` WHERE `ticket_id`=' " . hesk_dbEscape ( $ticket [ 'trackid' ]) . " ' " );
2014-11-23 00:20:28 -05:00
/* Delete the ticket */
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` WHERE `id`=' " . intval ( $ticket [ 'id' ]) . " ' " );
2014-11-23 00:20:28 -05:00
/* Delete replies to the ticket */
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " replies` WHERE `replyto`=' " . intval ( $ticket [ 'id' ]) . " ' " );
2014-11-23 00:20:28 -05:00
/* Delete ticket notes */
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " notes` WHERE `ticket`=' " . intval ( $ticket [ 'id' ]) . " ' " );
2014-11-23 00:20:28 -05:00
2015-01-11 16:27:48 -05:00
/* Delete ticket reply drafts */
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " reply_drafts` WHERE `ticket`= " . intval ( $ticket [ 'id' ]));
2015-01-11 16:27:48 -05:00
2014-11-23 00:20:28 -05:00
return true ;
}
2015-09-12 00:46:46 -04:00
2014-11-23 00:20:28 -05:00
?>