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

Correzione gestione email

This commit is contained in:
Thomas Zilio
2019-08-29 10:25:14 +02:00
parent 1eb60486fb
commit d76bdecc14
34 changed files with 308 additions and 242 deletions

View File

@ -2,11 +2,11 @@
include_once __DIR__.'/core.php'; include_once __DIR__.'/core.php';
use Models\MailTemplate;
use Models\Note; use Models\Note;
use Models\OperationLog; use Models\OperationLog;
use Modules\Checklists\Check; use Modules\Checklists\Check;
use Modules\Checklists\Checklist; use Modules\Checklists\Checklist;
use Modules\Emails\Template;
if (empty($structure) || empty($structure['enabled'])) { if (empty($structure) || empty($structure['enabled'])) {
die(tr('Accesso negato')); die(tr('Accesso negato'));
@ -207,12 +207,11 @@ elseif (filter('op') == 'sort_checks') {
// Inizializzazione email // Inizializzazione email
elseif (post('op') == 'send-email') { elseif (post('op') == 'send-email') {
$template = MailTemplate::find(post('template')); $template = Template::find(post('template'));
$mail = \Models\Mail::build($user, $template, $id_record); $mail = \Modules\Emails\Mail::build($user, $template, $id_record);
// Rimozione allegati predefiniti // Rimozione allegati predefiniti
$mail->resetAttachments();
$mail->resetPrints(); $mail->resetPrints();
// Destinatari // Destinatari
@ -236,9 +235,9 @@ elseif (post('op') == 'send-email') {
} }
// Allegati originali // Allegati originali
$files = post('attachments'); $files = post('uploads');
foreach ($files as $file) { foreach ($files as $file) {
$mail->addAttachment($file); $mail->addUpload($file);
} }
$mail->save(); $mail->save();

View File

@ -5,7 +5,6 @@
* *
* @since 2.3 * @since 2.3
*/ */
use Models\OperationLog; use Models\OperationLog;
/** /**

View File

@ -1,10 +1,10 @@
<?php <?php
use Models\MailTemplate; use Modules\Emails\Template;
include_once __DIR__.'/core.php'; include_once __DIR__.'/core.php';
$template = MailTemplate::find(get('id')); $template = Template::find(get('id'));
$module = $template->module; $module = $template->module;
$smtp = $template->account; $smtp = $template->account;
@ -81,7 +81,7 @@ echo '
</div>'; </div>';
// Stampe // Stampe
$selected_prints = $dbo->fetchArray('SELECT id_print FROM em_template_print WHERE id_email = '.prepare($template['id'])); $selected_prints = $dbo->fetchArray('SELECT id_print FROM em_print_template WHERE id_template = '.prepare($template['id']));
$selected = array_column($selected_prints, 'id_print'); $selected = array_column($selected_prints, 'id_print');
echo ' echo '
@ -91,17 +91,17 @@ echo '
{[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).' AND enabled=1" ]} {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).' AND enabled=1" ]}
</div>'; </div>';
$attachments = []; $uploads = [];
if ($template['name'] == 'Fattura Elettronica') { if ($template['name'] == 'Fattura Elettronica') {
$attachments = $dbo->fetchArray('SELECT id FROM zz_files WHERE id_module = '.prepare($module['id']).' AND id_record = '.prepare($id_record).' AND category = \'Fattura Elettronica\''); $uploads = $dbo->fetchArray('SELECT id FROM zz_files WHERE id_module = '.prepare($module['id']).' AND id_record = '.prepare($id_record).' AND category = \'Fattura Elettronica\'');
$attachments = array_column($attachments, 'id'); $uploads = array_column($uploads, 'id');
} }
// Allegati // Allegati
echo ' echo '
<div class="col-md-6"> <div class="col-md-6">
{[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "attachments[]", "value": "'.implode(',', $attachments).'", "values": "query=SELECT id, name AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)." UNION SELECT id, CONCAT(name, ' (Azienda)') AS text FROM zz_files WHERE id_module = ".prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')\" ]} {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "values": "query=SELECT id, name AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)." UNION SELECT id, CONCAT(name, ' (Azienda)') AS text FROM zz_files WHERE id_module = ".prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')\" ]}
</div> </div>
</div>"; </div>";

View File

@ -7,7 +7,7 @@ switch (post('op')) {
$dbo->insert('em_templates', [ $dbo->insert('em_templates', [
'name' => post('name'), 'name' => post('name'),
'id_module' => post('module'), 'id_module' => post('module'),
'id_smtp' => post('smtp'), 'id_account' => post('smtp'),
'subject' => post('subject'), 'subject' => post('subject'),
]); ]);
@ -20,7 +20,7 @@ switch (post('op')) {
case 'update': case 'update':
$dbo->update('em_templates', [ $dbo->update('em_templates', [
'name' => post('name'), 'name' => post('name'),
'id_smtp' => post('smtp'), 'id_account' => post('smtp'),
'icon' => post('icon'), 'icon' => post('icon'),
'subject' => post('subject'), 'subject' => post('subject'),
'reply_to' => post('reply_to'), 'reply_to' => post('reply_to'),
@ -30,7 +30,7 @@ switch (post('op')) {
'read_notify' => post('read_notify'), 'read_notify' => post('read_notify'),
], ['id' => $id_record]); ], ['id' => $id_record]);
$dbo->sync('em_template_print', ['id_email' => $id_record], ['id_print' => (array) post('prints')]); $dbo->sync('em_print_template', ['id_template' => $id_record], ['id_print' => (array) post('prints')]);
flash()->info(tr('Informazioni salvate correttamente!')); flash()->info(tr('Informazioni salvate correttamente!'));

View File

@ -25,7 +25,7 @@ include_once __DIR__.'/../../core.php';
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
{[ "type": "select", "label": "<?php echo tr('Indirizzo email'); ?>", "name": "smtp", "value": "$id_smtp$", "ajax-source": "smtp" ]} {[ "type": "select", "label": "<?php echo tr('Indirizzo email'); ?>", "name": "smtp", "value": "$id_account$", "ajax-source": "smtp" ]}
</div> </div>
</div> </div>

View File

@ -26,7 +26,7 @@ include_once __DIR__.'/../../core.php';
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
{[ "type": "select", "label": "<?php echo tr('Indirizzo email'); ?>", "name": "smtp", "value": "$id_smtp$", "ajax-source": "smtp" ]} {[ "type": "select", "label": "<?php echo tr('Indirizzo email'); ?>", "name": "smtp", "value": "$id_account$", "ajax-source": "smtp" ]}
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@ -62,7 +62,7 @@ include_once __DIR__.'/../../core.php';
<?php <?php
// Stampe // Stampe
$selected_prints = $dbo->fetchArray('SELECT id_print FROM em_template_print WHERE id_email = '.prepare($id_record)); $selected_prints = $dbo->fetchArray('SELECT id_print FROM em_print_template WHERE id_template = '.prepare($id_record));
$selected = array_column($selected_prints, 'id_print'); $selected = array_column($selected_prints, 'id_print');
echo ' echo '

View File

@ -1,5 +1,7 @@
<?php <?php
include_once __DIR__.'/../../core.php';
if (isset($id_record)) { if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM em_templates WHERE id='.prepare($id_record).' AND deleted_at IS NULL'); $record = $dbo->fetchOne('SELECT * FROM em_templates WHERE id='.prepare($id_record).' AND deleted_at IS NULL');
} }

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Models; namespace Modules\Emails;
use Common\Model; use Common\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Traits\StoreTrait; use Traits\StoreTrait;
class MailAccount extends Model class Account extends Model
{ {
use StoreTrait; use StoreTrait;
use SoftDeletes; use SoftDeletes;
@ -17,6 +17,6 @@ class MailAccount extends Model
public function templates() public function templates()
{ {
return $this->hasMany(MailTemplate::class, 'id_smtp'); return $this->hasMany(Template::class, 'id_account');
} }
} }

View File

@ -3,15 +3,13 @@
namespace Modules\Emails; namespace Modules\Emails;
use Hooks\Manager; use Hooks\Manager;
use Models\Mail;
use Models\MailAccount;
use Notifications\EmailNotification; use Notifications\EmailNotification;
class EmailHook extends Manager class EmailHook extends Manager
{ {
public function execute() public function execute()
{ {
$accounts = MailAccount::all(); $accounts = Account::all();
$diff = date('Y-m-d', strtotime('-4 hours')); $diff = date('Y-m-d', strtotime('-4 hours'));
$list = []; $list = [];

View File

@ -1,19 +1,17 @@
<?php <?php
namespace Models; namespace Modules\Emails;
use Common\Model; use Common\Model;
use Models\PrintTemplate;
use Models\Upload;
use Models\User;
use Modules\Newsletter\Newsletter; use Modules\Newsletter\Newsletter;
class Mail extends Model class Mail extends Model
{ {
protected $table = 'em_emails'; protected $table = 'em_emails';
protected $receivers = null;
protected $attachments = null;
protected $prints = null;
protected $options = null; protected $options = null;
public static function build(User $user, $template = null, $id_record = null, $account = null) public static function build(User $user, $template = null, $id_record = null, $account = null)
@ -22,9 +20,15 @@ class Mail extends Model
$model->created_by = $user->id; $model->created_by = $user->id;
$model->id_template = $template->id; if (!empty($template)) {
$model->id_template = $template->id;
$model->id_account = $template->account->id;
}
$model->id_record = $id_record; $model->id_record = $id_record;
$model->save();
if (!empty($template)) { if (!empty($template)) {
$model->resetFromTemplate(); $model->resetFromTemplate();
} }
@ -43,18 +47,9 @@ class Mail extends Model
* *
* @param string $file_id * @param string $file_id
*/ */
public function addAttachment($file_id) public function addUpload($file_id, $name = null)
{ {
if (!isset($this->attachments)) { $this->uploads()->attach($file_id, ['id_email' => $this->id, 'name' => $name]);
$this->attachments = [];
}
$this->attachments[] = $file_id;
}
public function resetAttachments()
{
$this->attachments = [];
} }
/** /**
@ -65,25 +60,16 @@ class Mail extends Model
*/ */
public function addPrint($print_id, $name = null) public function addPrint($print_id, $name = null)
{ {
if (!isset($this->prints)) { $this->prints()->attach($print_id, ['id_email' => $this->id, 'name' => $name]);
$this->prints = [];
}
$print = PrintTemplate::find($print_id);
if (empty($name)) {
$name = $print['title'].'.pdf';
}
$this->prints[] = [
'id' => $print['id'],
'name' => $name,
];
} }
public function resetPrints() public function resetPrints()
{ {
$this->prints = []; $prints = $this->prints;
foreach ($prints as $print) {
$this->prints()->detach($print->id, ['id_email' => $this->id]);
}
} }
/** /**
@ -98,33 +84,16 @@ class Mail extends Model
return; return;
} }
if (!isset($this->receivers)) {
$this->receivers = [];
}
$list = explode(';', $value); $list = explode(';', $value);
foreach ($list as $element) { foreach ($list as $address) {
$this->receivers[] = [ if (!empty($address)) {
'email' => $element, $receiver = Receiver::build($this, $address, $type);
'type' => $type, }
];
} }
} }
public function save(array $options = []) public function save(array $options = [])
{ {
if (isset($this->receivers)) {
$this->setReceiversAttribute($this->receivers);
}
if (isset($this->attachments)) {
$this->setAttachmentsAttribute($this->attachments);
}
if (isset($this->prints)) {
$this->setPrintsAttribute($this->prints);
}
if (isset($this->options)) { if (isset($this->options)) {
$this->setOptionsAttribute($this->options); $this->setOptionsAttribute($this->options);
} }
@ -139,36 +108,6 @@ class Mail extends Model
// Attributi Eloquent // Attributi Eloquent
public function setReceiversAttribute($value)
{
$this->attributes['receivers'] = json_encode($value);
}
public function getReceiversAttribute()
{
return json_decode($this->attributes['receivers'], true);
}
public function setAttachmentsAttribute($value)
{
$this->attributes['attachments'] = json_encode($value);
}
public function getAttachmentsAttribute()
{
return json_decode($this->attributes['attachments'], true);
}
public function setPrintsAttribute($value)
{
$this->attributes['prints'] = json_encode($value);
}
public function getPrintsAttribute()
{
return json_decode($this->attributes['prints'], true);
}
public function setOptionsAttribute($value) public function setOptionsAttribute($value)
{ {
$this->attributes['options'] = json_encode($value); $this->attributes['options'] = json_encode($value);
@ -189,7 +128,17 @@ class Mail extends Model
return $this->options['read-notify']; return $this->options['read-notify'];
} }
public function setSubjecyAttribute($value) /**
* Imposta il titolo della notifica.
*
* @param bool $value
*/
public function setReadNotifyAttribute($value)
{
$this->options['read-notify'] = boolval($value);
}
public function setSubjectAttribute($value)
{ {
if (isset($this->template)) { if (isset($this->template)) {
$module = $this->template->module; $module = $this->template->module;
@ -211,26 +160,16 @@ class Mail extends Model
$this->attributes['content'] = $value; $this->attributes['content'] = $value;
} }
/**
* Imposta il titolo della notifica.
*
* @param bool $value
*/
public function setReadNotifyAttribute($value)
{
$this->options['read-notify'] = boolval($value);
}
/* Relazioni Eloquent */ /* Relazioni Eloquent */
public function account() public function account()
{ {
return $this->belongsTo(MailAccount::class, 'id_account')->withTrashed(); return $this->belongsTo(Account::class, 'id_account')->withTrashed();
} }
public function template() public function template()
{ {
return $this->belongsTo(MailTemplate::class, 'id_template')->withTrashed(); return $this->belongsTo(Template::class, 'id_template')->withTrashed();
} }
public function user() public function user()
@ -240,7 +179,22 @@ class Mail extends Model
public function newsletter() public function newsletter()
{ {
return $this->belongsTo(Newsletter::class, 'id_campaign'); return $this->belongsTo(Newsletter::class, 'id_newsletter');
}
public function receivers()
{
return $this->hasMany(Receiver::class, 'id_email');
}
public function uploads()
{
return $this->belongsToMany(Upload::class, 'em_email_upload', 'id_email', 'id_file')->withPivot('name');
}
public function prints()
{
return $this->belongsToMany(PrintTemplate::class, 'em_email_print', 'id_email', 'id_print')->withPivot('name');
} }
protected function resetFromTemplate() protected function resetFromTemplate()
@ -270,9 +224,9 @@ class Mail extends Model
} }
// Incluesione stampe predefinite // Incluesione stampe predefinite
$prints = database()->fetchArray('SELECT id_print FROM em_template_print WHERE id_email = '.prepare($template['id'])); $prints = $template->prints;
foreach ($prints as $print) { foreach ($prints as $print) {
$this->addPrint($print['id_print']); $this->addPrint($print['id']);
} }
} }
} }

