From 91ef1bfd8df6ef85368151c5607f2a800f478950 Mon Sep 17 00:00:00 2001 From: aydreeihn <adriane@enhancesoft.com> Date: Mon, 7 May 2018 15:44:51 -0500 Subject: [PATCH] Issues Creating Task/Ticket from Thread - In class.forms.php, $this->field->getClean() was null so $new was not populated and attachments were not being carried over, so we must get the fileIds directly from the form-data array - We need to unset the form-data for attachment fields (on tasks and tickets) so that the array is empty each time we try to create a task or ticket from a thread - We need to add files attached to threads where we are creating a task or ticket to the list of allowed files otherwise they will not carry over to new tasks/tickets (only files uploaded by this user in this session were allowed previously) --- include/class.forms.php | 12 ++++++++++++ include/class.thread_actions.php | 6 ++++-- include/staff/ticket-open.inc.php | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index c4d6ea44e..7e0b82919 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -4366,6 +4366,12 @@ class FileUploadWidget extends Widget { $maxfilesize = ($config['size'] ?: 1048576) / 1048576; $files = $F = array(); $new = array_fill_keys($this->field->getClean(), 1); + + //get file ids stored in session when creating tickets/tasks from thread + if (!$new && is_array($_SESSION[':form-data']) + && array_key_exists($this->field->get('name'), $_SESSION[':form-data'])) + $new = array_fill_keys($_SESSION[':form-data'][$this->field->get('name')], 1); + foreach ($attachments as $a) { $F[] = $a->file; unset($new[$a->file_id]); @@ -4449,6 +4455,12 @@ class FileUploadWidget extends Widget { if (isset($_SESSION[':uploadedFiles'])) $allowed += $_SESSION[':uploadedFiles']; + // Files attached to threads where we are creating tasks/tickets are allowed + if (isset($_SESSION[':form-data'][$this->field->get('name')])) { + foreach ($_SESSION[':form-data'][$this->field->get('name')] as $key => $value) + $allowed[$value] = 1; + } + // Canned attachments initiated by this session if (isset($_SESSION[':cannedFiles'])) $allowed += $_SESSION[':cannedFiles']; diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index ee0c8b16d..08e83dcce 100644 --- a/include/class.thread_actions.php +++ b/include/class.thread_actions.php @@ -512,9 +512,11 @@ JS 'description' => Format::htmlchars($this->entry->getBody())); if (($f= TaskForm::getInstance()->getField('description'))) { $k = 'attach:'.$f->getId(); + unset($_SESSION[':form-data'][$k]); foreach ($this->entry->getAttachments() as $a) - if (!$a->inline && $a->file) - $vars[$k][] = $a->file->getId(); + if (!$a->inline && $a->file) { + $_SESSION[':form-data'][$k][] = $a->file->getId(); + } } return $this->getTicketsAPI()->addTask($this->getObjectId(), $vars); diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 2606bb736..5185c11d7 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -15,9 +15,12 @@ if (!$user && $_GET['tid'] && ($entry = ThreadEntry::lookup($_GET['tid']))) { if (($m= TicketForm::getInstance()->getField('message'))) { $k = 'attach:'.$m->getId(); - foreach ($entry->getAttachments() as $a) - if (!$a->inline && $a->file) - $_SESSION[':form-data'][$k][] = $a->file->getId(); + unset($_SESSION[':form-data'][$k]); + foreach ($entry->getAttachments() as $a) { + if (!$a->inline && $a->file) { + $_SESSION[':form-data'][$k][] = $a->file->getId(); + } + } } } -- GitLab