Page 1 of 1

Close a Ticket from an External Application

Posted: Tue Dec 23, 2008 7:56 pm
by azWRX06
/*************************************
Title: Close a Ticket from an External Application
Version: 1.0
Author: Aaron Lee
Demo: NA
Download: NA
Website: NA

Short description: This was just a simple way
one could pass a status change to Hesk and fire
off an email notifying the client that it was closed.
*************************************/

A quick back ground on the situation. I have a support staff from an outside group that is responsible for certain categories in Hesk. When my clients notify me of an issue that in actuality is something the other group is responsible for, they are notified and view the ticket in Hesk.

They then open their own home grown help desk/audit system and open another ticket. They have modified their system to include a field for their Hesk ticket number, which for a time was a reference only.

I created a separate php file and provided a link string that they can use to close the ticket automatically from their system without the need to remember to open Hesk and update the ticket.

Their application simply passes the string,
http://site.com/hesk/errorreportlink.ph ... ET_ID>&s=3

The file name errorreportlink.php, can of course be changed.

If the ticket was open in Hesk, an email will be sent to the client letting them know that the ticket was closed and in my case, provide a link to our internal survey. It also inserts a reply into the ticket indicating that it was closed from the other system.

If the ticket were closed manually before the external application could pass the link, the user of the other system will receive a message from Hesk that the ticket has already been closed.

First is my pre-formated email:

Code: Select all


Dear %%NAME%%,

Our staff has just closed to your ticket "%%SUBJECT%%"

You can view the ticket here:
%%TRACK_URL%%

Please take a moment and fill out this short survey.
http://site.com/survey

*DO NOT REPLY TO THIS E-MAIL*
This is an automated e-mail message sent from our support system. Do not reply to this e-mail as we won't receive your reply!

Yours sincerely,

%%SITE_TITLE%%
%%SITE_URL%%


Next is the code for the page that only receives the links from the other system:

Code: Select all


<?php
/*******************************************************************************
*  Title: Helpdesk software Hesk
*  Version: 0.94.1 @ October 25, 2007
*  Author: Klemen Stirn
*  Website: http://www.phpjunkyard.com
********************************************************************************
*  COPYRIGHT NOTICE
*  Copyright 2005-2007 Klemen Stirn. All Rights Reserved.
*
*  This script 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.
*
*  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 illegal! To remove PHPJunkyard copyright notice you must purchase a
*  license for this script. For more information on how to obtain a license
*  please visit the site below:
*  http://www.phpjunkyard.com/copyright-removal.php
*******************************************************************************/

define('IN_SCRIPT',1);

/* Get all the required files and functions */
require_once('hesk_settings.inc.php');
require_once('language/'.$hesk_settings['language'].'.inc.php');
require_once('inc/common.inc.php');

/* Print header */
require_once('inc/header.inc.php');

$trackingID=strtoupper(hesk_input($_GET['track'],"$hesklang[int_error]: $hesklang[no_trackID]."));
$status=hesk_isNumber($_GET['s'],"$hesklang[int_error]: $hesklang[status_not_valid].");

if ($status==3) {$action=$hesklang['closed'];}
else {$action=$hesklang['opened'];}

/* Connect to database */
require_once('inc/database.inc.php');
hesk_dbConnect() or hesk_error("$hesklang[cant_connect_db] $hesklang[contact_webmsater] $hesk_settings[webmaster_mail]!");

$sql = "UPDATE `hesk_tickets` SET `status`='$status' WHERE `trackid`='$trackingID' LIMIT 1";
$result = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
if (hesk_dbAffectedRows() != 1) {hesk_error("$hesklang[int_error]: Ticket was already closed.");}


$sql3 = "SELECT `id`, `email`, `name`, `subject` FROM `hesk_tickets` WHERE `trackid`='$trackingID' LIMIT 1";
$result3 = hesk_dbQuery($sql3) or hesk_error("$hesklang[cant_sql]: $sql3</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
$ticket3 = hesk_dbFetchAssoc($result3);
$email = $ticket3['email'];
$name = $ticket3['name'];

// You can customize the inserted reply below
//Replace <NAME> with the name or reference to the other system
//Replace <TEXT> with the body text of the inserted message

$sql2 = "INSERT INTO `hesk_replies` (`replyto`,`name`,`message`,`dt`,`attachments`) VALUES ('$ticket3[id]','<NAME>','<TEXT>',NOW(),'')";
$result2 = hesk_dbQuery($sql2) or hesk_error("$hesklang[cant_sql]: $sql2</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");

$trackingURL=$hesk_settings['hesk_url'].'/ticket.php?track='.$trackingID.'&Refresh='.rand(10000,99999);

/* Get e-mail message for customer */
$fp=fopen('emails/closed_by_staff.txt','r');
$message=fread($fp,filesize('emails/closed_by_staff.txt'));
fclose($fp);

$message=str_replace('%%NAME%%',$name,$message);
$message=str_replace('%%SUBJECT%%',$ticket3['subject'],$message);
$message=str_replace('%%TRACK_ID%%',$trackingID,$message);
$message=str_replace('%%TRACK_URL%%',$trackingURL,$message);
$message=str_replace('%%SITE_TITLE%%',$hesk_settings['site_title'] ,$message);
$message=str_replace('%%SITE_URL%%',$hesk_settings['site_url'] ,$message);

/* Send e-mail */
$headers="From: $hesk_settings[noreply_mail]\n";
$headers.="Reply-to: $hesk_settings[noreply_mail]\n";
@mail($ticket3['email'],$hesklang['new_reply_ticket'],$message,$headers);
?>

<p class="smaller"><a href="<?php echo $hesk_settings['site_url']; ?>"
class="smaller"><?php echo $hesk_settings['site_title']; ?></a> >
<a href="index.php?a=start" class="smaller"><?php echo $hesk_settings['hesk_title']; ?></a>
> <?php echo $hesklang['ticket'].' '.$action; ?><br>&nbsp;</p>
</td>
</tr>
<tr>
<td>

<p>&nbsp;</p>

<h3 align="center"><?php echo $hesklang['ticket'].' '.$action; ?></h3>

<p>&nbsp;</p>

<p align="center"><?php echo $hesklang['your_ticket_been'].' '.$action; ?>!</p>
<p align="center"><a href="<?php echo $trackingURL; ?>"><?php echo $hesklang['view_your_ticket']; ?></a></p>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center">
<button type="button" onclick="window.close()" value="close window"> Close Window</Button>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


<?php
require_once('inc/footer.inc.php');
?>

Make sure you locate the area labeled,

// You can customize the inserted reply below
//Replace <NAME> with the name or reference to the other system
//Replace <TEXT> with the body text of the inserted message

and update accordingly.

Of course you could make entires in the language files and alias those as well.