From 1b5cf0508f06fb89f7958d4fdb71f60422e77c6b Mon Sep 17 00:00:00 2001 From: aydreeihn <adriane@enhancesoft.com> Date: Thu, 17 May 2018 13:39:45 -0500 Subject: [PATCH] Create Task/Ticket From Thread Entry Fixes: - unset the sessions form data only in necessary places - refer to a tasks number instead of id in internal notes - use indexOf instead of includes in js for IE compatibility --- include/ajax.tasks.php | 8 ++++---- include/ajax.tickets.php | 7 +++---- include/class.thread_actions.php | 3 +++ include/class.ticket.php | 2 -- include/staff/ticket-open.inc.php | 2 ++ scp/js/thread.js | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/ajax.tasks.php b/include/ajax.tasks.php index 19016e20c..b379382b1 100644 --- a/include/ajax.tasks.php +++ b/include/ajax.tasks.php @@ -86,6 +86,8 @@ class TasksAjaxAPI extends AjaxController { if ($tid) $originalTask = Task::lookup($tid); + else + unset($_SESSION[':form-data']); $info=$errors=array(); if ($_POST) { @@ -116,9 +118,9 @@ class TasksAjaxAPI extends AjaxController { if (($task=Task::create($vars, $errors))) { if ($_SESSION[':form-data']['eid']) { //add internal note to original task: - $taskLink = sprintf('<a href="tasks.php?id=%d"><b>#%d</b></a>', + $taskLink = sprintf('<a href="tasks.php?id=%d"><b>#%s</b></a>', $task->getId(), - $task->getId()); + $task->getNumber()); $entryLink = sprintf('<a href="#entry-%d"><b>%d</b></a> (%s)', $_SESSION[':form-data']['eid'], @@ -143,8 +145,6 @@ class TasksAjaxAPI extends AjaxController { 'note' => __('This Task was created from Task ' . $taskLink)); $task->postNote($note, $errors, $thisstaff); - - unset($_SESSION[':form-data']); } Http::response(201, $task->getId()); diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 0a7cf21bc..5c2584f76 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -1352,9 +1352,9 @@ function refer($tid, $target=null) { if ($_SESSION[':form-data']['eid']) { //add internal note to ticket: - $taskLink = sprintf('<a href="tasks.php?id=%d"><b>#%d</b></a>', + $taskLink = sprintf('<a href="tasks.php?id=%d"><b>#%s</b></a>', $task->getId(), - $task->getId()); + $task->getNumber()); $entryLink = sprintf('<a href="#entry-%d"><b>%d</b></a> (%s)', $_SESSION[':form-data']['eid'], @@ -1380,8 +1380,7 @@ function refer($tid, $target=null) { $task->postNote($note, $errors, $thisstaff); } - unset($_SESSION[':form-data']); - } + } Http::response(201, $task->getId()); } diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index 4f65e38ed..95d116d08 100644 --- a/include/class.thread_actions.php +++ b/include/class.thread_actions.php @@ -511,6 +511,9 @@ JS $vars = array( 'description' => Format::htmlchars($this->entry->getBody())); + if ($_SESSION[':form-data']) + unset($_SESSION[':form-data']); + $_SESSION[':form-data']['tid'] = $this->entry->getThread()->getObJectId(); $_SESSION[':form-data']['eid'] = $this->entry->getId(); $_SESSION[':form-data']['timestamp'] = $this->entry->getCreateDate(); diff --git a/include/class.ticket.php b/include/class.ticket.php index 3c2856d3b..008a1b298 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -3933,8 +3933,6 @@ implements RestrictedAccess, Threadable, Searchable { $oldTicket->logNote($ticketNote['title'], $ticketNote['body'], $thisstaff); elseif ($oldTask) $oldTask->postNote($taskNote, $errors, $thisstaff); - - unset($_SESSION[':form-data']); } // Configure service-level-agreement for this ticket diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 17b9891b9..923e19b41 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -6,6 +6,8 @@ if (!defined('OSTSCPINC') || !$thisstaff $info=array(); $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); +if ($_SESSION[':form-data'] && !$_GET['tid']) + unset($_SESSION[':form-data']); // Use thread entry to seed the ticket if (!$user && $_GET['tid'] && ($entry = ThreadEntry::lookup($_GET['tid']))) { diff --git a/scp/js/thread.js b/scp/js/thread.js index bb67ca4ce..69a1a96c0 100644 --- a/scp/js/thread.js +++ b/scp/js/thread.js @@ -162,7 +162,7 @@ var thread = { // unless referring to thread entry on current page $('div.thread-body a', $container).each(function() { var str = this.toString(); - if (!str.includes('#entry-')) + if (str.indexOf('#entry-') == -1) $(this).attr('target', '_blank'); }); -- GitLab