diff --git a/inc/fieldinterface.class.php b/inc/fieldinterface.class.php index 6d0d6f155..0af277ed3 100644 --- a/inc/fieldinterface.class.php +++ b/inc/fieldinterface.class.php @@ -99,6 +99,11 @@ public function getValueForDesign(); */ public function getValueForTargetText($richText); + /** + * Move uploaded files and make Document items + */ + public function moveUploads(); + /** * Gets the documents IDs * diff --git a/inc/fields/actorfield.class.php b/inc/fields/actorfield.class.php index 7748fd61f..62174f8ff 100644 --- a/inc/fields/actorfield.class.php +++ b/inc/fields/actorfield.class.php @@ -200,6 +200,7 @@ public function getValueForTargetText($richText) { return $value; } + public function moveUploads() {} public function getDocumentsForTarget() { return []; diff --git a/inc/fields/checkboxesfield.class.php b/inc/fields/checkboxesfield.class.php index 9902ef19d..70d175b27 100644 --- a/inc/fields/checkboxesfield.class.php +++ b/inc/fields/checkboxesfield.class.php @@ -269,6 +269,8 @@ public function getValueForTargetText($richText) { return $value; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/datefield.class.php b/inc/fields/datefield.class.php index c8f0194af..b3b503e54 100644 --- a/inc/fields/datefield.class.php +++ b/inc/fields/datefield.class.php @@ -74,6 +74,8 @@ public function hasInput($input) { return isset($input['formcreator_field_' . $this->question->getID()]); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/datetimefield.class.php b/inc/fields/datetimefield.class.php index 2d74580fe..277de0c64 100644 --- a/inc/fields/datetimefield.class.php +++ b/inc/fields/datetimefield.class.php @@ -77,6 +77,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep(Html::convDateTime($this->value)); } + public function moveUploads() {} + public function getDocumentsForTarget() { return [];; } diff --git a/inc/fields/descriptionfield.class.php b/inc/fields/descriptionfield.class.php index 56c7a1c92..c9c77969b 100644 --- a/inc/fields/descriptionfield.class.php +++ b/inc/fields/descriptionfield.class.php @@ -70,6 +70,8 @@ public function getValueForTargetText($richText) { return ''; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 6411e879c..0b6733988 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -325,6 +325,8 @@ public function getValueForTargetText($richText) { return $value; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/emailfield.class.php b/inc/fields/emailfield.class.php index 098515cca..a3c0667de 100644 --- a/inc/fields/emailfield.class.php +++ b/inc/fields/emailfield.class.php @@ -81,6 +81,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/filefield.class.php b/inc/fields/filefield.class.php index c2aef6ea8..11474fa54 100644 --- a/inc/fields/filefield.class.php +++ b/inc/fields/filefield.class.php @@ -90,6 +90,25 @@ public function getValueForTargetText($richText) { return $this->value; } + public function moveUploads() + { + $key = 'formcreator_field_' . $this->question->getID(); + if (!is_array($this->uploads) || !isset($this->uploads["_$key"])) { + return; + } + $answer_value = []; + $index = 0; + foreach ($this->uploads["_$key"] as $document) { + $document = Toolbox::stripslashes_deep($document); + if (is_file(GLPI_TMP_DIR . '/' . $document)) { + $prefix = $this->uploads['_prefix_formcreator_field_' . $this->question->getID()][$index]; + $answer_value[] = $this->saveDocument($document, $prefix); + } + $index++; + } + $this->uploadData = $answer_value; + } + public function getDocumentsForTarget() { return $this->uploadData; } @@ -210,26 +229,6 @@ public function parseAnswerValues($input, $nonDestructive = false) { return false; } - if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) { - $answer_value = []; - $index = 0; - if ($nonDestructive) { - $index = count($input["_$key"]); - } else { - foreach ($input["_$key"] as $document) { - $document = Toolbox::stripslashes_deep($document); - if (is_file(GLPI_TMP_DIR . '/' . $document)) { - $prefix = $input['_prefix_formcreator_field_' . $this->question->getID()][$index]; - $answer_value[] = $this->saveDocument($document, $prefix); - } - $index++; - } - } - $this->uploadData = $answer_value; - $this->value = __('Attached document', 'formcreator'); - - return true; - } if ($this->hasInput($input)) { $this->value = __('Attached document', 'formcreator'); } diff --git a/inc/fields/floatfield.class.php b/inc/fields/floatfield.class.php index 3d6ee38e2..896f4efa1 100644 --- a/inc/fields/floatfield.class.php +++ b/inc/fields/floatfield.class.php @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/hiddenfield.class.php b/inc/fields/hiddenfield.class.php index 870d999f6..bf6dcd483 100644 --- a/inc/fields/hiddenfield.class.php +++ b/inc/fields/hiddenfield.class.php @@ -107,6 +107,8 @@ public function hasInput($input) { return isset($input['formcreator_field_' . $this->question->getID()]); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/hostnamefield.class.php b/inc/fields/hostnamefield.class.php index d903cbc5b..70dfc2248 100644 --- a/inc/fields/hostnamefield.class.php +++ b/inc/fields/hostnamefield.class.php @@ -54,6 +54,8 @@ public function hasInput($input) { return false; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/integerfield.class.php b/inc/fields/integerfield.class.php index b3b32f0ee..3df242488 100644 --- a/inc/fields/integerfield.class.php +++ b/inc/fields/integerfield.class.php @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/ipfield.class.php b/inc/fields/ipfield.class.php index f1268b947..240893461 100644 --- a/inc/fields/ipfield.class.php +++ b/inc/fields/ipfield.class.php @@ -87,6 +87,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($this->value); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/multiselectfield.class.php b/inc/fields/multiselectfield.class.php index b25d73ce2..276b183a9 100644 --- a/inc/fields/multiselectfield.class.php +++ b/inc/fields/multiselectfield.class.php @@ -239,6 +239,8 @@ public function getValueForTargetText($richText) { return $value; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/radiosfield.class.php b/inc/fields/radiosfield.class.php index 919f5c030..4a834a621 100644 --- a/inc/fields/radiosfield.class.php +++ b/inc/fields/radiosfield.class.php @@ -216,6 +216,8 @@ public function getValueForTargetText($richText) { return $this->value; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/requesttypefield.class.php b/inc/fields/requesttypefield.class.php index e4889a313..d2a6af132 100644 --- a/inc/fields/requesttypefield.class.php +++ b/inc/fields/requesttypefield.class.php @@ -156,6 +156,8 @@ public function getValueForTargetText($richText) { return $available[$this->value]; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/textfield.class.php b/inc/fields/textfield.class.php index 54564ac68..dfc976463 100644 --- a/inc/fields/textfield.class.php +++ b/inc/fields/textfield.class.php @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) { return $this->value; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/timefield.class.php b/inc/fields/timefield.class.php index d3327bdea..bc862bbe2 100644 --- a/inc/fields/timefield.class.php +++ b/inc/fields/timefield.class.php @@ -128,6 +128,8 @@ public function getValueForTargetText($richText) { return Toolbox::addslashes_deep($date->format('H:i')); } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/fields/urgencyfield.class.php b/inc/fields/urgencyfield.class.php index 17a754987..d44aa0827 100644 --- a/inc/fields/urgencyfield.class.php +++ b/inc/fields/urgencyfield.class.php @@ -163,6 +163,8 @@ public function getValueForTargetText($richText) { return $available[$this->value]; } + public function moveUploads() {} + public function getDocumentsForTarget() { return []; } diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index 2331466ff..1ddf634ac 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -49,7 +49,9 @@ class PluginFormcreatorFormAnswer extends CommonDBTM const STATUS_REFUSED = 102; const STATUS_ACCEPTED = 103; + /** @var $questionFields PluginFormcreatorField[] fields of the form answers */ private $questionFields = []; + private $questions = []; public static function getStatuses() { @@ -1105,7 +1107,9 @@ public function getFullForm($richText = false) { public function post_addItem() { // Save questions answers + /** @var PluginFormcreatorField $field */ foreach ($this->questionFields as $questionId => $field) { + $field->moveUploads(); $answer = new PluginFormcreatorAnswer(); $answer->add([ 'plugin_formcreator_formanswers_id' => $this->getID(),