View File

@ -0,0 +1,29 @@
<?php
namespace Modules\Emails;
use Common\Model;
class Receiver extends Model
{
protected $table = 'em_email_receiver';
/* Relazioni Eloquent */
public static function build(Mail $mail, $address, $type = null)
{
$model = parent::build();
$model->email()->associate($mail);
$model->address = $address;
$model->type = $type ?: 'a';
$model->save();
}
public function email()
{
return $this->belongsTo(Mail::class, 'id_email');
}
}

View File

@ -1,12 +1,14 @@
<?php <?php
namespace Models; namespace Modules\Emails;
use Common\Model; use Common\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Models\Module;
use Models\PrintTemplate;
use Traits\StoreTrait; use Traits\StoreTrait;
class MailTemplate extends Model class Template extends Model
{ {
use StoreTrait; use StoreTrait;
use SoftDeletes; use SoftDeletes;
@ -32,6 +34,11 @@ class MailTemplate extends Model
public function account() public function account()
{ {
return $this->belongsTo(MailAccount::class, 'id_smtp')->withTrashed(); return $this->belongsTo(Account::class, 'id_account')->withTrashed();
}
public function prints()
{
return $this->belongsToMany(PrintTemplate::class, 'em_print_template', 'id_template', 'id_print');
} }
} }

