From b64a1904352a70dcf204976b05ef97fa26cd7861 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 20 Aug 2014 17:29:56 -0500
Subject: [PATCH] forms: Use new file upload field for staff response

---
 include/class.forms.php           |  1 +
 include/staff/ticket-view.inc.php |  4 +++-
 scp/tickets.php                   | 16 ++++++++++++++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/class.forms.php b/include/class.forms.php
index 7f8a0f935..3de1c8292 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -59,6 +59,7 @@ class Form {
     function getTitle() { return $this->title; }
     function getInstructions() { return $this->instructions; }
     function getSource() { return $this->_source; }
+    function setSource($source) { $this->_source = $source; }
 
     /**
      * Validate the form and indicate if there no errors.
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 2b6bc0477..442ca0882 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -591,7 +591,9 @@ $tcount+= $ticket->getNumNotes();
                     <div class="uploads">
                     </div>
                     <div class="file_input">
-                        <input type="file" class="multifile" name="attachments[]" size="30" value="" />
+<?php
+print $response_form->getField('attachments')->render();
+?>
                     </div>
                 </td>
             </tr>
diff --git a/scp/tickets.php b/scp/tickets.php
index 7de8a89fb..8815c3209 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -39,6 +39,11 @@ if($_REQUEST['id']) {
 if ($_REQUEST['uid'])
     $user = User::lookup($_REQUEST['uid']);
 
+// Configure form for file uploads
+$response_form = new Form(array(
+    'attachments' => new FileUploadField(array('id'=>'attach'))
+));
+
 //At this stage we know the access status. we can process the post.
 if($_POST && !$errors):
 
@@ -65,8 +70,10 @@ if($_POST && !$errors):
 
             //If no error...do the do.
             $vars = $_POST;
-            if(!$errors && $_FILES['attachments'])
-                $vars['files'] = AttachmentFile::format($_FILES['attachments']);
+            $attachments = $response_form->getField('attachments')->getClean();
+            if(!$errors && $attachments)
+                $vars['cannedattachments'] = array_merge(
+                    $vars['cannedattachments'] ?: array(), $attachments);
 
             if(!$errors && ($response=$ticket->postReply($vars, $errors, $_POST['emailreply']))) {
                 $msg = sprintf(__('%s: Reply posted successfully'),
@@ -75,6 +82,10 @@ if($_POST && !$errors):
                                 $ticket->getId(), $ticket->getNumber()))
                         );
 
+                // Clear attachment list
+                $response_form->setSource(array());
+                $response_form->getField('attachments')->reset();
+
                 // Remove staff's locks
                 TicketLock::removeStaffLocks($thisstaff->getId(),
                         $ticket->getId());
@@ -465,4 +476,5 @@ if($ticket) {
 
 require_once(STAFFINC_DIR.'header.inc.php');
 require_once(STAFFINC_DIR.$inc);
+print $response_form->getMedia();
 require_once(STAFFINC_DIR.'footer.inc.php');
-- 
GitLab