From 6e47f5d25d117dda1c66e82476165d9abce91fc5 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Tue, 16 Apr 2019 16:59:17 +0000 Subject: [PATCH] Refactoring in UploadFile.class.php to simplify things. --- WEB-INF/lib/form/Form.class.php | 12 ++++++------ WEB-INF/lib/form/UploadFile.class.php | 26 ++++++++++---------------- WEB-INF/templates/footer.tpl | 2 +- project_files.php | 3 +-- time_files.php | 3 +-- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/WEB-INF/lib/form/Form.class.php b/WEB-INF/lib/form/Form.class.php index 19dd0111..1f77414b 100644 --- a/WEB-INF/lib/form/Form.class.php +++ b/WEB-INF/lib/form/Form.class.php @@ -95,6 +95,12 @@ class Form { $el = new Submit($params['name']); break; + case 'upload': + import('form.UploadFile'); + $el = new UploadFile($params['name']); + if (isset($params['maxsize'])) $el->setMaxSize($params['maxsize']); + break; + // TODO: refactoring ongoing down from here. case "checkboxgroup": import('form.CheckboxGroup'); @@ -129,12 +135,6 @@ class Form { $el->setData(@$params["data"]); $el->setWidth(@$params["width"]); break; - - case "upload": - import('form.UploadFile'); - $el = new UploadFile($params["name"]); - if (isset($params["maxsize"])) $el->setMaxSize($params["maxsize"]); - break; } if ($el!=null) { $el->setFormName($this->name); diff --git a/WEB-INF/lib/form/UploadFile.class.php b/WEB-INF/lib/form/UploadFile.class.php index e46f29d3..50e8aad5 100644 --- a/WEB-INF/lib/form/UploadFile.class.php +++ b/WEB-INF/lib/form/UploadFile.class.php @@ -29,7 +29,8 @@ import('form.FormElement'); class UploadFile extends FormElement { - var $mMaxSize = 100000; // 100kb // TODO: refactor this. + + var $maxSize = 8388608; // 8MB default max size. function __construct($name) { @@ -37,21 +38,14 @@ class UploadFile extends FormElement { $this->name = $name; } -// TODO: refactoring ongoing down from here. - function setMaxSize($value) { $this->mMaxSize = $value; } - function getMaxSize() { return $this->mMaxSize; } - - function getHtml() { + function setMaxSize($value) { $this->maxSize = $value; } - if ($this->id=="") $this->id = $this->name; - - $html = "\n\tmMaxSize."\"/>"; - $html .= "\n\tname\" id=\"$this->id\""; - - $html .= " type=\"file\""; - $html .= ">"; + function getHtml() { - return $html; - } + if ($this->id == '') $this->id = $this->name; + + $html = "\n\tmaxSize\">"; + $html .= "\n\tid\" name=\"$this->name\">"; + return $html; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index f584e2d5..0cd9a3d1 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.65.4948 | Copyright © Anuko | +  Anuko Time Tracker 1.18.65.4949 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/project_files.php b/project_files.php index 9ca15e39..6ffe123f 100644 --- a/project_files.php +++ b/project_files.php @@ -57,8 +57,7 @@ $files = $fileHelper::getEntityFiles($cl_project_id, 'project'); $form = new Form('fileUploadForm'); $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_project_id)); -$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'),'maxsize'=>67108864)); // 64 MB file upload limit. -// Note: for the above limit to work make sure to set upload_max_filesize and post_max_size in php.ini to at least 64M. +$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'))); $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add'))); diff --git a/time_files.php b/time_files.php index c499b25c..33273da4 100644 --- a/time_files.php +++ b/time_files.php @@ -57,8 +57,7 @@ $files = $fileHelper::getEntityFiles($cl_id, 'time'); $form = new Form('fileUploadForm'); $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); -$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'),'maxsize'=>67108864)); // 64 MB file upload limit. -// Note: for the above limit to work make sure to set upload_max_filesize and post_max_size in php.ini to at least 64M. +$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'))); $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add'))); -- 2.20.1