diff --git a/include/class.forms.php b/include/class.forms.php index 1688e5fd79d102c688ce3ab9c6eeb9fd77eb1498..790a48be9c5681c34ef2d7654e42915e253e0eab 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1718,7 +1718,7 @@ class ThreadEntryWidget extends Widget { return new FileUploadField(array( 'id'=>'attach', - 'name'=>'attach:' + $this->field->get('id'), + 'name'=>'attach:' . $this->field->get('id'), 'configuration'=>$config) ); } @@ -1759,8 +1759,9 @@ class FileUploadWidget extends Widget { ?>" class="filedrop"><div class="files"></div> <div class="dropzone"><i class="icon-upload"></i> Drop files here or <a href="#" class="manual">choose - them</a></div></div> - <input type="file" multiple id="file-<?php echo $id; ?>" style="display:none;"/> + them</a> + <input type="file" class="multifile" multiple id="file-<?php echo $id; ?>" style="display:none;"/> + </div></div> <script type="text/javascript"> $(function(){$('#<?php echo $id; ?> .dropzone').filedropbox({ url: 'ajax.php/form/upload/<?php echo $this->field->get('id') ?>', @@ -1780,9 +1781,19 @@ class FileUploadWidget extends Widget { function getValue() { $data = $this->field->getSource(); + $ids = array(); + // Handle manual uploads (IE<10) + if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES[$this->name])) { + foreach (AttachmentFile::format($_FILES[$this->name]) as $file) { + if ($id = AttachmentFile::upload($file)) + $ids[] = $id; + } + return array_merge($ids, parent::getValue() ?: array()); + } // If no value was sent, assume an empty list - if ($data && is_array($data) && !isset($data[$this->name])) + elseif ($data && is_array($data) && !isset($data[$this->name])) return array(); + return parent::getValue(); } } diff --git a/js/filedrop.field.js b/js/filedrop.field.js index 5af121c85178e1ba985e1ee6e835d1fb913ed7da..5edf17c995a810915a68e42d3e85134eba066080 100644 --- a/js/filedrop.field.js +++ b/js/filedrop.field.js @@ -19,8 +19,11 @@ this.options = $.extend({}, $.fn.filedropbox.defaults, events, options); this.$element.filedrop(this.options); - if (!window.FileReader) - $('input[type=file]', this.$element).attr('name', this.options.name).show(); + if (this.options.shim) { + $('input[type=file]', this.$element).attr('name', this.options.name) + .addClass('shim').css('display', 'inline-block').show(); + $('a.manual', this.$element).hide(); + } (this.options.files || []).forEach($.proxy(this.addNode, this)); }; @@ -190,7 +193,8 @@ $.fn.filedropbox.defaults = { files: [], - deletable: true + deletable: true, + shim: !window.FileReader }; $.fn.filedropbox.Constructor = FileDropbox; @@ -270,11 +274,12 @@ files_count = 0, files; - $('#' + opts.fallback_id).css({ - display: 'none', - width: 0, - height: 0 - }); + if (window.FileReader) + $('#' + opts.fallback_id).css({ + display: 'none', + width: 0, + height: 0 + }); this.on('drop', drop).on('dragstart', opts.dragStart).on('dragenter', dragEnter).on('dragover', dragOver).on('dragleave', dragLeave); $(document).on('drop', docDrop).on('dragenter', docEnter).on('dragover', docOver).on('dragleave', docLeave); diff --git a/open.php b/open.php index dc6325529be414986231c746acdcd10f4122f626..93d74c2629e7940970e8f74e7b79873e81959d89 100644 --- a/open.php +++ b/open.php @@ -29,7 +29,8 @@ if ($_POST) { $errors['captcha']=__('Invalid - try again!'); } - $attachments = new FileUploadField(array('id'=>'attach')); + $tform = TicketForm::objects()->one()->getForm($create_vars); + $attachments = $tform->getField('message')->getWidget()->getAttachments(); if (!$errors && $cfg->allowOnlineAttachments()) $vars['cannedattachments'] = $attachments->getClean();