Skip to content

Instantly share code, notes, and snippets.

@clonemeagain
Last active August 15, 2022 01:18
Show Gist options
  • Save clonemeagain/8089055 to your computer and use it in GitHub Desktop.
Save clonemeagain/8089055 to your computer and use it in GitHub Desktop.
Adds onClose notification template functionality to osTicket 1.8
I've just trawled the code (including latest dev), and no, there is no part of it which will do that..
Shouldn't be too hard to implement though, just a few modifications, and a single db entry!
First, Run this query to create the template:
<?php
INSERT INTO `tickets`.`ost_email_template` (`id`, `tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) VALUES (NULL, 1, 'ticket.close', '[#%{ticket.number}] %{ticket.subject}', '%{ticket.name},
Our customer care team has closed the ticket, #%{ticket.number} on your behalf.
If you wish to provide additional comments or information regarding this issue, please don''t open a new ticket. You can update or view this ticket''s progress online here: %{ticket.client_link}.
%{signature}', NOW(), NOW());
?>
Add the following code: (also below as patches)
/include/class.ticket.php
(doesn't matter where really, between two functions will do:
<?php
function onClose()
{
global $thisstaff, $cfg;
$dept = $this->getDept ();
if ($thisstaff && $vars ['signature'] == 'mine')
$signature = $thisstaff->getSignature ();
elseif ($vars ['signature'] == 'dept' && $dept && $dept->isPublic ())
$signature = $dept->getSignature ();
else
$signature = '';
$variables = array ('signature' => $signature,'staff' => $thisstaff,'poster' => $thisstaff );
if (($email = $dept->getEmail ()) && ($tpl = $dept->getTemplate ()) && ($msg = $tpl->getCloseMsgTemplate ())) {
$msg = $this->replaceVars ( $msg->asArray (), $variables );
if ($cfg->stripQuotedReply () && ($tag = $cfg->getReplySeparator ()))
$msg ['body'] = "<p style=\"display:none\">$tag<p>" . $msg ['body'];
$email->send ( $this->getEmail (), $msg ['subj'], $msg ['body'] );
}
}
?>
/include/class.template.php
Find:
<?php
'staff.pwreset' => array(
'name' => 'Staff Password Reset',
'desc' => 'Notice sent to staff with the password reset link.',
'default' => 'templates/staff.pwreset.txt'),
?>
Add after:
<?php
'ticket.close' => array(
'name' => 'Ticket Closed Notification',
'desc' => 'Notice sent to client on the closure of a ticket.'
)
?>
Just before the final );
Then find
<?php
function getReplyMsgTemplate() {
return $this->getMsgTemplate('ticket.reply');
}
?>
Add after:
<?php
function getCloseMsgTemplate() {
return $this->getMsgTemplate('ticket.close');
}
?>
diff --git a/include/class.template.php b/include/class.template.php
index e135034..d5f3a59 100644
--- a/include/class.template.php
+++ b/include/class.template.php
@@ -65,6 +65,10 @@
'name' => 'Staff Password Reset',
'desc' => 'Notice sent to staff with the password reset link.',
'default' => 'templates/staff.pwreset.txt'),
+ 'ticket.close' => array(
+ 'name' => 'Ticket Closed Notification',
+ 'desc' => 'Notice sent to client on the closure of a ticket.'
+ )
);
function EmailTemplateGroup($id){
@@ -207,6 +211,9 @@
function getReplyMsgTemplate() {
return $this->getMsgTemplate('ticket.reply');
+ }
+ function getCloseMsgTemplate() {
+ return $this->getMsgTemplate('ticket.close');
}
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 273d8e2..f730133 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -793,6 +793,8 @@
$this->reload();
$this->logEvent('closed');
$this->deleteDrafts();
+
+ $this->onClose();
return true;
}
@@ -1634,6 +1636,31 @@
return $response;
}
+
+ function onClose()
+ {
+ global $thisstaff, $cfg;
+
+ $dept = $this->getDept ();
+
+ if ($thisstaff && $vars ['signature'] == 'mine')
+ $signature = $thisstaff->getSignature ();
+ elseif ($vars ['signature'] == 'dept' && $dept && $dept->isPublic ())
+ $signature = $dept->getSignature ();
+ else
+ $signature = '';
+
+ $variables = array ('signature' => $signature,'staff' => $thisstaff,'poster' => $thisstaff );
+
+ if (($email = $dept->getEmail ()) && ($tpl = $dept->getTemplate ()) && ($msg = $tpl->getCloseMsgTemplate ())) {
+
+ $msg = $this->replaceVars ( $msg->asArray (), $variables );
+
+ if ($cfg->stripQuotedReply () && ($tag = $cfg->getReplySeparator ()))
+ $msg ['body'] = "<p style=\"display:none\">$tag<p>" . $msg ['body'];
+ $email->send ( $this->getEmail (), $msg ['subj'], $msg ['body'] );
+ }
+ }
//Activity log - saved as internal notes WHEN enabled!!
function logActivity($title, $note) {
@sandeepkohli2124
Copy link

@clonemeagain,
Can You Help Me, I am unable to do this, after paste, this code,its not working.

@sandeepkohli2124
Copy link

@marinod
Can You help me to setup this.

@clonemeagain
Copy link
Author

Hey chief, this was for an ancient version of osTicket.. trying to use it on a modem version would probably break stuff.

@sandeepkohli2124
Copy link

Yesterday I have installed the latest version but it's giving the same issue.Pls help me

@Dsaamorim
Copy link

I would like to know how to setup this please

@Dsaamorim
Copy link

For me doesn´t work :(

@Dsaamorim
Copy link

@clonemeagain, please if you can help me

@clonemeagain
Copy link
Author

Hi Dsaamorim, this was written in 2016.. osTicket has changed a lot since then. So, it will not work in any current version. Probably better asking them to add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment