From 74665d4a8878e48e69efbd32ccdf555c19054222 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Thu, 23 Sep 2021 17:55:58 +0200 Subject: [PATCH] Introduzione opt-out newsletter per Referenti e Sedi --- modules/newsletter/ajax/table.php | 4 ++-- modules/newsletter/src/Newsletter.php | 2 +- plugins/referenti/actions.php | 4 ++++ plugins/referenti/add.php | 6 +++++- plugins/referenti/edit.php | 6 +++++- plugins/sedi/actions.php | 4 ++++ plugins/sedi/edit.php | 7 ++++++- update/2_4_26.sql | 5 +++++ 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/modules/newsletter/ajax/table.php b/modules/newsletter/ajax/table.php index ed4f15f23..c4979b8eb 100644 --- a/modules/newsletter/ajax/table.php +++ b/modules/newsletter/ajax/table.php @@ -114,12 +114,12 @@ foreach ($destinatari_filtrati as $destinatario) { $riga = array_merge($riga, [ '
'. - (!empty($anagrafica->enable_newsletter) ? + (!empty($origine->enable_newsletter) ? ' '.tr('Abilitato').'' : ' '.tr('Disabilitato').'' ).'
', - '
'.(empty($lista) && !empty($origine->email) && !empty($anagrafica->enable_newsletter) ? ' + '
'.(empty($lista) && !empty($origine->email) && !empty($origine->enable_newsletter) ? ' ' : '').' diff --git a/modules/newsletter/src/Newsletter.php b/modules/newsletter/src/Newsletter.php index ed02d46bc..74fe13040 100755 --- a/modules/newsletter/src/Newsletter.php +++ b/modules/newsletter/src/Newsletter.php @@ -147,7 +147,7 @@ class Newsletter extends Model $anagrafica = $origine instanceof Anagrafica ? $origine : $origine->anagrafica; - $abilita_newsletter = $anagrafica->enable_newsletter; + $abilita_newsletter = $origine->enable_newsletter; $email = $destinatario->email; if (empty($email) || empty($abilita_newsletter) || !v::email()->validate($email)) { return null; diff --git a/plugins/referenti/actions.php b/plugins/referenti/actions.php index dbeda2089..665a362f5 100755 --- a/plugins/referenti/actions.php +++ b/plugins/referenti/actions.php @@ -46,6 +46,8 @@ switch ($operazione) { break; case 'updatereferente': + $opt_out_newsletter = post('disable_newsletter'); + $dbo->update('an_referenti', [ 'idanagrafica' => $id_parent, 'nome' => post('nome'), @@ -53,6 +55,8 @@ switch ($operazione) { 'telefono' => post('telefono'), 'email' => post('email'), 'idsede' => post('idsede'), + + 'enable_newsletter' => empty($opt_out_newsletter), ], ['id' => $id_record]); flash()->info(tr('Salvataggio completato!')); diff --git a/plugins/referenti/add.php b/plugins/referenti/add.php index d2e9cf51f..15b7083f3 100755 --- a/plugins/referenti/add.php +++ b/plugins/referenti/add.php @@ -49,9 +49,13 @@ echo '
-
+
{[ "type": "select", "label": "'.tr('Sede').'", "name": "idsede", "values": "query=SELECT 0 AS id, \'Sede legale\' AS descrizione UNION SELECT id, CONCAT_WS(\' - \', nomesede, citta) AS descrizione FROM an_sedi WHERE idanagrafica='.$id_parent.'", "value": "0", "required": 1 ]}
+ +
+ {[ "type": "checkbox", "label": "'.tr('Opt-out per newsletter').'", "name": "disable_newsletter", "id": "disable_newsletter_m", "value": "0" ]} +
diff --git a/plugins/referenti/edit.php b/plugins/referenti/edit.php index 8b58fd5ae..ea04449a9 100755 --- a/plugins/referenti/edit.php +++ b/plugins/referenti/edit.php @@ -48,9 +48,13 @@ echo '
-
+
{[ "type": "select", "label": "'.tr('Sede').'", "name": "idsede", "values": "query=SELECT 0 AS id, \'Sede legale\' AS descrizione UNION SELECT id, CONCAT_WS(\' - \', nomesede, citta) AS descrizione FROM an_sedi WHERE idanagrafica='.$id_parent.'", "value" : "$idsede$", "required": 1 ]}
+ +
+ {[ "type": "checkbox", "label": "'.tr('Opt-out per newsletter').'", "name": "disable_newsletter", "id": "disable_newsletter_m", "value": "'.empty($record['enable_newsletter']).'" ]} +
diff --git a/plugins/sedi/actions.php b/plugins/sedi/actions.php index ff5f30723..08a8a7358 100755 --- a/plugins/sedi/actions.php +++ b/plugins/sedi/actions.php @@ -53,6 +53,8 @@ switch ($operazione) { break; case 'updatesede': + $opt_out_newsletter = post('disable_newsletter'); + $dbo->update('an_sedi', [ 'nomesede' => post('nomesede'), 'indirizzo' => post('indirizzo'), @@ -73,6 +75,8 @@ switch ($operazione) { 'gaddress' => post('gaddress'), 'lat' => post('lat'), 'lng' => post('lng'), + + 'enable_newsletter' => empty($opt_out_newsletter), ], ['id' => $id_record]); flash()->info(tr('Salvataggio completato!')); diff --git a/plugins/sedi/edit.php b/plugins/sedi/edit.php index 9c25607de..8b1e555f4 100755 --- a/plugins/sedi/edit.php +++ b/plugins/sedi/edit.php @@ -95,10 +95,15 @@ echo ' {[ "type": "text", "label": "'.tr('Indirizzo email').'", "name": "email", "value": "$email$" ]}
-
+
+ {[ "type": "checkbox", "label": "'.tr('Opt-out per newsletter').'", "name": "disable_newsletter", "id": "disable_newsletter_m", "value": "'.empty($record['enable_newsletter']).'" ]} +
+ +
{[ "type": "select", "label": "'.tr('Zona').'", "name": "idzona", "ajax-source": "zone", "value": "$idzona$", "placeholder": "'.tr('Nessuna zona').'", "icon-after": "add|'.Modules::get('Zone')['id'].'" ]}
+
{[ "type": "textarea", "label": "'.tr('Note').'", "name": "note", "value": "$note$" ]} diff --git a/update/2_4_26.sql b/update/2_4_26.sql index 72f202a11..81c7ba69e 100644 --- a/update/2_4_26.sql +++ b/update/2_4_26.sql @@ -127,3 +127,8 @@ CREATE TABLE IF NOT EXISTS `zz_oauth2` ( ALTER TABLE `em_accounts` ADD `id_oauth2` INT(11) DEFAULT NULL, ADD FOREIGN KEY (`id_oauth2`) REFERENCES `zz_oauth2`(`id`); + +-- Aggiunta opt-out Newsletter per Referenti e Sedi +ALTER TABLE `an_referenti` ADD `enable_newsletter` BOOLEAN DEFAULT TRUE; +ALTER TABLE `an_sedi` ADD `enable_newsletter` BOOLEAN DEFAULT TRUE; +