Last active
January 4, 2016 13:08
-
-
Save clonemeagain/8625660 to your computer and use it in GitHub Desktop.
Create custom PHP Actions for osTicket filter rules.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 49c17afdb035cf825288613cc1011aeb86ebdb01 Mon Sep 17 00:00:00 2001 | |
From: Grizly <clonemeagain@gmail.com> | |
Date: Sun, 26 Jan 2014 10:44:36 +1100 | |
Subject: [PATCH 1/1] Actual changes to osTicket to implement Custom PHP file | |
actions for Ticket Filters. | |
--- | |
include/class.filter.php | 7 +++++++ | |
include/staff/filter.inc.php | 20 ++++++++++++++++++++ | |
2 files changed, 27 insertions(+), 0 deletions(-) | |
diff --git a/include/class.filter.php b/include/class.filter.php | |
index a17962c..0e86e91 100644 | |
--- a/include/class.filter.php | |
+++ b/include/class.filter.php | |
@@ -53,6 +53,10 @@ class Filter { | |
return true; | |
} | |
+ | |
+ function getCustomScript(){ | |
+ return $this->ht['custom_script']; | |
+ } | |
function reload() { | |
return $this->load($this->getId()); | |
@@ -306,6 +310,8 @@ class Filter { | |
if ($info['reply-to-name']) | |
$ticket['name'] = $info['reply-to-name']; | |
} | |
+ # Use a custom script, we'll include it here, be kind. | |
+ if($this->getCustomScript()) include(INCLUDE_DIR . $this->getCustomScript()); //defaults to custom/*.php | |
# Use canned response. | |
if ($this->getCannedResponse()) | |
@@ -489,6 +495,7 @@ class Filter { | |
.',use_replyto_email='.db_input(isset($vars['use_replyto_email'])?1:0) | |
.',disable_autoresponder='.db_input(isset($vars['disable_autoresponder'])?1:0) | |
.',canned_response_id='.db_input($vars['canned_response_id']) | |
+ .',custom_script='.db_input($vars['custom_script']) | |
.',notes='.db_input(Format::sanitize($vars['notes'])); | |
diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php | |
index 37ac6c6..9e1ae8e 100644 | |
--- a/include/staff/filter.inc.php | |
+++ b/include/staff/filter.inc.php | |
@@ -319,6 +319,26 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); | |
<span class="error"> <?php echo $errors['assign']; ?></span> | |
</td> | |
</tr> | |
+ <tr> | |
+ <td width="180"> | |
+ Custom PHP Script: | |
+ </td> | |
+ <td> | |
+ <select name="custom_script"> | |
+ <option value="0">— None —</option> | |
+ <?php | |
+ foreach(glob(INCLUDE_DIR . 'custom' . DIRECTORY_SEPARATOR .'*.php') as $filename) { | |
+ $filename = str_replace(INCLUDE_DIR,'',$filename); | |
+ echo sprintf('<option value="%s" %s>%s</option>', | |
+ $filename, ($info['custom_script']==$filename)?'selected="selected"':'',$filename); | |
+ } | |
+ | |
+ ?> | |
+ </select> | |
+ <span class="error"> <?php echo $errors['custom_script']; ?></span> | |
+ <em>Programmers Only, this can break things, be careful! (Check the logs!)</em> | |
+ </td> | |
+ </tr> | |
<tr> | |
<th colspan="2"> | |
<em><strong>Admin Notes</strong>: Internal notes. </em> | |
-- | |
1.7.10.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This gets included in class.filter.php::apply(); Save it in /include/custom | |
* | |
* Has context of &$ticket, so all Ticket functions are available and we can modify the ticket directly. | |
* Form $info should also be available. (that which is provided by admin?) | |
*/ | |
//Just to demonstrate, we'll see what we have: | |
print_r($ticket); | |
print_r($info); | |
global $ost; | |
$ost->logInfo('filter_action', "custom script running!"); | |
/** | |
* Output resembles: | |
* root@debiant:/home/grizly/repos/osticket1.8.git/api# php cron.php | |
Array | |
( | |
[name] => osTicket Forums | |
[email] => forum@osticket.com | |
[subject] => [osTicket Forums] wingnut sent you a message. | |
[mid] => <0c99d1a8c91069abd4c88641a4472431@osticket.com> | |
[header] => Delivered-To: clonemeagain@gmail.com | |
Received: by 10.68.215.99 with SMTP id oh3csp27262pbc; Sat, 25 Jan 2014 | |
12:40:15 -0800 (PST) | |
X-Received: by 10.204.118.67 with SMTP id u3mr13028694bkq.41.1390682414753; | |
Sat, 25 Jan 2014 12:40:14 -0800 (PST) | |
Return-Path: <forum@osticket.com> | |
Received: from mailsvr.supportsystem.com (mailsvr.supportsystem.com. | |
[2600:3c00::f03c:91ff:fe70:ef31]) by mx.google.com with ESMTP id | |
k2si8061320bkr.273.2014.01.25.12.40.13 for <clonemeagain@gmail.com>; Sat, 25 | |
Jan 2014 12:40:14 -0800 (PST) | |
Received-SPF: pass (google.com: domain of forum@osticket.com designates | |
2600:3c00::f03c:91ff:fe70:ef31 as permitted sender) | |
client-ip=2600:3c00::f03c:91ff:fe70:ef31; | |
Authentication-Results: mx.google.com; spf=pass (google.com: domain of | |
forum@osticket.com designates 2600:3c00::f03c:91ff:fe70:ef31 as permitted | |
sender) smtp.mail=forum@osticket.com; dkim=pass header.i=@osticket.com | |
To: Grizly <clonemeagain@gmail.com> | |
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=osticket.com; s=mail; | |
t=1390682413; bh=2CSyIKJg6+z2SpmUURfivOML/pTLn648q0w9OSjX5Uc=; | |
h=Subject:Date:From; | |
b=eOtFe1oM22vAyKLoe2ROYZqNwWBYiL/b6drkmMQa8ydYxLuzpPIfoJfoYBvYb09Wk | |
f/AfIPPU7umi6pCy5O9BzhTO9nx2H5q8XYPmlcUMT6rLgH5SmY/3xpy/3OfOlOLpUC | |
iJ5dRHdH/KvU6YcNvtPumi8XExCGosRMzBSmkh+8= | |
Subject: [osTicket Forums] wingnut sent you a message. | |
Date: Sat, 25 Jan 2014 20:40:13 +0000 | |
From: osTicket Forums <forum@osticket.com> | |
Message-ID: <0c99d1a8c91069abd4c88641a4472431@osticket.com> | |
X-Priority: 3 | |
Content-Transfer-Encoding: quoted-printable | |
Content-Type: text/plain; charset="utf-8" | |
[in-reply-to] => | |
[references] => | |
[reply-to] => forum@osticket.com | |
[reply-to-name] => osTicket Forums | |
[emailId] => 1 | |
[message] => <pre>wingnut sent you a message. | |
userdata is part of EasyLogin. | |
I tried the following and received no errors, but no information was populated on the form. | |
if(userdata($data)) { $info=array('name'=>userdata('name'), 'email'=>userdata('email')); } | |
--- | |
Follow the link below to check it out: | |
http://osticket.com/forum/messages/29#75 | |
Have a great day! | |
</pre> | |
[field.5] => [osTicket Forums] wingnut sent you a message. | |
[field.6] => <pre>wingnut sent you a message. | |
userdata is part of EasyLogin. | |
I tried the following and received no errors, but no information was populated on the form. | |
if(userdata($data)) { $info=array('name'=>userdata('name'), 'email'=>userdata('email')); } | |
--- | |
Follow the link below to check it out: | |
http://osticket.com/forum/messages/29#75 | |
Have a great day! | |
</pre> | |
[field.7] => | |
[deptId] => 1 | |
[priorityId] => 3 | |
[slaId] => 1 | |
) | |
Array | |
( | |
[body] => <pre>wingnut sent you a message. | |
userdata is part of EasyLogin. | |
I tried the following and received no errors, but no information was populated on the form. | |
if(userdata($data)) { $info=array('name'=>userdata('name'), 'email'=>userdata('email')); } | |
--- | |
Follow the link below to check it out: | |
http://osticket.com/forum/messages/29#75 | |
Have a great day! | |
</pre> | |
[name] => osTicket Forums | |
[email] => forum@osticket.com | |
[subject] => [osTicket Forums] wingnut sent you a message. | |
[reply-to] => forum@osticket.com | |
[reply-to-name] => osTicket Forums | |
[emailId] => 1 | |
[field.5] => [osTicket Forums] wingnut sent you a message. | |
[field.6] => <pre>wingnut sent you a message. | |
userdata is part of EasyLogin. | |
I tried the following and received no errors, but no information was populated on the form. | |
if(userdata($data)) { $info=array('name'=>userdata('name'), 'email'=>userdata('email')); } | |
--- | |
Follow the link below to check it out: | |
http://osticket.com/forum/messages/29#75 | |
Have a great day! | |
</pre> | |
[field.7] => | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot to include the MySQL change:
Run this mysql command: (your prefix may vary)