diff --git a/include/ajax.forms.php b/include/ajax.forms.php index 031ae8785f424e78f512dd3def65ff73a740d65e..da6bb6560724604e4603925ec12dd1fbfd971315 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -98,7 +98,6 @@ class DynamicFormsAjaxAPI extends AjaxController { function attach() { $field = new FileUploadField(); - $field->loadSystemDefaultConfig(); return JsonDataEncoder::encode( array('id'=>$field->upload()) ); diff --git a/include/class.attachment.php b/include/class.attachment.php index 937d09edd5346d331170752077e1b00f9a354e51..2e3b8c55e303ff74996a538352bb9fb46c674fd8 100644 --- a/include/class.attachment.php +++ b/include/class.attachment.php @@ -167,6 +167,8 @@ class GenericAttachments { .' AND a.object_id='.db_input($this->getId()); if(($res=db_query($sql)) && db_num_rows($res)) { while($rec=db_fetch_array($res)) { + $rec['download'] = AttachmentFile::getDownloadForIdAndKey( + $rec['id'], $rec['key']); $this->attachments[] = $rec; } } diff --git a/include/class.file.php b/include/class.file.php index d9266d63376e245aa8bb31dcfdc91af468580c3d..702936c7d5204caa2ab40aa1115947ae7aff9d04 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -107,13 +107,17 @@ class AttachmentFile { return $this->ht['created']; } + static function getDownloadForIdAndKey($id, $key) { + return strtolower($key . md5($id.session_id().strtolower($key))); + } + + /** * Retrieve a signature that can be sent to scp/file.php?h= in order to * download this file */ function getDownloadHash() { - return strtolower($this->getKey() - . md5($this->getId().session_id().strtolower($this->getKey()))); + return self::getDownloadForIdAndKey($this->getId(), $this->getKey()); } function open() { diff --git a/include/class.forms.php b/include/class.forms.php index 0e91683cfc7b783ecd63771fbdeeb98823a1bd8a..2390912d00e70e9ed1e122650d33a6ff7e93537a 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1235,11 +1235,12 @@ class FileUploadField extends FormField { if ($next < $limit * 2) $sizes[$limit] = Format::file_size($limit); + global $cfg; return array( 'size' => new ChoiceField(array( 'label'=>'Maximum File Size', 'hint'=>'Maximum size of a single file uploaded to this field', - 'default'=>'262144', + 'default'=>$cfg->getMaxFileSize(), 'choices'=>$sizes )), 'extensions' => new TextareaField(array( @@ -1247,7 +1248,7 @@ class FileUploadField extends FormField { 'hint'=>'Enter allowed file extensions separated by a comma. e.g .doc, .pdf. To accept all files enter wildcard <b><i>.*</i></b> — i.e dotStar (NOT Recommended).', - 'default'=>'.doc, .pdf, .jpg, .jpeg, .gif, .png, .xls, .docx, .xlsx, .txt', + 'default'=>$cfg->getAllowedFileTypes(), 'configuration'=>array('html'=>false, 'rows'=>2), )), 'max' => new TextboxField(array( @@ -1261,19 +1262,6 @@ class FileUploadField extends FormField { ); } - function loadSystemDefaultConfig() { - global $cfg; - return array( - 'max' => $cfg->getStaffMaxFileUploads(), - 'size' => $cfg->getMaxFileSize(), - 'extensions' => $cfg->getAllowedFileTypes(), - ); - } - - function getConfiguration() { - return parent::getConfiguration() ?: $this->loadSystemDefaultConfig(); - } - function upload() { $config = $this->getConfiguration(); diff --git a/js/filedrop.field.js b/js/filedrop.field.js index 987e4ba429a7c5bd4808effa776a95171e543a13..1dd179d6a5a07c2814de5546ccd5bfc83dac43c0 100644 --- a/js/filedrop.field.js +++ b/js/filedrop.field.js @@ -95,7 +95,7 @@ var filenode = $('<div class="file"></div>') .append($('<div class="filetype"></div>').addClass()) - .append($('<div class="filename"></div>').text(file.name) + .append($('<div class="filename"></div>') .append($('<span class="filesize"></span>').text( this.fileSize(parseInt(file.size)) )).append($('<div class="upload-rate pull-right"></div>')) @@ -113,6 +113,13 @@ } if (file.id) filenode.data('fileId', file.id); + if (file.download) + filenode.find('.filename').prepend( + $('<a class="no-pjax" target="_blank"></a>').text(file.name) + .attr('href', 'file.php?h='+escape(file.download)) + ); + else + filenode.find('.filename').prepend(document.createTextNode(file.name)); this.$element.parent().find('.files').append(filenode); this.uploads.push(filenode); return filenode;