From 15b209c96407e1bf5b0b3151a9cbf69b1125cd5d Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Tue, 20 Mar 2018 12:24:41 +0000 Subject: [PATCH] Thread Entry Action: New Ticket Add thread entry action to create a new ticket. The entry is used to seed ticket data like user, message (issue details) and attachments --- include/class.thread_actions.php | 39 +++++++++++++++++++++++++++++++ include/staff/ticket-open.inc.php | 16 +++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index 3423b17c8..1a1e1a39f 100644 --- a/include/class.thread_actions.php +++ b/include/class.thread_actions.php @@ -431,6 +431,45 @@ class TEA_ResendThreadEntry extends TEA_EditAndResendThreadEntry { } ThreadEntry::registerAction(/* trans */ 'Manage', 'TEA_ResendThreadEntry'); +/* Create a new ticket from thread entry as description */ +class TEA_CreateTicket extends ThreadEntryAction { + static $id = 'create_ticket'; + static $name = /* trans */ 'Create Ticket'; + static $icon = 'plus'; + + function isVisible() { + global $thisstaff; + + return $thisstaff && $thisstaff->hasPerm(Ticket::PERM_CREATE, false); + } + + function getJsStub() { + return sprintf(<<<JS + window.location.href = '%s'; +JS + , $this->getCreateTicketUrl() + ); + } + + function trigger() { + switch ($_SERVER['REQUEST_METHOD']) { + case 'GET': + return $this->trigger__get(); + } + } + + private function trigger__get() { + Http::redirect($this->getCreateTicketUrl()); + } + + private function getCreateTicketUrl() { + return sprintf('tickets.php?a=open&tid=%d', $this->entry->getId()); + } +} + +ThreadEntry::registerAction(/* trans */ 'Manage', 'TEA_CreateTicket'); + + class TEA_CreateTask extends ThreadEntryAction { static $id = 'create_task'; static $name = /* trans */ 'Create Task'; diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index aa396305a..a299117e8 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -6,6 +6,22 @@ if (!defined('OSTSCPINC') || !$thisstaff $info=array(); $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); + +// Use thread entry to seed the ticket +if (!$user && $_GET['tid'] && ($entry = ThreadEntry::lookup($_GET['tid']))) { + if ($entry->user_id) + $user = User::lookup($entry->user_id); + else + + $_SESSION[':form-data']['message'] = Format::htmlchars($entry->getBody()); + if (($m= TicketForm::getInstance()->getField('subject'))) { + $k = 'attach:'.$m->getId(); + foreach ($entry->getAttachments() as $a) + if (!$a->inline && $a->file) + $_SESSION[':form-data'][$k][] = $a->file->getId(); + } +} + if (!$info['topicId']) $info['topicId'] = $cfg->getDefaultTopicId(); -- GitLab