Commit 75afd5db authored by Carsten  Rose's avatar Carsten Rose
Browse files

Upload: fixed bug that pathfilenames in table are overwritten with SIP id after reload and save.

CODING.md: edited to be more clearly.
AbstractBuildForm.php: doc
Save.php: If there is no upload, do not save the filename again (which needs to be calculated instead of using the sip)
parent 02fb2d00
...@@ -73,26 +73,27 @@ DELETE ...@@ -73,26 +73,27 @@ DELETE
<button type="button" class="record-delete" data-sip={{SIP}} ><span class="glyphicon glyphicon-trash"></span></button> <button type="button" class="record-delete" data-sip={{SIP}} ><span class="glyphicon glyphicon-trash"></span></button>
Form Build (load) Upload
................. -----------------
* The upload functionality consist of three elements
* 1) A <div> tag with a) an optional filename of an earlier uploaded file plus and b) a trash Button. * The upload UI consist of three elements
* 2) The 'browse' button (<input type='file' name='_upload_<feName>'>). This element will not be send by post. * 1) A <div> tag with a) an optional filename of an earlier uploaded file and b) a trash Button.
* 2) The 'browse' button (<input type='file' name='<feName>'>). This element will not be send by post.
* 3) A HTML hidden element with name=<feName> containing the <sipUpload>. * 3) A HTML hidden element with name=<feName> containing the <sipUpload>.
* A new uniq SIP (sipUpload) will be created for every upload formElement. These 'sipUpload' will be assigned to the browse button and to the delete button. * A new uniq SIP (sipUpload) will be created for every upload formElement. These 'sipUpload' will be assigned to the upload browse button and to the upload delete button.
* The individual sipUpload is necessary to correctly handle multiple simustaenously forms when using r=0. Also, through this uniq id it's easy to distinguish between asynchron uploaded files. * The individual sipUpload is necessary to correctly handle multiple simultaenously forms when using r=0. Also, through this uniq id it's easy to distinguish between asynchron uploaded files.
* The SIP contains the '_FILES' information submitted during the upload. * The SIP on ther server contains the individual '_FILES' information submitted during the upload.
* Via the hidden element <feName> 'save()' access the form individual upload status informations. * Via the hidden element <feName> 'save()', access to the form individual upload status informations is given.
Upload to server, before 'save' Upload to server, before 'save'
............................... ...............................
* If a user open's a file for upload via the browse button, that file is immediately transmitted to the server. The user will see a turning wheel during the upload time. * If a user open's a file for upload via the browse button, that file is immediately transmitted to the server. The user will see a turning wheel during until the upload finished.
* On success the 'Browse; Button disappears and the filename plus the delete button will be displayed (client logic). * After successfull upload the 'Browse' button disappears and the filename, plus the delete button, will be displayed (client logic).
* The uploaded file will be checked: maxsize, mime type, check script. * The uploaded file will be checked: maxsize, mime type, check script.
* The uploaded file is still temporary. It has been renamed from $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] to $_SESSION['X'][<uploadSip>][FILES_TMP_NAME].cached * The uploaded file is still temporary. It has been renamed from $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] to $_SESSION['X'][<uploadSip>][FILES_TMP_NAME].cached
* The upload action will be saved in the user session. * The upload action will be saved in the user session.
* $_SESSION['X'][<uploadSip>][FILES_TMP_NAME|FILES_NAME|FILES_ERROR|FILE_SIZE] * $_SESSION['X'][<uploadSip>][FILES_TMP_NAME|FILES_NAME|FILES_ERROR|FILE_SIZE]
* Clicks the user on delete button. * Clicks the user on delete button:
* In the usersession a flagDelete will be set: $_SESSION['X'][<uploadSip>]['flagDelete']='1' * In the usersession a flagDelete will be set: $_SESSION['X'][<uploadSip>]['flagDelete']='1'
* An optional previous upload file (still not saved on the final place) will be deleted. * An optional previous upload file (still not saved on the final place) will be deleted.
* An optional existing variable $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] will be deleted. The 'flagDelete' must not be change - it's later needed to detect to delete earlier uploaded files. * An optional existing variable $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] will be deleted. The 'flagDelete' must not be change - it's later needed to detect to delete earlier uploaded files.
......
...@@ -1680,7 +1680,7 @@ abstract class AbstractBuildForm { ...@@ -1680,7 +1680,7 @@ abstract class AbstractBuildForm {
} }
/** /**
* Builds an Upload (File) Button. * Build an Upload (File) Button.
* *
* @param array $formElement * @param array $formElement
* @param $htmlFormElementId * @param $htmlFormElementId
...@@ -1693,6 +1693,7 @@ abstract class AbstractBuildForm { ...@@ -1693,6 +1693,7 @@ abstract class AbstractBuildForm {
public function buildFile(array $formElement, $htmlFormElementId, $value, array &$json) { public function buildFile(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = ''; $attribute = '';
# Build param array for uniq SIP
$arr = array(); $arr = array();
$arr['fake_uniq_never_use_this'] = uniqid(); // make sure we get a new SIP. This is needed for multiple forms (same user) with r=0 $arr['fake_uniq_never_use_this'] = uniqid(); // make sure we get a new SIP. This is needed for multiple forms (same user) with r=0
$arr[CLIENT_SIP_FOR_FORM] = $this->store->getVar(SIP_SIP, STORE_SIP); $arr[CLIENT_SIP_FOR_FORM] = $this->store->getVar(SIP_SIP, STORE_SIP);
......
...@@ -134,6 +134,9 @@ class Save { ...@@ -134,6 +134,9 @@ class Save {
$file = $this->doUpload($formElement, $formValues[$column]); $file = $this->doUpload($formElement, $formValues[$column]);
if ($file !== false) { if ($file !== false) {
$formValues[$column] = $file; $formValues[$column] = $file;
} else {
// if there was no new upload, do nothing on this field
unset ($formValues[$column]);
} }
} }
} }
...@@ -151,7 +154,6 @@ class Save { ...@@ -151,7 +154,6 @@ class Save {
*/ */
private function doUpload($formElement, $sipUpload) { private function doUpload($formElement, $sipUpload) {
// Status information about upload file // Status information about upload file
$statusUpload = $this->store->getVar($sipUpload, STORE_EXTRA); $statusUpload = $this->store->getVar($sipUpload, STORE_EXTRA);
if ($statusUpload === false) { if ($statusUpload === false) {
...@@ -196,6 +198,11 @@ class Save { ...@@ -196,6 +198,11 @@ class Save {
private function copyUploadFile(array $formElement, array $statusUpload) { private function copyUploadFile(array $formElement, array $statusUpload) {
$pathFileName = ''; $pathFileName = '';
if (!isset($statusUpload[FILES_NAME])) {
// nothing to upload: e.g. user has deleted a previous uploaded file.
return '';
}
if (isset($formElement[FE_PATH_FILE_NAME])) { if (isset($formElement[FE_PATH_FILE_NAME])) {
// Provide variable '_filename'. Might be substituted in $formElement[FE_PATH_FILE_NAME]. // Provide variable '_filename'. Might be substituted in $formElement[FE_PATH_FILE_NAME].
......
Markdown is supported
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