@@ -144,7 +144,7 @@ public static function getJSFields() {
144144 *
145145 * @return integer|NULL
146146 */
147- private function saveDocument ($ file ) {
147+ private function saveDocument ($ file, $ prefix ) {
148148 global $ DB ;
149149
150150 $ sectionTable = PluginFormcreatorSection::getTable ();
@@ -177,14 +177,15 @@ private function saveDocument($file) {
177177 return ;
178178 }
179179
180- $ doc = new Document ();
181- $ file_data = [];
182- $ file_data ["name " ] = Toolbox::addslashes_deep ($ form ->getField ('name ' ). ' - ' . $ this ->fields ['name ' ]);
183- $ file_data ["entities_id " ] = isset ($ _SESSION ['glpiactive_entity ' ])
184- ? $ _SESSION ['glpiactive_entity ' ]
185- : $ form ->getField ('entities_id ' );
186- $ file_data ["is_recursive " ] = $ form ->getField ('is_recursive ' );
187- $ file_data ['_filename ' ] = [$ file ];
180+ $ doc = new Document ();
181+ $ file_data = [];
182+ $ file_data ["name " ] = Toolbox::addslashes_deep ($ form ->getField ('name ' ). ' - ' . $ this ->fields ['name ' ]);
183+ $ file_data ["entities_id " ] = isset ($ _SESSION ['glpiactive_entity ' ])
184+ ? $ _SESSION ['glpiactive_entity ' ]
185+ : $ form ->getField ('entities_id ' );
186+ $ file_data ["is_recursive " ] = $ form ->getField ('is_recursive ' );
187+ $ file_data ['_filename ' ] = [$ file ];
188+ $ file_data ['_prefix_filename ' ] = [$ prefix ];
188189 if ($ docID = $ doc ->add ($ file_data )) {
189190 return $ docID ;
190191 }
@@ -199,10 +200,13 @@ public function parseAnswerValues($input) {
199200 }
200201
201202 $ answer_value = [];
203+ $ index = 0 ;
202204 foreach ($ input ["_ $ key " ] as $ document ) {
203205 if (is_file (GLPI_TMP_DIR . '/ ' . $ document )) {
204- $ answer_value [] = $ this ->saveDocument ($ document );
206+ $ prefix = $ input ['_prefix_formcreator_field_ ' . $ this ->fields ['id ' ]][$ index ];
207+ $ answer_value [] = $ this ->saveDocument ($ document , $ prefix );
205208 }
209+ $ index ++;
206210 }
207211 $ this ->uploadData = $ answer_value ;
208212 $ this ->value = __ ('Attached document ' , 'formcreator ' );
0 commit comments