diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index 3423b17c8a3e1ac62ef266ed0560f88b2e27021c..1a1e1a39f0ea8431330ff1456bc9096b3b6edc6e 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 aa396305a70f7b99c0a12e4bad6ed4cbe04e6257..a299117e88f672ec6a1349a300ba5fa71c41fc92 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();