Commit b3fc11c3 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(FileTextAreaAttribute) Add option to remove download button

issue #5913
parent 0fae8492
......@@ -130,6 +130,7 @@ class FileDownloadAttribute extends FileAttribute
{
protected $extension;
protected $upload;
protected $download = TRUE;
function __construct ($label, $description, $ldapName, $required = FALSE, $extension = '', $upload = FALSE, $defaultValue = "", $acl = "")
{
......@@ -148,13 +149,15 @@ class FileDownloadAttribute extends FileAttribute
{
if ($this->isVisible()) {
$this->postValue = $this->value;
foreach (array_keys($_POST) as $name) {
if (preg_match('/^download'.$this->getHtmlId().'/', $name)) {
session::set('binary', $this->value);
session::set('binarytype', 'octet-stream');
session::set('binaryfile', $this->computeFilename());
header('location: getbin.php');
exit();
if ($this->download) {
foreach (array_keys($_POST) as $name) {
if (preg_match('/^download'.$this->getHtmlId().'/', $name)) {
session::set('binary', $this->value);
session::set('binarytype', 'octet-stream');
session::set('binaryfile', $this->computeFilename());
header('location: getbin.php');
exit();
}
}
}
if ($this->upload && isset($_POST['upload'.$this->getHtmlId()])) {
......@@ -171,22 +174,27 @@ class FileDownloadAttribute extends FileAttribute
$display .= $this->renderInputField('file', $id);
$display .= $this->renderInputField('submit', 'upload'.$id, array('value' => _('Upload'), 'formnovalidate' => 'formnovalidate'));
}
$display .= $this->renderInputField(
'image', 'download'.$id,
array(
'title' => _('Download'),
'alt' => _('Download'),
'class' => 'center',
'src' => 'geticon.php?context=actions&icon=document-save&size=16',
)
);
if ($this->download) {
$display .= $this->renderInputField(
'image', 'download'.$id,
array(
'title' => _('Download'),
'alt' => _('Download'),
'class' => 'center',
'src' => 'geticon.php?context=actions&icon=document-save&size=16',
)
);
}
return $this->renderAcl($display);
}
public function htmlIds()
{
$id = $this->getHtmlId();
$ids = array('download'.$id);
$ids = array();
if ($this->download) {
$ids[] = 'download'.$id;
}
if ($this->upload) {
$ids[] = $id;
$ids[] = 'upload'.$id;
......@@ -210,12 +218,13 @@ class FileDownloadAttribute extends FileAttribute
class FileTextAreaAttribute extends FileDownloadAttribute
{
/* Default values are not the same that for FileDownloadAttribute */
function __construct ($label, $description, $ldapName, $required = FALSE, $extension = '.txt', $upload = TRUE, $defaultValue = '', $acl = '')
function __construct ($label, $description, $ldapName, $required = FALSE, $extension = '.txt', $upload = TRUE, $download = TRUE, $defaultValue = '', $acl = '')
{
parent::__construct(
$label, $description, $ldapName, $required,
$extension, $upload, $defaultValue, $acl
);
$this->download = $download;
}
/*! \brief Update this attributes postValue depending of the $_POST values
......@@ -224,13 +233,15 @@ class FileTextAreaAttribute extends FileDownloadAttribute
{
if ($this->isVisible()) {
$this->postValue = $this->value;
foreach (array_keys($_POST) as $name) {
if (preg_match('/^download'.$this->getHtmlId().'/', $name)) {
session::set('binary', $this->value);
session::set('binarytype', 'octet-stream');
session::set('binaryfile', $this->computeFilename());
header('location: getbin.php');
exit();
if ($this->download) {
foreach (array_keys($_POST) as $name) {
if (preg_match('/^download'.$this->getHtmlId().'/', $name)) {
session::set('binary', $this->value);
session::set('binarytype', 'octet-stream');
session::set('binaryfile', $this->computeFilename());
header('location: getbin.php');
exit();
}
}
}
if ($this->upload) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment