From c7557724ef269db3e216dca35d18c117466ba4d9 Mon Sep 17 00:00:00 2001
From: Guillaume AGNIERAY <dev@agnieray.net>
Date: Wed, 22 Sep 2021 21:40:58 +0200
Subject: [PATCH 4/5] Fix attachments whith Summernote; refs #1568

---
 .../Controllers/Crud/MailingsController.php   | 20 +++++++++----------
 .../templates/default/mailing_adherents.tpl   |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/galette/lib/Galette/Controllers/Crud/MailingsController.php b/galette/lib/Galette/Controllers/Crud/MailingsController.php
index d6763552..77ffa774 100644
--- a/galette/lib/Galette/Controllers/Crud/MailingsController.php
+++ b/galette/lib/Galette/Controllers/Crud/MailingsController.php
@@ -333,15 +333,15 @@ class MailingsController extends CrudController
                 $mailing->html = (isset($post['mailing_html'])) ? true : false;
 
                 //handle attachments
-                if (isset($_FILES['files'])) {
-                    $cnt_files = count($_FILES['files']['name']);
+                if (isset($_FILES['attachment'])) {
+                    $cnt_files = count($_FILES['attachment']['name']);
                     for ($i = 0; $i < $cnt_files; $i++) {
-                        if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) {
-                            if ($_FILES['files']['tmp_name'][$i] != '') {
-                                if (is_uploaded_file($_FILES['files']['tmp_name'][$i])) {
+                        if ($_FILES['attachment']['error'][$i] === UPLOAD_ERR_OK) {
+                            if ($_FILES['attachment']['tmp_name'][$i] != '') {
+                                if (is_uploaded_file($_FILES['attachment']['tmp_name'][$i])) {
                                     $da_file = array();
-                                    foreach (array_keys($_FILES['files']) as $key) {
-                                        $da_file[$key] = $_FILES['files'][$key][$i];
+                                    foreach (array_keys($_FILES['attachment']) as $key) {
+                                        $da_file[$key] = $_FILES['attachment'][$key][$i];
                                     }
                                     $res = $mailing->store($da_file);
                                     if ($res < 0) {
@@ -350,13 +350,13 @@ class MailingsController extends CrudController
                                     }
                                 }
                             }
-                        } elseif ($_FILES['files']['error'][$i] !== UPLOAD_ERR_NO_FILE) {
+                        } elseif ($_FILES['attachment']['error'][$i] !== UPLOAD_ERR_NO_FILE) {
                             Analog::log(
-                                $this->logo->getPhpErrorMessage($_FILES['files']['error'][$i]),
+                                $this->logo->getPhpErrorMessage($_FILES['attachment']['error'][$i]),
                                 Analog::WARNING
                             );
                             $error_detected[] = $this->logo->getPhpErrorMessage(
-                                $_FILES['files']['error'][$i]
+                                $_FILES['attachment']['error'][$i]
                             );
                         }
                     }
diff --git a/galette/templates/default/mailing_adherents.tpl b/galette/templates/default/mailing_adherents.tpl
index 2118dc4d..878117fc 100644
--- a/galette/templates/default/mailing_adherents.tpl
+++ b/galette/templates/default/mailing_adherents.tpl
@@ -55,7 +55,7 @@
                     {/if}
                     <label for="attachment" class="bline tooltip" title="{_T string="Select attachments"}">{_T string="Add attachment"}</label>
                     <span class="tip">{_T string="Select files to add as attachments.<br/>Multiple file selection using 'ctrl' or 'shift' keys are only available on compatible browsers."}</span>
-                    <input type="file" name="files[]" name="attachment" id="attachment" multiple="multiple">
+                    <input type="file" name="attachment[]" id="attachment" multiple="multiple">
                 </div>
             </section>
 
-- 
2.30.2

