1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-06-05 22:09:38 +02:00

Sistema di opt-out da newsletter

This commit is contained in:
Thomas Zilio
2019-08-29 15:09:01 +02:00
parent d7fd612dc9
commit f320cb97d4
7 changed files with 198 additions and 141 deletions

View File

@@ -31,6 +31,9 @@ switch (post('op')) {
$sede->idzona = post('idzona'); $sede->idzona = post('idzona');
$sede->email = post('email'); $sede->email = post('email');
$opt_out_newsletter = post('disable_newsletter');
$sede->enable_newsletter = empty($opt_out_newsletter);
$sede->save(); $sede->save();
// Informazioni sull'anagrafica // Informazioni sull'anagrafica

View File

@@ -87,8 +87,6 @@ if (!$is_cliente) {
<?php <?php
} ?> } ?>
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
{[ "type": "text", "label": "<?php echo tr('Codice anagrafica'); ?>", "name": "codice", "required": 1, "class": "text-center alphanumeric-mask", "value": "$codice$", "maxlength": 20, "validation": "codice" ]} {[ "type": "text", "label": "<?php echo tr('Codice anagrafica'); ?>", "name": "codice", "required": 1, "class": "text-center alphanumeric-mask", "value": "$codice$", "maxlength": 20, "validation": "codice" ]}
@@ -498,6 +496,12 @@ echo '
{[ "type": "textarea", "label": "<?php echo tr('Note'); ?>", "name": "note", "value": "$note$" ]} {[ "type": "textarea", "label": "<?php echo tr('Note'); ?>", "name": "note", "value": "$note$" ]}
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-12">
{[ "type": "checkbox", "label": "<?php echo tr('Opt-out newsletter'); ?>", "name": "disable_newsletter", "value": "<?php echo empty($record['enable_newsletter']); ?>" ]}
</div>
</div>
</div> </div>
</div> </div>
</fieldset> </fieldset>

View File

@@ -0,0 +1,49 @@
<?php
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'anagrafiche_newsletter':
$query = "SELECT an_anagrafiche.idanagrafica AS id, CONCAT_WS('', ragione_sociale, IF(citta !='' OR provincia != '', CONCAT(' (', citta, IF(provincia!='', CONCAT(' ', provincia), ''), ')'), ''), IF(deleted_at IS NULL, '', ' (".tr('eliminata').")')) AS descrizione, `an_tipianagrafiche`.`descrizione` AS optgroup FROM an_anagrafiche INNER JOIN (an_tipianagrafiche_anagrafiche INNER JOIN an_tipianagrafiche ON an_tipianagrafiche_anagrafiche.idtipoanagrafica=an_tipianagrafiche.idtipoanagrafica) ON an_anagrafiche.idanagrafica=an_tipianagrafiche_anagrafiche.idanagrafica |where| ORDER BY `optgroup` ASC, ragione_sociale ASC";
foreach ($elements as $element) {
$filter[] = 'an_anagrafiche.idanagrafica='.prepare($element);
}
if (empty($filter)) {
$where[] = 'deleted_at IS NULL';
$where[] = 'enable_newsletter = 1';
}
if (!empty($search)) {
$search_fields[] = 'ragione_sociale LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'citta LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'provincia LIKE '.prepare('%'.$search.'%');
}
// Aggiunta filtri di ricerca
if (!empty($search_fields)) {
$where[] = '('.implode(' OR ', $search_fields).')';
}
if (!empty($filter)) {
$where[] = '('.implode(' OR ', $filter).')';
}
$query = str_replace('|where|', !empty($where) ? 'WHERE '.implode(' AND ', $where) : '', $query);
$rs = $dbo->fetchArray($query);
foreach ($rs as $r) {
if ($prev != $r['optgroup']) {
$results[] = ['text' => $r['optgroup'], 'children' => []];
$prev = $r['optgroup'];
}
$results[count($results) - 1]['children'][] = [
'id' => $r['id'],
'text' => $r['descrizione'],
'descrizione' => $r['descrizione'],
];
}
break;
}

View File

@@ -82,7 +82,7 @@ echo '
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div class="col-md-9"> <div class="col-md-9">
{[ "type": "select", "label": "'.tr('Destinatari').'", "name": "receivers[]", "ajax-source": "anagrafiche", "multiple": 1 ]} {[ "type": "select", "label": "'.tr('Destinatari').'", "name": "receivers[]", "ajax-source": "anagrafiche_newsletter", "multiple": 1 ]}
</div> </div>
<div class="col-md-3 text-right"> <div class="col-md-3 text-right">

View File

@@ -72,7 +72,7 @@ class Newsletter extends Model
public function emails() public function emails()
{ {
return $this->hasMany(Mail::class, 'id_newsletter'); return $this->belongsToMany(Mail::class, 'em_newsletter_anagrafica', 'id_newsletter', 'id_email')->withPivot('id_anagrafica');
} }
public function account() public function account()

View File

@@ -433,3 +433,4 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`,
ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL; ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL;
ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL; ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL;
ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000; ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;
ALTER TABLE `an_anagrafiche` ADD `enable_newsletter` BOOLEAN DEFAULT TRUE;