Correzione gestione email
This commit is contained in:
parent
1eb60486fb
commit
d76bdecc14
11
actions.php
11
actions.php
|
@ -2,11 +2,11 @@
|
|||
|
||||
include_once __DIR__.'/core.php';
|
||||
|
||||
use Models\MailTemplate;
|
||||
use Models\Note;
|
||||
use Models\OperationLog;
|
||||
use Modules\Checklists\Check;
|
||||
use Modules\Checklists\Checklist;
|
||||
use Modules\Emails\Template;
|
||||
|
||||
if (empty($structure) || empty($structure['enabled'])) {
|
||||
die(tr('Accesso negato'));
|
||||
|
@ -207,12 +207,11 @@ elseif (filter('op') == 'sort_checks') {
|
|||
|
||||
// Inizializzazione 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
|
||||
$mail->resetAttachments();
|
||||
$mail->resetPrints();
|
||||
|
||||
// Destinatari
|
||||
|
@ -236,9 +235,9 @@ elseif (post('op') == 'send-email') {
|
|||
}
|
||||
|
||||
// Allegati originali
|
||||
$files = post('attachments');
|
||||
$files = post('uploads');
|
||||
foreach ($files as $file) {
|
||||
$mail->addAttachment($file);
|
||||
$mail->addUpload($file);
|
||||
}
|
||||
|
||||
$mail->save();
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
|
||||
use Models\OperationLog;
|
||||
|
||||
/**
|
||||
|
|
14
mail.php
14
mail.php
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
use Models\MailTemplate;
|
||||
use Modules\Emails\Template;
|
||||
|
||||
include_once __DIR__.'/core.php';
|
||||
|
||||
$template = MailTemplate::find(get('id'));
|
||||
$template = Template::find(get('id'));
|
||||
$module = $template->module;
|
||||
$smtp = $template->account;
|
||||
|
||||
|
@ -81,7 +81,7 @@ echo '
|
|||
</div>';
|
||||
|
||||
// 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');
|
||||
|
||||
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" ]}
|
||||
</div>';
|
||||
|
||||
$attachments = [];
|
||||
$uploads = [];
|
||||
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\'');
|
||||
$attachments = array_column($attachments, 'id');
|
||||
$uploads = $dbo->fetchArray('SELECT id FROM zz_files WHERE id_module = '.prepare($module['id']).' AND id_record = '.prepare($id_record).' AND category = \'Fattura Elettronica\'');
|
||||
$uploads = array_column($uploads, 'id');
|
||||
}
|
||||
|
||||
// Allegati
|
||||
echo '
|
||||
|
||||
<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>";
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ switch (post('op')) {
|
|||
$dbo->insert('em_templates', [
|
||||
'name' => post('name'),
|
||||
'id_module' => post('module'),
|
||||
'id_smtp' => post('smtp'),
|
||||
'id_account' => post('smtp'),
|
||||
'subject' => post('subject'),
|
||||
]);
|
||||
|
||||
|
@ -20,7 +20,7 @@ switch (post('op')) {
|
|||
case 'update':
|
||||
$dbo->update('em_templates', [
|
||||
'name' => post('name'),
|
||||
'id_smtp' => post('smtp'),
|
||||
'id_account' => post('smtp'),
|
||||
'icon' => post('icon'),
|
||||
'subject' => post('subject'),
|
||||
'reply_to' => post('reply_to'),
|
||||
|
@ -30,7 +30,7 @@ switch (post('op')) {
|
|||
'read_notify' => post('read_notify'),
|
||||
], ['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!'));
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ include_once __DIR__.'/../../core.php';
|
|||
|
||||
<div class="row">
|
||||
<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>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ include_once __DIR__.'/../../core.php';
|
|||
|
||||
<div class="row">
|
||||
<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 class="col-md-4">
|
||||
|
@ -62,7 +62,7 @@ include_once __DIR__.'/../../core.php';
|
|||
<?php
|
||||
|
||||
// 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');
|
||||
|
||||
echo '
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
if (isset($id_record)) {
|
||||
$record = $dbo->fetchOne('SELECT * FROM em_templates WHERE id='.prepare($id_record).' AND deleted_at IS NULL');
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Models;
|
||||
namespace Modules\Emails;
|
||||
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Traits\StoreTrait;
|
||||
|
||||
class MailAccount extends Model
|
||||
class Account extends Model
|
||||
{
|
||||
use StoreTrait;
|
||||
use SoftDeletes;
|
||||
|
@ -17,6 +17,6 @@ class MailAccount extends Model
|
|||
|
||||
public function templates()
|
||||
{
|
||||
return $this->hasMany(MailTemplate::class, 'id_smtp');
|
||||
return $this->hasMany(Template::class, 'id_account');
|
||||
}
|
||||
}
|
|
@ -3,15 +3,13 @@
|
|||
namespace Modules\Emails;
|
||||
|
||||
use Hooks\Manager;
|
||||
use Models\Mail;
|
||||
use Models\MailAccount;
|
||||
use Notifications\EmailNotification;
|
||||
|
||||
class EmailHook extends Manager
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$accounts = MailAccount::all();
|
||||
$accounts = Account::all();
|
||||
$diff = date('Y-m-d', strtotime('-4 hours'));
|
||||
|
||||
$list = [];
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Models;
|
||||
namespace Modules\Emails;
|
||||
|
||||
use Common\Model;
|
||||
use Models\PrintTemplate;
|
||||
use Models\Upload;
|
||||
use Models\User;
|
||||
use Modules\Newsletter\Newsletter;
|
||||
|
||||
class Mail extends Model
|
||||
{
|
||||
protected $table = 'em_emails';
|
||||
|
||||
protected $receivers = null;
|
||||
|
||||
protected $attachments = null;
|
||||
protected $prints = null;
|
||||
|
||||
protected $options = 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->id_template = $template->id;
|
||||
if (!empty($template)) {
|
||||
$model->id_template = $template->id;
|
||||
$model->id_account = $template->account->id;
|
||||
}
|
||||
|
||||
$model->id_record = $id_record;
|
||||
|
||||
$model->save();
|
||||
|
||||
if (!empty($template)) {
|
||||
$model->resetFromTemplate();
|
||||
}
|
||||
|
@ -43,18 +47,9 @@ class Mail extends Model
|
|||
*
|
||||
* @param string $file_id
|
||||
*/
|
||||
public function addAttachment($file_id)
|
||||
public function addUpload($file_id, $name = null)
|
||||
{
|
||||
if (!isset($this->attachments)) {
|
||||
$this->attachments = [];
|
||||
}
|
||||
|
||||
$this->attachments[] = $file_id;
|
||||
}
|
||||
|
||||
public function resetAttachments()
|
||||
{
|
||||
$this->attachments = [];
|
||||
$this->uploads()->attach($file_id, ['id_email' => $this->id, 'name' => $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,25 +60,16 @@ class Mail extends Model
|
|||
*/
|
||||
public function addPrint($print_id, $name = null)
|
||||
{
|
||||
if (!isset($this->prints)) {
|
||||
$this->prints = [];
|
||||
}
|
||||
|
||||
$print = PrintTemplate::find($print_id);
|
||||
|
||||
if (empty($name)) {
|
||||
$name = $print['title'].'.pdf';
|
||||
}
|
||||
|
||||
$this->prints[] = [
|
||||
'id' => $print['id'],
|
||||
'name' => $name,
|
||||
];
|
||||
$this->prints()->attach($print_id, ['id_email' => $this->id, 'name' => $name]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!isset($this->receivers)) {
|
||||
$this->receivers = [];
|
||||
}
|
||||
|
||||
$list = explode(';', $value);
|
||||
foreach ($list as $element) {
|
||||
$this->receivers[] = [
|
||||
'email' => $element,
|
||||
'type' => $type,
|
||||
];
|
||||
foreach ($list as $address) {
|
||||
if (!empty($address)) {
|
||||
$receiver = Receiver::build($this, $address, $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
$this->setOptionsAttribute($this->options);
|
||||
}
|
||||
|
@ -139,36 +108,6 @@ class Mail extends Model
|
|||
|
||||
// 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)
|
||||
{
|
||||
$this->attributes['options'] = json_encode($value);
|
||||
|
@ -189,7 +128,17 @@ class Mail extends Model
|
|||
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)) {
|
||||
$module = $this->template->module;
|
||||
|
@ -211,26 +160,16 @@ class Mail extends Model
|
|||
$this->attributes['content'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta il titolo della notifica.
|
||||
*
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setReadNotifyAttribute($value)
|
||||
{
|
||||
$this->options['read-notify'] = boolval($value);
|
||||
}
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(MailAccount::class, 'id_account')->withTrashed();
|
||||
return $this->belongsTo(Account::class, 'id_account')->withTrashed();
|
||||
}
|
||||
|
||||
public function template()
|
||||
{
|
||||
return $this->belongsTo(MailTemplate::class, 'id_template')->withTrashed();
|
||||
return $this->belongsTo(Template::class, 'id_template')->withTrashed();
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
@ -240,7 +179,22 @@ class Mail extends Model
|
|||
|
||||
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()
|
||||
|
@ -270,9 +224,9 @@ class Mail extends Model
|
|||
}
|
||||
|
||||
// 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) {
|
||||
$this->addPrint($print['id_print']);
|
||||
$this->addPrint($print['id']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Models;
|
||||
namespace Modules\Emails;
|
||||
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Models\Module;
|
||||
use Models\PrintTemplate;
|
||||
use Traits\StoreTrait;
|
||||
|
||||
class MailTemplate extends Model
|
||||
class Template extends Model
|
||||
{
|
||||
use StoreTrait;
|
||||
use SoftDeletes;
|
||||
|
@ -32,6 +34,11 @@ class MailTemplate extends Model
|
|||
|
||||
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');
|
||||
}
|
||||
}
|
|
@ -141,7 +141,7 @@ switch (post('op')) {
|
|||
|
||||
if ($result) {
|
||||
++$added;
|
||||
//operationLog('export-xml-bulk', ['id_record' => $r['id']]);
|
||||
//operationLog('export-xml-bulk', ['id_record' => $r['id']]);
|
||||
} else {
|
||||
$failed[] = $fattura->numero_esterno;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ $r = $dbo->fetchOne('SELECT co_documenti.*,
|
|||
an_anagrafiche.pec,
|
||||
an_anagrafiche.ragione_sociale,
|
||||
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
|
||||
INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica
|
||||
INNER JOIN co_tipidocumento ON co_tipidocumento.id=co_documenti.idtipodocumento
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Models\Mail;
|
||||
use Models\MailTemplate;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Modules\Interventi\Components\Articolo;
|
||||
use Modules\Interventi\Components\Riga;
|
||||
use Modules\Interventi\Components\Sconto;
|
||||
|
@ -51,7 +51,7 @@ switch (post('op')) {
|
|||
// Notifica chiusura intervento
|
||||
$stato = $dbo->selectOne('in_statiintervento', '*', ['idstatointervento' => post('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->addReceiver($stato['destinatari']);
|
||||
|
@ -477,7 +477,7 @@ switch (post('op')) {
|
|||
$stato = $dbo->selectOne('in_statiintervento', '*', ['descrizione' => 'Completato']);
|
||||
// Notifica chiusura intervento
|
||||
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->addReceiver($stato['destinatari']);
|
||||
|
@ -521,7 +521,7 @@ switch (post('op')) {
|
|||
|
||||
// Notifica rimozione dell' intervento al tecnico
|
||||
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->addReceiver($tecnico['email']);
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Models\Mail;
|
||||
use Models\MailTemplate;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Modules\Fatture\Components\Descrizione;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
use Modules\Fatture\Fattura;
|
||||
|
@ -63,7 +63,7 @@ function add_tecnico($idintervento, $idtecnico, $inizio, $fine, $idcontratto = n
|
|||
|
||||
// Notifica nuovo intervento al tecnico
|
||||
if (!empty($tecnico['email'])) {
|
||||
$template = MailTemplate::get('Notifica intervento');
|
||||
$template = Template::get('Notifica intervento');
|
||||
|
||||
$mail = Mail::build(auth()->getUser(), $template, $idintervento);
|
||||
$mail->addReceiver($anagrafica['email']);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Models\MailTemplate;
|
||||
use Modules\Emails\Template;
|
||||
use Modules\Newsletter\Newsletter;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
switch (filter('op')) {
|
||||
case 'add':
|
||||
$template = MailTemplate::find(filter('id_template'));
|
||||
$template = Template::find(filter('id_template'));
|
||||
$newsletter = Newsletter::build($user, $template, filter('name'));
|
||||
|
||||
$id_record = $newsletter->id;
|
||||
|
@ -48,16 +48,16 @@ switch (filter('op')) {
|
|||
continue;
|
||||
}
|
||||
|
||||
$mail = \Models\Mail::build($user, $template, $anagrafica->id);
|
||||
$mail = \Modules\Emails\Mail::build($user, $template, $anagrafica->id);
|
||||
|
||||
$mail->addReceiver($anagrafica['email']);
|
||||
$mail->subject = $newsletter->subject;
|
||||
$mail->content = $newsletter->content;
|
||||
|
||||
$mail->id_campaign = $newsletter->id;
|
||||
$mail->id_newsletter = $newsletter->id;
|
||||
|
||||
foreach ($uploads as $upload) {
|
||||
$mail->addAttachment($upload);
|
||||
$mail->addUpload($upload);
|
||||
}
|
||||
|
||||
$mail->save();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Models\Mail;
|
||||
use Modules\Emails\Mail;
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ namespace Modules\Newsletter;
|
|||
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Models\Mail;
|
||||
use Models\MailAccount;
|
||||
use Models\MailTemplate;
|
||||
use Models\User;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Emails\Account;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Traits\RecordTrait;
|
||||
|
||||
class Newsletter extends Model
|
||||
|
@ -16,9 +16,9 @@ class Newsletter extends Model
|
|||
use SoftDeletes;
|
||||
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();
|
||||
|
||||
|
@ -67,22 +67,22 @@ class Newsletter extends Model
|
|||
|
||||
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()
|
||||
{
|
||||
return $this->hasMany(Mail::class, 'id_campaign');
|
||||
return $this->hasMany(Mail::class, 'id_newsletter');
|
||||
}
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(MailAccount::class, 'id_account');
|
||||
return $this->belongsTo(Account::class, 'id_account');
|
||||
}
|
||||
|
||||
public function template()
|
||||
{
|
||||
return $this->belongsTo(MailTemplate::class, 'id_template');
|
||||
return $this->belongsTo(Template::class, 'id_template');
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
|
|
@ -5,7 +5,7 @@ $r = $dbo->fetchOne('SELECT co_scadenziario.*, co_documenti.*,
|
|||
an_anagrafiche.pec,
|
||||
an_anagrafiche.ragione_sociale,
|
||||
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
|
||||
FROM co_scadenziario
|
||||
INNER JOIN co_documenti ON co_documenti.id = co_scadenziario.iddocumento
|
||||
|
|
|
@ -82,7 +82,7 @@ include_once __DIR__.'/../../core.php';
|
|||
<?php
|
||||
// Collegamenti diretti
|
||||
// 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)) {
|
||||
echo '
|
||||
|
|
|
@ -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>';
|
|
@ -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();
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
$skip_permissions = true;
|
||||
include_once __DIR__.'/core.php';
|
||||
|
||||
use Models\Mail;
|
||||
use Models\MailTemplate;
|
||||
use Models\User;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Notifications\EmailNotification;
|
||||
|
||||
$token = get('reset_token');
|
||||
|
@ -26,7 +26,7 @@ switch (post('op')) {
|
|||
$utente->reset_token = secure_random_string();
|
||||
$utente->save();
|
||||
|
||||
$template = MailTemplate::get('Reset password');
|
||||
$template = Template::get('Reset password');
|
||||
|
||||
$mail = Mail::build($user, $template, $utente->id);
|
||||
$mail->addReceiver($utente->email);
|
||||
|
|
|
@ -21,7 +21,9 @@ class MessageHandler extends AbstractProcessingHandler
|
|||
|
||||
if (auth()->check()) {
|
||||
$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()) {
|
||||
$message .= '
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace HTMLBuilder\Manager;
|
||||
|
||||
use Models\MailTemplate;
|
||||
use Modules\Emails\Template;
|
||||
|
||||
/**
|
||||
* @since 2.4
|
||||
|
@ -38,7 +38,7 @@ class ButtonManager implements ManagerInterface
|
|||
'icon' => $print['icon'],
|
||||
];
|
||||
} else {
|
||||
$template = MailTemplate::find($options['id']);
|
||||
$template = Template::find($options['id']);
|
||||
|
||||
$result = [
|
||||
'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') {
|
||||
$results = \Prints::getModulePrints($options['id_module']);
|
||||
} else {
|
||||
$results = MailTemplate::where('id_module', $options['id_module'])->get()->toArray();
|
||||
$results = Template::where('id_module', $options['id_module'])->get()->toArray();
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace HTMLBuilder\Manager;
|
||||
|
||||
use Models\Mail;
|
||||
use Prints;
|
||||
use Translator;
|
||||
use Modules\Emails\Mail;
|
||||
|
||||
/**
|
||||
* Gestione allegati.
|
||||
|
@ -49,28 +47,24 @@ class EmailManager implements ManagerInterface
|
|||
<ul>';
|
||||
|
||||
foreach ($emails as $operation) {
|
||||
$receivers = array_column($operation->receivers, 'email');
|
||||
$receivers = $operation->receivers->pluck('address')->toArray();
|
||||
|
||||
$prints = [];
|
||||
$list = $operation->prints;
|
||||
foreach ($list as $print) {
|
||||
$print = Prints::get($print['id']);
|
||||
|
||||
$prints[] = $print['title'];
|
||||
}
|
||||
|
||||
$attachments = [];
|
||||
$list = $operation->attachments;
|
||||
foreach ($list as $attachment) {
|
||||
$attachment = $database->selectOne('zz_files', '*', ['id' => $attachment]);
|
||||
|
||||
$attachments[] = $attachment['name'];
|
||||
$uploads = [];
|
||||
$list = $operation->uploads;
|
||||
foreach ($list as $upload) {
|
||||
$uploads[] = $upload['name'];
|
||||
}
|
||||
|
||||
$sent = !empty($operation['sent_at']) ? tr('inviata il _DATE_ alle _HOUR_', [
|
||||
'_DATE_' => dateFormat($operation['sent_at']),
|
||||
'_HOUR_' => timeFormat($operation['sent_at']),
|
||||
]) : tr('in coda di invio') ;
|
||||
]) : tr('in coda di invio');
|
||||
|
||||
$result .= '
|
||||
<li>
|
||||
|
@ -86,9 +80,9 @@ class EmailManager implements ManagerInterface
|
|||
<li><b>'.tr('Stampe').'</b>: '.implode(', ', $prints).'.</li>';
|
||||
}
|
||||
|
||||
if (!empty($attachments)) {
|
||||
if (!empty($uploads)) {
|
||||
$result .= '
|
||||
<li><b>'.tr('Allegati').'</b>: '.implode(', ', $attachments).'.</li>';
|
||||
<li><b>'.tr('Allegati').'</b>: '.implode(', ', $uploads).'.</li>';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
|
|
|
@ -123,9 +123,9 @@ class Module extends Model
|
|||
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()
|
||||
|
|
|
@ -10,11 +10,13 @@ class OperationLog extends Model
|
|||
|
||||
protected static $info = [];
|
||||
|
||||
public static function setInfo($name, $value){
|
||||
public static function setInfo($name, $value)
|
||||
{
|
||||
self::$info[$name] = $value;
|
||||
}
|
||||
|
||||
public static function getInfo($name){
|
||||
public static function getInfo($name)
|
||||
{
|
||||
return self::$info[$name];
|
||||
}
|
||||
|
||||
|
@ -26,7 +28,7 @@ class OperationLog extends Model
|
|||
|
||||
$model = parent::build();
|
||||
|
||||
foreach (self::$info as $key => $value){
|
||||
foreach (self::$info as $key => $value) {
|
||||
$model->{$key} = $value;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Notifications;
|
||||
|
||||
use Models\MailAccount;
|
||||
use Modules\Emails\Account;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use Prints;
|
||||
use Uploads;
|
||||
|
@ -21,9 +21,9 @@ class EmailNotification extends PHPMailer implements NotificationInterface
|
|||
$this->CharSet = 'UTF-8';
|
||||
|
||||
// Configurazione di base
|
||||
$config = MailAccount::find($account);
|
||||
$config = Account::find($account);
|
||||
if (empty($config)) {
|
||||
$config = MailAccount::where('predefined', true)->first();
|
||||
$config = Account::where('predefined', true)->first();
|
||||
}
|
||||
|
||||
// Preparazione email
|
||||
|
@ -71,7 +71,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface
|
|||
$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);
|
||||
|
||||
|
@ -153,7 +153,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface
|
|||
$this->mail->failed_at = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$this->mail->save();
|
||||
//$this->mail->save();
|
||||
}
|
||||
|
||||
$this->SmtpClose();
|
||||
|
@ -192,32 +192,6 @@ class EmailNotification extends PHPMailer implements NotificationInterface
|
|||
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.
|
||||
*
|
||||
|
@ -226,9 +200,8 @@ class EmailNotification extends PHPMailer implements NotificationInterface
|
|||
public function addUpload($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'];
|
||||
|
||||
$this->addAttachment($info['path'], $name);
|
||||
|
||||
$this->logs['prints'][] = $print['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -269,6 +269,9 @@ class Update
|
|||
}
|
||||
}
|
||||
|
||||
// Normalizzazione di charset e collation
|
||||
self::normalizeDatabase($database->getDatabaseName());
|
||||
|
||||
// Normalizzazione dei campi per l'API
|
||||
self::executeScript(DOCROOT.'/update/api.php');
|
||||
|
||||
|
|
|
@ -1,27 +1,36 @@
|
|||
<?php
|
||||
|
||||
// Correzione zz_operations
|
||||
use Models\Mail;
|
||||
use Models\MailTemplate;
|
||||
use Models\User;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
|
||||
$database->query('ALTER TABLE `zz_operations` DROP FOREIGN KEY `zz_operations_ibfk_3`');
|
||||
$logs = $database->fetchArray("SELECT * FROM `zz_operations` WHERE `op` = 'send-email'");
|
||||
foreach ($logs as $log) {
|
||||
$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->resetPrints();
|
||||
|
||||
$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->created_at = $log['created_at'];
|
||||
$mail->sent_at = $log['created_at'];
|
||||
foreach ($options['attachments'] as $upload) {
|
||||
$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();
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
-- 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'));
|
||||
|
||||
-- Miglioramento gestione email
|
||||
ALTER TABLE `zz_emails` RENAME TO `em_templates`;
|
||||
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_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_smtps', 'em_accounts');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `em_campaigns` (
|
||||
CREATE TABLE IF NOT EXISTS `em_newsletters` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`id_template` int(11) NOT NULL,
|
||||
`state` varchar(25) NOT NULL,
|
||||
`subject` varchar(255) NOT NULL,
|
||||
`content` TEXT NOT NULL,
|
||||
`notes` TEXT,
|
||||
`created_by` int(11) NOT NULL,
|
||||
`completed_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_account` int(11) NOT NULL,
|
||||
`id_template` int(11),
|
||||
`id_campaign` int(11),
|
||||
`id_newsletter` int(11),
|
||||
`id_record` int(11),
|
||||
`subject` varchar(255),
|
||||
`content` TEXT,
|
||||
`receivers` TEXT,
|
||||
`attachments` TEXT,
|
||||
`prints` TEXT,
|
||||
`options` TEXT,
|
||||
`sent_at` TIMESTAMP NULL DEFAULT NULL,
|
||||
`failed_at` TIMESTAMP NULL DEFAULT NULL,
|
||||
`processing_at` TIMESTAMP NULL DEFAULT NULL,
|
||||
`created_by` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
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_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
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `em_campaign_anagrafica` (
|
||||
`id_campaign` int(11) NOT NULL,
|
||||
CREATE TABLE IF NOT EXISTS `em_email_receiver` (
|
||||
`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_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_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- Hook per la gestione della coda di invio
|
||||
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_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
|
||||
((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'), '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);
|
||||
|
||||
-- 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;
|
||||
|
|
|
@ -48,12 +48,15 @@ return [
|
|||
'dt_spedizione',
|
||||
'dt_statiddt',
|
||||
'dt_tipiddt',
|
||||
'em_template_print',
|
||||
'em_print_template',
|
||||
'em_accounts',
|
||||
'em_templates',
|
||||
'em_campaigns',
|
||||
'em_newsletters',
|
||||
'em_emails',
|
||||
'em_campaign_anagrafica',
|
||||
'em_email_receiver',
|
||||
'em_email_upload',
|
||||
'em_email_print',
|
||||
'em_newsletter_anagrafica',
|
||||
'fe_causali_pagamento_ritenuta',
|
||||
'fe_modalita_pagamento',
|
||||
'fe_natura',
|
||||
|
|
Loading…
Reference in New Issue