diff --git a/include/class.forms.php b/include/class.forms.php index c7dedaeb1a9d212a3c849a0619c71486850514c6..3aa5f4a93ff8aa92ddf05a51e029650f7e00d7fd 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1696,14 +1696,24 @@ class ThreadEntryWidget extends Widget { if (!$config['attachments']) return; - $attachments = new FileUploadField(array('id'=>'attach', - 'configuration'=>$config)); + $attachments = $this->getAttachments($config); print $attachments->render($client); foreach ($attachments->getMedia() as $type=>$urls) { foreach ($urls as $url) Form::emitMedia($url, $type); } } + + function getAttachments($config=false) { + if (!$config) + $config = $this->field->getConfiguration(); + + return new FileUploadField(array( + 'id'=>'attach', + 'name'=>'attach:' + $this->field->get('id'), + 'configuration'=>$config) + ); + } } class FileUploadWidget extends Widget { @@ -1722,16 +1732,16 @@ class FileUploadWidget extends Widget { $id = substr(md5(spl_object_hash($this)), 10); $attachments = $this->field->getFiles(); $files = array(); - foreach ($this->value ?: array() as $id) { + foreach ($this->value ?: array() as $fid) { $found = false; foreach ($attachments as $f) { - if ($f['id'] == $id) { + if ($f['id'] == $fid) { $files[] = $f; $found = true; break; } } - if (!$found && ($file = AttachmentFile::lookup($id))) { + if (!$found && ($file = AttachmentFile::lookup($fid))) { $files[] = array( 'id' => $file->getId(), 'name' => $file->getName(), diff --git a/include/class.ticket.php b/include/class.ticket.php index d44303ca9acdf2bba0cbc0584a46ec347ed2bbb1..311e098b5d5edcd8f36e08ccd456153f72cec270 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2773,7 +2773,10 @@ class Ticket { unset($vars['assignId']); $create_vars = $vars; - unset($create_vars['cannedattachments']); + $tform = TicketForm::objects()->one()->getForm($create_vars); + $create_vars['cannedattachments'] + = $tform->getField('message')->getWidget()->getAttachments()->getClean(); + if(!($ticket=Ticket::create($create_vars, $errors, 'staff', false))) return false; @@ -2783,11 +2786,9 @@ class Ticket { $response = null; if($vars['response'] && $thisstaff->canPostReply()) { - // unpack any uploaded files into vars. - if ($_FILES['attachments']) - $vars['files'] = AttachmentFile::format($_FILES['attachments']); - $vars['response'] = $ticket->replaceVars($vars['response']); + // $vars['cannedatachments'] contains the attachments placed on + // the response form. if(($response=$ticket->postReply($vars, $errors, false))) { //Only state supported is closed on response if(isset($vars['ticket_state']) && $thisstaff->canCloseTickets()) diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 6a9b533ade9ccb692f05f24127d4e7f5fef78529..5c225ff7266c129f9da88bbe42caf30cda39c39d 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -305,26 +305,10 @@ if ($_POST) <table border="0" cellspacing="0" cellpadding="2" width="100%"> <?php if($cfg->allowAttachments()) { ?> - <tr><td width="100" valign="top"><?php echo __('Attachments');?>:</td> - <td> - <div class="canned_attachments"> - <?php - if($info['cannedattachments']) { - foreach($info['cannedattachments'] as $k=>$id) { - if(!($file=AttachmentFile::lookup($id))) continue; - $hash=$file->getKey().md5($file->getId().session_id().$file->getKey()); - echo sprintf('<label><input type="checkbox" name="cannedattachments[]" - id="f%d" value="%d" checked="checked" - <a href="file.php?h=%s">%s</a> </label> ', - $file->getId(), $file->getId() , $hash, $file->getName()); - } - } - ?> - </div> - <div class="uploads"></div> - <div class="file_input"> - <input type="file" class="multifile" name="attachments[]" size="30" value="" /> - </div> + <tr><td class="attachments" colspan="2"> +<?php +print $response_form->getField('attachments')->render(); +?> </td> </tr> <?php diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 32c7d7e6d3997232287e647832f82e8fb2ca2766..f2e6387d2d9bca7270880f59f23233df6e01bbbd 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -586,15 +586,9 @@ $tcount+= $ticket->getNumNotes(); <label for="attachment"><?php echo __('Attachments');?>:</label> </td> <td id="reply_form_attachments" class="attachments"> - <div class="canned_attachments"> - </div> - <div class="uploads"> - </div> - <div class="file_input"> <?php print $response_form->getField('attachments')->render(); ?> - </div> </td> </tr> <?php diff --git a/scp/js/scp.js b/scp/js/scp.js index 5f2ff747cab99b563227feb3dfbedb0543ebb6fe..9bd4a3f0f23deb40e0243cf38c68e974efff3f22 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -229,9 +229,9 @@ var scp_prep = function() { redactor.observeStart(); } //Canned attachments. - var ca = $('.canned_attachments', fObj); + var ca = $('.attachments', fObj); if(canned.files && ca.length) { - var fdb = ca.parent().find('.dropzone').data('dropbox'); + var fdb = ca.find('.dropzone').data('dropbox'); $.each(canned.files,function(i, j) { fdb.addNode(j); }); diff --git a/scp/tickets.php b/scp/tickets.php index a6b2c9d4c09d634018599baeb76da35a5c778172..ebf2ed08194bc19ae9162a5361461ea89584bd4a 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -41,10 +41,12 @@ if ($_REQUEST['uid']) // Configure form for file uploads $response_form = new Form(array( - 'attachments' => new FileUploadField(array('id'=>'attach')) + 'attachments' => new FileUploadField(array('id'=>'attach', + 'name'=>'attach:response')) )); $note_form = new Form(array( - 'attachments' => new FileUploadField(array('id'=>'attach')) + 'attachments' => new FileUploadField(array('id'=>'attach', + 'name'=>'attach:note')) )); //At this stage we know the access status. we can process the post. @@ -73,10 +75,7 @@ if($_POST && !$errors): //If no error...do the do. $vars = $_POST; - $attachments = $response_form->getField('attachments')->getClean(); - if(!$errors && $attachments) - $vars['cannedattachments'] = array_merge( - $vars['cannedattachments'] ?: array(), $attachments); + $vars['cannedattachments'] = $response_form->getField('attachments')->getClean(); if(!$errors && ($response=$ticket->postReply($vars, $errors, $_POST['emailreply']))) { $msg = sprintf(__('%s: Reply posted successfully'), @@ -334,12 +333,17 @@ if($_POST && !$errors): $vars = $_POST; $vars['uid'] = $user? $user->getId() : 0; + $vars['cannedattachments'] = $response_form->getField('attachments')->getClean(); + if(($ticket=Ticket::open($vars, $errors))) { $msg=__('Ticket created successfully'); $_REQUEST['a']=null; if (!$ticket->checkStaffAccess($thisstaff) || $ticket->isClosed()) $ticket=null; Draft::deleteForNamespace('ticket.staff%', $thisstaff->getId()); + // Drop files from the response attachments widget + $response_form->setSource(array()); + $response_form->getField('attachments')->reset(); unset($_SESSION[':form-data']); } elseif(!$errors['err']) { $errors['err']=__('Unable to create the ticket. Correct the error(s) and try again'); diff --git a/tickets.php b/tickets.php index 8fc98e92c4bd3a24bc20edeb1fd7e79533a7efcf..593c337f313ca43e16e2471343868181f1ea374c 100644 --- a/tickets.php +++ b/tickets.php @@ -79,8 +79,7 @@ if($_POST && is_object($ticket) && $ticket->getId()): 'userId' => $thisclient->getId(), 'poster' => (string) $thisclient->getName(), 'message' => $_POST['message']); - if ($cfg->allowOnlineAttachments()) - $vars['cannedattachments'] = $response_form->getField('attachments')->getClean(); + $vars['cannedattachments'] = $response_form->getField('attachments')->getClean(); if (isset($_POST['draft_id'])) $vars['draft_id'] = $_POST['draft_id'];