View File

@ -141,7 +141,7 @@ switch (post('op')) {
if ($result) { if ($result) {
++$added; ++$added;
//operationLog('export-xml-bulk', ['id_record' => $r['id']]); //operationLog('export-xml-bulk', ['id_record' => $r['id']]);
} else { } else {
$failed[] = $fattura->numero_esterno; $failed[] = $fattura->numero_esterno;
} }

View File

@ -7,7 +7,7 @@ $r = $dbo->fetchOne('SELECT co_documenti.*,
an_anagrafiche.pec, an_anagrafiche.pec,
an_anagrafiche.ragione_sociale, an_anagrafiche.ragione_sociale,
co_tipidocumento.descrizione AS tipo_documento, co_tipidocumento.descrizione AS tipo_documento,
(SELECT pec FROM em_accounts WHERE em_accounts.id='.prepare($template['id_smtp']).') AS is_pec (SELECT pec FROM em_accounts WHERE em_accounts.id='.prepare($template['id_account']).') AS is_pec
FROM co_documenti FROM co_documenti
INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica
INNER JOIN co_tipidocumento ON co_tipidocumento.id=co_documenti.idtipodocumento INNER JOIN co_tipidocumento ON co_tipidocumento.id=co_documenti.idtipodocumento

View File

@ -2,10 +2,10 @@
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
use Models\Mail;
use Models\MailTemplate;
use Modules\Anagrafiche\Anagrafica; use Modules\Anagrafiche\Anagrafica;
use Modules\Articoli\Articolo as ArticoloOriginale; use Modules\Articoli\Articolo as ArticoloOriginale;
use Modules\Emails\Mail;
use Modules\Emails\Template;
use Modules\Interventi\Components\Articolo; use Modules\Interventi\Components\Articolo;
use Modules\Interventi\Components\Riga; use Modules\Interventi\Components\Riga;
use Modules\Interventi\Components\Sconto; use Modules\Interventi\Components\Sconto;
@ -51,7 +51,7 @@ switch (post('op')) {
// Notifica chiusura intervento // Notifica chiusura intervento
$stato = $dbo->selectOne('in_statiintervento', '*', ['idstatointervento' => post('idstatointervento')]); $stato = $dbo->selectOne('in_statiintervento', '*', ['idstatointervento' => post('idstatointervento')]);
if (!empty($stato['notifica']) && !empty($stato['destinatari']) && $stato['idstatointervento'] != $record['idstatointervento']) { if (!empty($stato['notifica']) && !empty($stato['destinatari']) && $stato['idstatointervento'] != $record['idstatointervento']) {
$template = MailTemplate::find($stato['id_email']); $template = Template::find($stato['id_email']);
$mail = Mail::build(auth()->getUser(), $template, $id_record); $mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($stato['destinatari']); $mail->addReceiver($stato['destinatari']);
@ -477,7 +477,7 @@ switch (post('op')) {
$stato = $dbo->selectOne('in_statiintervento', '*', ['descrizione' => 'Completato']); $stato = $dbo->selectOne('in_statiintervento', '*', ['descrizione' => 'Completato']);
// Notifica chiusura intervento // Notifica chiusura intervento
if (!empty($stato['notifica']) && !empty($stato['destinatari'])) { if (!empty($stato['notifica']) && !empty($stato['destinatari'])) {
$template = MailTemplate::find($stato['id_email']); $template = Template::find($stato['id_email']);
$mail = Mail::build(auth()->getUser(), $template, $id_record); $mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($stato['destinatari']); $mail->addReceiver($stato['destinatari']);
@ -521,7 +521,7 @@ switch (post('op')) {
// Notifica rimozione dell' intervento al tecnico // Notifica rimozione dell' intervento al tecnico
if (!empty($tecnico['email'])) { if (!empty($tecnico['email'])) {
$template = MailTemplate::get('Notifica rimozione intervento'); $template = Template::get('Notifica rimozione intervento');
$mail = Mail::build(auth()->getUser(), $template, $id_record); $mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($tecnico['email']); $mail->addReceiver($tecnico['email']);

View File

@ -2,9 +2,9 @@
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
use Models\Mail;
use Models\MailTemplate;
use Modules\Anagrafiche\Anagrafica; use Modules\Anagrafiche\Anagrafica;
use Modules\Emails\Mail;
use Modules\Emails\Template;
use Modules\Fatture\Components\Descrizione; use Modules\Fatture\Components\Descrizione;
use Modules\Fatture\Components\Riga; use Modules\Fatture\Components\Riga;
use Modules\Fatture\Fattura; use Modules\Fatture\Fattura;
@ -63,7 +63,7 @@ function add_tecnico($idintervento, $idtecnico, $inizio, $fine, $idcontratto = n
// Notifica nuovo intervento al tecnico // Notifica nuovo intervento al tecnico
if (!empty($tecnico['email'])) { if (!empty($tecnico['email'])) {
$template = MailTemplate::get('Notifica intervento'); $template = Template::get('Notifica intervento');
$mail = Mail::build(auth()->getUser(), $template, $idintervento); $mail = Mail::build(auth()->getUser(), $template, $idintervento);
$mail->addReceiver($anagrafica['email']); $mail->addReceiver($anagrafica['email']);

View File

@ -1,13 +1,13 @@
<?php <?php
use Models\MailTemplate; use Modules\Emails\Template;
use Modules\Newsletter\Newsletter; use Modules\Newsletter\Newsletter;
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
switch (filter('op')) { switch (filter('op')) {
case 'add': case 'add':
$template = MailTemplate::find(filter('id_template')); $template = Template::find(filter('id_template'));
$newsletter = Newsletter::build($user, $template, filter('name')); $newsletter = Newsletter::build($user, $template, filter('name'));
$id_record = $newsletter->id; $id_record = $newsletter->id;
@ -48,16 +48,16 @@ switch (filter('op')) {
continue; continue;
} }
$mail = \Models\Mail::build($user, $template, $anagrafica->id); $mail = \Modules\Emails\Mail::build($user, $template, $anagrafica->id);
$mail->addReceiver($anagrafica['email']); $mail->addReceiver($anagrafica['email']);
$mail->subject = $newsletter->subject; $mail->subject = $newsletter->subject;
$mail->content = $newsletter->content; $mail->content = $newsletter->content;
$mail->id_campaign = $newsletter->id; $mail->id_newsletter = $newsletter->id;
foreach ($uploads as $upload) { foreach ($uploads as $upload) {
$mail->addAttachment($upload); $mail->addUpload($upload);
} }
$mail->save(); $mail->save();

View File

@ -1,6 +1,6 @@
<?php <?php
use Models\Mail; use Modules\Emails\Mail;
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';

View File

@ -4,11 +4,11 @@ namespace Modules\Newsletter;
use Common\Model; use Common\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Models\Mail;
use Models\MailAccount;
use Models\MailTemplate;
use Models\User; use Models\User;
use Modules\Anagrafiche\Anagrafica; use Modules\Anagrafiche\Anagrafica;
use Modules\Emails\Account;
use Modules\Emails\Mail;
use Modules\Emails\Template;
use Traits\RecordTrait; use Traits\RecordTrait;
class Newsletter extends Model class Newsletter extends Model
@ -16,9 +16,9 @@ class Newsletter extends Model
use SoftDeletes; use SoftDeletes;
use RecordTrait; use RecordTrait;
protected $table = 'em_campaigns'; protected $table = 'em_newsletters';
public static function build(User $user, MailTemplate $template, $name) public static function build(User $user, Template $template, $name)
{ {
$model = parent::build(); $model = parent::build();
@ -67,22 +67,22 @@ class Newsletter extends Model
public function anagrafiche() public function anagrafiche()
{ {
return $this->belongsToMany(Anagrafica::class, 'em_campaign_anagrafica', 'id_campaign', 'id_anagrafica')->withPivot('id_email'); return $this->belongsToMany(Anagrafica::class, 'em_newsletter_anagrafica', 'id_newsletter', 'id_anagrafica')->withPivot('id_email');
} }
public function emails() public function emails()
{ {
return $this->hasMany(Mail::class, 'id_campaign'); return $this->hasMany(Mail::class, 'id_newsletter');
} }
public function account() public function account()
{ {
return $this->belongsTo(MailAccount::class, 'id_account'); return $this->belongsTo(Account::class, 'id_account');
} }
public function template() public function template()
{ {
return $this->belongsTo(MailTemplate::class, 'id_template'); return $this->belongsTo(Template::class, 'id_template');
} }
public function user() public function user()

View File

@ -5,7 +5,7 @@ $r = $dbo->fetchOne('SELECT co_scadenziario.*, co_documenti.*,
an_anagrafiche.pec, an_anagrafiche.pec,
an_anagrafiche.ragione_sociale, an_anagrafiche.ragione_sociale,
co_scadenziario.da_pagare - co_scadenziario.pagato AS totale, co_scadenziario.da_pagare - co_scadenziario.pagato AS totale,
(SELECT pec FROM em_accounts WHERE em_accounts.id='.prepare($template['id_smtp']).') AS is_pec, (SELECT pec FROM em_accounts WHERE em_accounts.id='.prepare($template['id_account']).') AS is_pec,
(SELECT descrizione FROM co_pagamenti WHERE co_pagamenti.id = co_documenti.idpagamento) AS pagamento (SELECT descrizione FROM co_pagamenti WHERE co_pagamenti.id = co_documenti.idpagamento) AS pagamento
FROM co_scadenziario FROM co_scadenziario
INNER JOIN co_documenti ON co_documenti.id = co_scadenziario.iddocumento INNER JOIN co_documenti ON co_documenti.id = co_scadenziario.iddocumento

View File

@ -82,7 +82,7 @@ include_once __DIR__.'/../../core.php';
<?php <?php
// Collegamenti diretti // Collegamenti diretti
// Template email collegati a questo account // Template email collegati a questo account
$elementi = $dbo->fetchArray('SELECT `id`, `name` FROM `em_templates` WHERE `id_smtp` = '.prepare($id_record)); $elementi = $dbo->fetchArray('SELECT `id`, `name` FROM `em_templates` WHERE `id_account` = '.prepare($id_record));
if (!empty($elementi)) { if (!empty($elementi)) {
echo ' echo '

View File

@ -0,0 +1,38 @@
<?php
include_once __DIR__.'/../../core.php';
echo '
<!-- DATI -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">'.tr('Informazioni').'</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Template email').'", "name": "id_template", "values": "query=SELECT id, name AS descrizione FROM em_templates", "required": 1, "value": "$id_template$", "disabled": 1 ]}
</div>
<div class="col-md-4">
{[ "type": "span", "label": "'.tr('Data di invio').'", "name": "sent_at", "value": "$sent_at$" ]}
</div>
<div class="col-md-4">
{[ "type": "span", "label": "'.tr('Ultimo tentativo').'", "name": "failed_at", "value": "$failed_at$" ]}
</div>
</div>
</div>
</div>
<h4>'.tr('Oggetto').'</h4>
<div class="well">
'.$mail->subject.'
</div>
<h4>'.tr('Contenuto').'</h4>
<div class="well">
'.$mail->content.'
</div>';

View File

@ -0,0 +1,11 @@
<?php
include_once __DIR__.'/../../core.php';
use Modules\Emails\Mail;
if (isset($id_record)) {
$mail = Mail::find($id_record);
$record = $mail->toArray();
}

View File

@ -3,9 +3,9 @@
$skip_permissions = true; $skip_permissions = true;
include_once __DIR__.'/core.php'; include_once __DIR__.'/core.php';
use Models\Mail;
use Models\MailTemplate;
use Models\User; use Models\User;
use Modules\Emails\Mail;
use Modules\Emails\Template;
use Notifications\EmailNotification; use Notifications\EmailNotification;
$token = get('reset_token'); $token = get('reset_token');
@ -26,7 +26,7 @@ switch (post('op')) {
$utente->reset_token = secure_random_string(); $utente->reset_token = secure_random_string();
$utente->save(); $utente->save();
$template = MailTemplate::get('Reset password'); $template = Template::get('Reset password');
$mail = Mail::build($user, $template, $utente->id); $mail = Mail::build($user, $template, $utente->id);
$mail->addReceiver($utente->email); $mail->addReceiver($utente->email);

View File

@ -21,7 +21,9 @@ class MessageHandler extends AbstractProcessingHandler
if (auth()->check()) { if (auth()->check()) {
$message .= ' $message .= '
'.tr('Se il problema persiste siete pregati di chiedere assistenza tramite la sezione Bug').'. <a href="'.ROOTDIR.'/bug.php"><i class="fa fa-external-link"></i></a>'; '.tr('Se il problema persiste siete pregati di chiedere assistenza tramite il forum apposito (_LINK_FORUM_)', [
'_LINK_FORUM_' => '<a href="https://forum.openstamanager.com/">https://forum.openstamanager.com/</a>',
]).'.</a>';
if (auth()->isAdmin()) { if (auth()->isAdmin()) {
$message .= ' $message .= '

View File

@ -2,7 +2,7 @@
namespace HTMLBuilder\Manager; namespace HTMLBuilder\Manager;
use Models\MailTemplate; use Modules\Emails\Template;
/** /**
* @since 2.4 * @since 2.4
@ -38,7 +38,7 @@ class ButtonManager implements ManagerInterface
'icon' => $print['icon'], 'icon' => $print['icon'],
]; ];
} else { } else {
$template = MailTemplate::find($options['id']); $template = Template::find($options['id']);
$result = [ $result = [
'link' => ROOTDIR.'/mail.php?id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id='.$options['id'], 'link' => ROOTDIR.'/mail.php?id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id='.$options['id'],
@ -87,7 +87,7 @@ class ButtonManager implements ManagerInterface
if ($options['type'] == 'print') { if ($options['type'] == 'print') {
$results = \Prints::getModulePrints($options['id_module']); $results = \Prints::getModulePrints($options['id_module']);
} else { } else {
$results = MailTemplate::where('id_module', $options['id_module'])->get()->toArray(); $results = Template::where('id_module', $options['id_module'])->get()->toArray();
} }
return $results; return $results;

View File

@ -2,9 +2,7 @@
namespace HTMLBuilder\Manager; namespace HTMLBuilder\Manager;
use Models\Mail; use Modules\Emails\Mail;
use Prints;
use Translator;
/** /**
* Gestione allegati. * Gestione allegati.
@ -49,28 +47,24 @@ class EmailManager implements ManagerInterface
<ul>'; <ul>';
foreach ($emails as $operation) { foreach ($emails as $operation) {
$receivers = array_column($operation->receivers, 'email'); $receivers = $operation->receivers->pluck('address')->toArray();
$prints = []; $prints = [];
$list = $operation->prints; $list = $operation->prints;
foreach ($list as $print) { foreach ($list as $print) {
$print = Prints::get($print['id']);
$prints[] = $print['title']; $prints[] = $print['title'];
} }
$attachments = []; $uploads = [];
$list = $operation->attachments; $list = $operation->uploads;
foreach ($list as $attachment) { foreach ($list as $upload) {
$attachment = $database->selectOne('zz_files', '*', ['id' => $attachment]); $uploads[] = $upload['name'];
$attachments[] = $attachment['name'];
} }
$sent = !empty($operation['sent_at']) ? tr('inviata il _DATE_ alle _HOUR_', [ $sent = !empty($operation['sent_at']) ? tr('inviata il _DATE_ alle _HOUR_', [
'_DATE_' => dateFormat($operation['sent_at']), '_DATE_' => dateFormat($operation['sent_at']),
'_HOUR_' => timeFormat($operation['sent_at']), '_HOUR_' => timeFormat($operation['sent_at']),
]) : tr('in coda di invio') ; ]) : tr('in coda di invio');
$result .= ' $result .= '
<li> <li>
@ -86,9 +80,9 @@ class EmailManager implements ManagerInterface
<li><b>'.tr('Stampe').'</b>: '.implode(', ', $prints).'.</li>'; <li><b>'.tr('Stampe').'</b>: '.implode(', ', $prints).'.</li>';
} }
if (!empty($attachments)) { if (!empty($uploads)) {
$result .= ' $result .= '
<li><b>'.tr('Allegati').'</b>: '.implode(', ', $attachments).'.</li>'; <li><b>'.tr('Allegati').'</b>: '.implode(', ', $uploads).'.</li>';
} }
$result .= ' $result .= '

View File

@ -123,9 +123,9 @@ class Module extends Model
return $this->hasMany(PrintTemplate::class, 'id_module'); return $this->hasMany(PrintTemplate::class, 'id_module');
} }
public function mailTemplates() public function Templates()
{ {
return $this->hasMany(MailTemplate::class, 'id_module'); return $this->hasMany(Template::class, 'id_module');
} }
public function views() public function views()

View File

@ -10,11 +10,13 @@ class OperationLog extends Model
protected static $info = []; protected static $info = [];
public static function setInfo($name, $value){ public static function setInfo($name, $value)
{
self::$info[$name] = $value; self::$info[$name] = $value;
} }
public static function getInfo($name){ public static function getInfo($name)
{
return self::$info[$name]; return self::$info[$name];
} }
@ -26,7 +28,7 @@ class OperationLog extends Model
$model = parent::build(); $model = parent::build();
foreach (self::$info as $key => $value){ foreach (self::$info as $key => $value) {
$model->{$key} = $value; $model->{$key} = $value;
} }

View File

@ -2,7 +2,7 @@
namespace Notifications; namespace Notifications;
use Models\MailAccount; use Modules\Emails\Account;
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use Prints; use Prints;
use Uploads; use Uploads;
@ -21,9 +21,9 @@ class EmailNotification extends PHPMailer implements NotificationInterface
$this->CharSet = 'UTF-8'; $this->CharSet = 'UTF-8';
// Configurazione di base // Configurazione di base
$config = MailAccount::find($account); $config = Account::find($account);
if (empty($config)) { if (empty($config)) {
$config = MailAccount::where('predefined', true)->first(); $config = Account::where('predefined', true)->first();
} }
// Preparazione email // Preparazione email
@ -71,7 +71,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface
$this->WordWrap = 78; $this->WordWrap = 78;
} }
public static function build(\Models\Mail $mail, $exceptions = null) public static function build(\Modules\Emails\Mail $mail, $exceptions = null)
{ {
$result = new self($mail->account->id, $exceptions); $result = new self($mail->account->id, $exceptions);
@ -153,7 +153,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface
$this->mail->failed_at = date('Y-m-d H:i:s'); $this->mail->failed_at = date('Y-m-d H:i:s');
} }
$this->mail->save(); //$this->mail->save();
} }
$this->SmtpClose(); $this->SmtpClose();
@ -192,32 +192,6 @@ class EmailNotification extends PHPMailer implements NotificationInterface
return false; return false;
} }
/**
* Restituisce gli allegati della notifica.
*
* @return array
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* Imposta gli allegati della notifica.
*
* @param array $values
*/
public function setAttachments(array $values)
{
$this->attachments = [];
foreach ($values as $value) {
$path = is_array($value) ? $value['path'] : $value;
$name = is_array($value) ? $value['name'] : null;
$this->addAttachment($path, $name);
}
}
/** /**
* Aggiunge un allegato del gestionale alla notifica. * Aggiunge un allegato del gestionale alla notifica.
* *
@ -226,9 +200,8 @@ class EmailNotification extends PHPMailer implements NotificationInterface
public function addUpload($file_id) public function addUpload($file_id)
{ {
$attachment = database()->fetchOne('SELECT * FROM zz_files WHERE id = '.prepare($file_id)); $attachment = database()->fetchOne('SELECT * FROM zz_files WHERE id = '.prepare($file_id));
$this->addAttachment(DOCROOT.'/'.Uploads::getDirectory($attachment['id_module'], $attachment['id_plugin']).'/'.$attachment['filename']);
$this->logs['attachments'][] = $attachment['id']; $this->addAttachment(DOCROOT.'/'.Uploads::getDirectory($attachment['id_module'], $attachment['id_plugin']).'/'.$attachment['filename']);
} }
/** /**
@ -253,8 +226,6 @@ class EmailNotification extends PHPMailer implements NotificationInterface
$name = $name ?: $info['name']; $name = $name ?: $info['name'];
$this->addAttachment($info['path'], $name); $this->addAttachment($info['path'], $name);
$this->logs['prints'][] = $print['id'];
} }
/** /**

View File

@ -269,6 +269,9 @@ class Update
} }
} }
// Normalizzazione di charset e collation
self::normalizeDatabase($database->getDatabaseName());
// Normalizzazione dei campi per l'API // Normalizzazione dei campi per l'API
self::executeScript(DOCROOT.'/update/api.php'); self::executeScript(DOCROOT.'/update/api.php');

View File

@ -1,27 +1,36 @@
<?php <?php
// Correzione zz_operations // Correzione zz_operations
use Models\Mail;
use Models\MailTemplate;
use Models\User; use Models\User;
use Modules\Emails\Mail;
use Modules\Emails\Template;
$database->query('ALTER TABLE `zz_operations` DROP FOREIGN KEY `zz_operations_ibfk_3`'); $database->query('ALTER TABLE `zz_operations` DROP FOREIGN KEY `zz_operations_ibfk_3`');
$logs = $database->fetchArray("SELECT * FROM `zz_operations` WHERE `op` = 'send-email'"); $logs = $database->fetchArray("SELECT * FROM `zz_operations` WHERE `op` = 'send-email'");
foreach ($logs as $log) { foreach ($logs as $log) {
$user = User::find($log['id_utente']); $user = User::find($log['id_utente']);
$template = MailTemplate::find($log['id_email']); $template = Template::find($log['id_email']);
$mail = Mail::build($user, $template, $log['id_record']); $mail = Mail::build($user, $template, $log['id_record']);
$mail->resetPrints();
$options = json_decode($log['options'], true); $options = json_decode($log['options'], true);
$mail->attachments = $options['attachments'] ?: [];
$mail->prints = $options['prints'] ?: [];
foreach ($options['receivers'] as $receiver){ foreach ($options['receivers'] as $receiver) {
$mail->addReceiver($receiver); $mail->addReceiver($receiver);
} }
$mail->created_at = $log['created_at']; foreach ($options['attachments'] as $upload) {
$mail->sent_at = $log['created_at']; $mail->addUpload($upload);
}
foreach ($options['prints'] as $print) {
$mail->addPrint($print);
}
$sent_at = $log['created_at'] ?: date('Y-m-d H:i:s');
$mail->created_at = $sent_at;
$mail->sent_at = $sent_at;
$mail->save(); $mail->save();

View File

@ -318,26 +318,27 @@ ALTER TABLE `mg_articoli` ADD `deleted_at` timestamp NULL DEFAULT NULL;
UPDATE `zz_modules` SET `options` = 'SELECT |select| FROM `mg_articoli` WHERE 1=1 AND `deleted_at` IS NULL HAVING 2=2 ORDER BY `descrizione`' WHERE `name` = 'Articoli'; UPDATE `zz_modules` SET `options` = 'SELECT |select| FROM `mg_articoli` WHERE 1=1 AND `deleted_at` IS NULL HAVING 2=2 ORDER BY `descrizione`' WHERE `name` = 'Articoli';
-- Ampliamento hooks -- Ampliamento hooks
ALTER TABLE `zz_hooks` ADD `processing` BOOLEAN DEFAULT FALSE; ALTER TABLE `zz_hooks` ADD `processing_at` TIMESTAMP NULL DEFAULT NULL, ADD `processing_token` varchar(255);
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Backup', 'Modules\\Backups\\BackupHook', '1 day', (SELECT `id` FROM `zz_modules` WHERE `name` = 'Backup')); INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Backup', 'Modules\\Backups\\BackupHook', '1 day', (SELECT `id` FROM `zz_modules` WHERE `name` = 'Backup'));
-- Miglioramento gestione email -- Miglioramento gestione email
ALTER TABLE `zz_emails` RENAME TO `em_templates`; ALTER TABLE `zz_emails` RENAME TO `em_templates`;
ALTER TABLE `zz_smtps` RENAME TO `em_accounts`; ALTER TABLE `zz_smtps` RENAME TO `em_accounts`;
ALTER TABLE `zz_email_print` RENAME TO `em_template_print`; ALTER TABLE `zz_email_print` RENAME TO `em_print_template`;
UPDATE zz_modules SET options = REPLACE(options, 'zz_emails', 'em_templates'), options2 = REPLACE(options2, 'zz_emails', 'em_templates'); UPDATE zz_modules SET options = REPLACE(options, 'zz_emails', 'em_templates'), options2 = REPLACE(options2, 'zz_emails', 'em_templates');
UPDATE zz_modules SET options = REPLACE(options, 'zz_smtps', 'em_accounts'), options2 = REPLACE(options2, 'zz_smtps', 'em_accounts'); UPDATE zz_modules SET options = REPLACE(options, 'zz_smtps', 'em_accounts'), options2 = REPLACE(options2, 'zz_smtps', 'em_accounts');
UPDATE zz_views SET query = REPLACE(query, 'zz_emails', 'em_templates'); UPDATE zz_views SET query = REPLACE(query, 'zz_emails', 'em_templates');
UPDATE zz_views SET query = REPLACE(query, 'zz_smtps', 'em_accounts'); UPDATE zz_views SET query = REPLACE(query, 'zz_smtps', 'em_accounts');
CREATE TABLE IF NOT EXISTS `em_campaigns` ( CREATE TABLE IF NOT EXISTS `em_newsletters` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`id_template` int(11) NOT NULL, `id_template` int(11) NOT NULL,
`state` varchar(25) NOT NULL, `state` varchar(25) NOT NULL,
`subject` varchar(255) NOT NULL, `subject` varchar(255) NOT NULL,
`content` TEXT NOT NULL, `content` TEXT NOT NULL,
`notes` TEXT,
`created_by` int(11) NOT NULL, `created_by` int(11) NOT NULL,
`completed_at` TIMESTAMP NULL DEFAULT NULL, `completed_at` TIMESTAMP NULL DEFAULT NULL,
`deleted_at` TIMESTAMP NULL DEFAULT NULL, `deleted_at` TIMESTAMP NULL DEFAULT NULL,
@ -350,40 +351,84 @@ CREATE TABLE IF NOT EXISTS `em_emails` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_account` int(11) NOT NULL, `id_account` int(11) NOT NULL,
`id_template` int(11), `id_template` int(11),
`id_campaign` int(11), `id_newsletter` int(11),
`id_record` int(11), `id_record` int(11),
`subject` varchar(255), `subject` varchar(255),
`content` TEXT, `content` TEXT,
`receivers` TEXT,
`attachments` TEXT,
`prints` TEXT,
`options` TEXT, `options` TEXT,
`sent_at` TIMESTAMP NULL DEFAULT NULL, `sent_at` TIMESTAMP NULL DEFAULT NULL,
`failed_at` TIMESTAMP NULL DEFAULT NULL, `failed_at` TIMESTAMP NULL DEFAULT NULL,
`processing_at` TIMESTAMP NULL DEFAULT NULL,
`created_by` int(11) NOT NULL, `created_by` int(11) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
FOREIGN KEY (`id_account`) REFERENCES `em_accounts`(`id`) ON DELETE CASCADE, FOREIGN KEY (`id_account`) REFERENCES `em_accounts`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_template`) REFERENCES `em_templates`(`id`) ON DELETE CASCADE, FOREIGN KEY (`id_template`) REFERENCES `em_templates`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_campaign`) REFERENCES `em_campaigns`(`id`) ON DELETE CASCADE, FOREIGN KEY (`id_newsletter`) REFERENCES `em_newsletters`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`created_by`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE FOREIGN KEY (`created_by`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB; ) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `em_campaign_anagrafica` ( CREATE TABLE IF NOT EXISTS `em_email_receiver` (
`id_campaign` int(11) NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_email` int(11) NOT NULL,
`type` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `em_email_upload` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_email` int(11) NOT NULL,
`id_file` int(11) NOT NULL,
`name` varchar(255),
PRIMARY KEY (`id`),
FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_file`) REFERENCES `zz_files`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `em_email_print` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_email` int(11) NOT NULL,
`id_print` int(11) NOT NULL,
`name` varchar(255),
PRIMARY KEY (`id`),
FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_print`) REFERENCES `zz_prints`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `em_newsletter_anagrafica` (
`id_newsletter` int(11) NOT NULL,
`id_anagrafica` int(11) NOT NULL, `id_anagrafica` int(11) NOT NULL,
`id_email` int(11), `id_email` int(11),
FOREIGN KEY (`id_campaign`) REFERENCES `em_campaigns`(`id`) ON DELETE CASCADE, FOREIGN KEY (`id_newsletter`) REFERENCES `em_newsletters`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_anagrafica`) REFERENCES `an_anagrafiche`(`idanagrafica`) ON DELETE CASCADE, FOREIGN KEY (`id_anagrafica`) REFERENCES `an_anagrafiche`(`idanagrafica`) ON DELETE CASCADE,
FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB; ) ENGINE=InnoDB;
-- Hook per la gestione della coda di invio
ALTER TABLE `zz_hooks` CHANGE `id_module` `id_module` INT(11) NULL; ALTER TABLE `zz_hooks` CHANGE `id_module` `id_module` INT(11) NULL;
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Email', 'Modules\\Emails\\EmailHook', '1 minute', NULL); INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Email', 'Modules\\Emails\\EmailHook', '1 minute', NULL);
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Newsletter', 'Newsletter', 'newsletter', 'SELECT |select| FROM `em_campaigns` WHERE 1=1 AND deleted_at IS NULL HAVING 2=2', '', 'fa fa-newspaper-o ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1'); -- Modulo Newsletter
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Newsletter', 'Newsletter', 'newsletter', 'SELECT |select| FROM `em_newsletters` WHERE 1=1 AND deleted_at IS NULL HAVING 2=2', '', 'fa fa-newspaper-o ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1');
INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`) VALUES INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`) VALUES
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'id', 'id', 1, 0, 0, 1, 0), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'id', 'id', 1, 0, 0, 1, 0),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Nome', 'name', 2, 1, 0, 0, 1), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Nome', 'name', 2, 1, 0, 0, 1),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Template', '(SELECT name FROM em_templates WHERE id = em_campaigns.id_template)', 3, 1, 0, 1, 1), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Template', '(SELECT name FROM em_templates WHERE id = em_newsletters.id_template)', 3, 1, 0, 1, 1),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Completato', 'IF(completed_at IS NULL, ''No'', ''Si'')', 4, 1, 0, 1, 1); ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Completato', 'IF(completed_at IS NULL, ''No'', ''Si'')', 4, 1, 0, 1, 1);
-- Modulo Stato email
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stato email', 'Stato email', 'stato_email', 'SELECT |select| FROM `em_emails` WHERE 1=1 AND (`em_emails`.`created_at` BETWEEN ''|period_start|'' AND ''|period_end|'' OR `em_emails`.`sent_at` IS NULL) HAVING 2=2', '', 'fa fa-spinner ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1');
INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`, `format`) VALUES
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'id', 'id', 1, 0, 0, 1, 0, 0),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Oggetto', 'subject', 2, 1, 0, 0, 1, 0),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Contenuto', 'content', 3, 1, 0, 0, 1, 0),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Template', '(SELECT name FROM em_templates WHERE id = em_emails.id_template)', 3, 1, 0, 1, 1, 0),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Data invio', 'sent_at', 4, 1, 0, 1, 1, 1),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'Ultimo tentativo', 'failed_at', 5, 1, 0, 1, 1, 1),
((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), '_bg_', 'IF(sent_at IS NULL, IF(failed_at IS NULL, ''#CC9837'', ''#CC4D37''), ''#38CD4E'')', 6, 1, 0, 0, 0, 0);
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;

View File

@ -48,12 +48,15 @@ return [
'dt_spedizione', 'dt_spedizione',
'dt_statiddt', 'dt_statiddt',
'dt_tipiddt', 'dt_tipiddt',
'em_template_print', 'em_print_template',
'em_accounts', 'em_accounts',
'em_templates', 'em_templates',
'em_campaigns', 'em_newsletters',
'em_emails', 'em_emails',
'em_campaign_anagrafica', 'em_email_receiver',
'em_email_upload',
'em_email_print',
'em_newsletter_anagrafica',
'fe_causali_pagamento_ritenuta', 'fe_causali_pagamento_ritenuta',
'fe_modalita_pagamento', 'fe_modalita_pagamento',
'fe_natura', 'fe_natura',