diff --git a/actions.php b/actions.php
index a41108489..61352dbcf 100644
--- a/actions.php
+++ b/actions.php
@@ -2,6 +2,7 @@
include_once __DIR__.'/core.php';
+use Models\MailTemplate;
use Models\Note;
use Modules\Checklists\Check;
use Modules\Checklists\Checklist;
@@ -203,16 +204,15 @@ elseif (filter('op') == 'sort_checks') {
}
}
-// Invio email
+// Inizializzazione email
elseif (post('op') == 'send-email') {
- $id_template = post('template');
+ $template = MailTemplate::find(post('template'));
- // Inizializzazione
- $mail = new Notifications\EmailNotification();
- $mail->setTemplate($id_template, $id_record);
+ $mail = \Models\Mail::build($template, $id_record);
// Rimozione allegati predefiniti
- $mail->setAttachments([]);
+ $mail->resetAttachments();
+ $mail->resetPrints();
// Destinatari
$receivers = array_clean(post('destinatari'));
@@ -222,29 +222,25 @@ elseif (post('op') == 'send-email') {
}
// Contenuti
- $mail->setSubject(post('subject'));
- $mail->setContent(post('body'));
+ $mail->subject = post('subject');
+ $mail->content = post('body');
+
+ // Conferma di lettura
+ $mail->read_notify = post('read_notify');
// Stampe da allegare
$prints = post('prints');
foreach ($prints as $print) {
- $mail->addPrint($print, $id_record);
+ $mail->addPrint($print);
}
// Allegati originali
$files = post('attachments');
foreach ($files as $file) {
- $mail->addUpload($file);
+ $mail->addAttachment($file);
}
- // Invio mail
- try {
- $mail->send(true); // Il valore true impone la gestione degli errori tramite eccezioni
-
- flash()->info(tr('Email inviata correttamente!'));
- } catch (PHPMailer\PHPMailer\Exception $e) {
- flash()->error(tr("Errore durante l'invio dell'email").': '.$e->errorMessage());
- }
+ $mail->save();
}
// Inclusione di eventuale plugin personalizzato
diff --git a/ajax.php b/ajax.php
index d2c611bc0..9f685051f 100644
--- a/ajax.php
+++ b/ajax.php
@@ -114,6 +114,16 @@ switch (get('op')) {
break;
+ case 'prepare-hook':
+ $hook_id = filter('id');
+ $hook = Hook::find($hook_id);
+
+ $response = $hook->prepare();
+
+ echo json_encode($response);
+
+ break;
+
case 'flash':
$response = flash()->getMessages();
diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js
index 0b668b4a7..b682afd73 100644
--- a/assets/src/js/functions/hooks.js
+++ b/assets/src/js/functions/hooks.js
@@ -1,7 +1,77 @@
+/**
+ *
+ */
+function startHooks() {
+ $.ajax({
+ url: globals.rootdir + "/ajax.php",
+ type: "get",
+ data: {
+ op: "hooks",
+ },
+ success: function(data) {
+ hooks = JSON.parse(data);
-function executeHook(hook, length){
- $("#hooks").append('
' + globals.translations.hookExecuting.replace('_NAME_', hook.name) + '');
+ $("#hooks-header").text(globals.translations.hooksExecuting);
+ $("#hooks-number").text(hooks.length);
+ if (hooks.length == 0) {
+ $("#hooks-loading").hide();
+ $("#hooks-number").text(0);
+ $("#hooks-header").text(globals.translations.hookNone);
+ }
+
+ hooks.forEach(function(item, index){
+ startHook(item);
+ });
+ },
+ });
+}
+
+/**
+ *
+ * @param hook
+ */
+function startHook(hook){
+ var element_id = "hook-" + hook.id;
+ $("#hooks").append('' + globals.translations.hookExecuting.replace('_NAME_', hook.name) + '');
+
+ element_id = "#" + element_id;
+
+ $.ajax({
+ url: globals.rootdir + "/ajax.php",
+ type: "get",
+ data: {
+ op: "prepare-hook",
+ id: hook.id,
+ },
+ success: function(data) {
+ var result = JSON.parse(data);
+
+ addHookCount("#hooks-counter");
+
+ if (result){
+ renderHook(element_id, result);
+
+ if (result.execute){
+ addHookCount("#hooks-notified");
+
+ executeHook(hook, element_id, true)
+ } else {
+ $(element_id).remove();
+ }
+ } else {
+ executeHook(hook, element_id)
+ }
+ },
+ });
+}
+
+/**
+ *
+ * @param hook
+ * @param element_id
+ */
+function executeHook(hook, element_id, is_background){
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "get",
@@ -10,35 +80,22 @@ function executeHook(hook, length){
id: hook.id,
},
success: function(data) {
- result = JSON.parse(data);
+ var result = JSON.parse(data);
- $("#hook-loader-" + hook.id).remove();
+ renderHook(element_id, result);
- notification = ' ' + result.message + '';
-
- // Inserimento della notifica
- hooks_number = $("#hooks-number");
- number = parseInt(hooks_number.text());
- number = isNaN(number) ? 0 : number;
-
- if(result.notify) {
- number++;
-
- $("#hooks").prepend(notification);
- } else {
- //$("#hooks").append(notification);
+ if (!is_background) {
+ if (result.notify) {
+ addHookCount("#hooks-notified");
+ } else {
+ $(element_id).remove();
+ }
}
- hooks_number.text(number);
-
- // Contatore dell'esecuzione degli hook
- hooks_counter = $("#hooks-counter");
- counter = parseInt(hooks_counter.text());
- counter++;
- hooks_counter.text(counter);
-
// Rimozione eventuale della rotella di caricamento
- if(counter == hooks.length) {
+ var counter = $("#hooks-counter").text();
+ var number = $("#hooks-notified").text();
+ if(counter == $("#hooks-number").text()) {
$("#hooks-loading").hide();
if (number > 1){
@@ -54,3 +111,26 @@ function executeHook(hook, length){
},
});
}
+
+/**
+ * Aggiunta dell'hook al numero totale.
+ */
+function addHookCount(id) {
+ var hooks_number = $(id);
+ var number = parseInt(hooks_number.text());
+ number = isNaN(number) ? 0 : number;
+
+ number++;
+ hooks_number.text(number);
+
+ return number;
+}
+
+/**
+ *
+ * @param element_id
+ * @param result
+ */
+function renderHook(element_id, result) {
+ $(element_id).html(' ' + result.message + '');
+}
diff --git a/bug.php b/bug.php
index 14efdf827..a6251c4e4 100644
--- a/bug.php
+++ b/bug.php
@@ -1,8 +1,10 @@
'Common',
'modules/aggiornamenti' => 'Modules\Aggiornamenti',
'modules/anagrafiche' => 'Modules\Anagrafiche',
+ 'modules/backups' => 'Modules\Backups',
'modules/articoli' => 'Modules\Articoli',
'modules/checklists' => 'Modules\Checklists',
'modules/ritenute' => 'Modules\Ritenute',
diff --git a/include/bottom.php b/include/bottom.php
index 4b4b455b5..7b9693eb9 100644
--- a/include/bottom.php
+++ b/include/bottom.php
@@ -53,40 +53,20 @@ if (Auth::check()) {
echo '
';
}
echo '
- ';
-echo '
+