diff --git a/actions.php b/actions.php index 28a057484..e8d9182ff 100644 --- a/actions.php +++ b/actions.php @@ -217,47 +217,57 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { } elseif (filter('op') == 'send-email') { $template = Mail::getTemplate($post['template']); - $final_attachments = []; + $attachments = []; - $prints = Prints::getModulePrints($id_module); - foreach ($prints as $print) { - if (!empty($post['print-'.$print['id']])) { - $filename = $upload_dir.'/'.$print['title'].' - '.$id_record.'.pdf'; + // Stampe + foreach ($post['prints'] as $print) { + $print = Prints::get($print); - Prints::render($print['id'], $id_record, $filename); + $filename = $upload_dir.'/'.$print['title'].' - '.$id_record.'.pdf'; - $final_attachments[] = [ - 'path' => $filename, - 'name' => $print['title'], - ]; - } + Prints::render($print['id'], $id_record, $filename); + + $attachments[] = [ + 'path' => $filename, + 'name' => $print['title'], + ]; } - $attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)); - foreach ($attachments as $attachment) { - if (!empty($post['attachment-'.$attachment['id']])) { - $final_attachments[] = [ - 'path' => $upload_dir.'/'.$attachment['filename'], - 'name' => $attachment['nome'], - ]; - } + // Allegati del record + $selected = []; + if (!empty($post['attachments'])) { + $selected = $dbo->fetchArray('SELECT * FROM zz_files WHERE id IN ('.implode($post['attachments']).') AND id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)); } + foreach ($selected as $attachment) { + $attachments[] = [ + 'path' => $upload_dir.'/'.$attachment['filename'], + 'name' => $attachment['nome'], + ]; + } + + // Allegati dell'Azienda predefinita $anagrafiche = Modules::get('Anagrafiche'); - $attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($anagrafiche['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')"); - foreach ($attachments as $attachment) { - if (!empty($post['default-'.$attachment['id']])) { - $final_attachments[] = [ - 'path' => DOCROOT.'/files/'.$anagrafiche['directory'].'/'.$attachment['filename'], - 'name' => $attachment['nome'], - ]; - } + + $selected = []; + if (!empty($post['attachments'])) { + $selected = $dbo->fetchArray('SELECT * FROM zz_files WHERE id IN ('.implode(',', $post['attachments']).') AND id_module != '.prepare($id_module)); + } + + foreach ($selected as $attachment) { + $attachments[] = [ + 'path' => DOCROOT.'/files/'.$anagrafiche['directory'].'/'.$attachment['filename'], + 'name' => $attachment['nome'], + ]; } // Preparazione email $mail = new Mail(); - $mail->AddAddress($post['email']); + // Conferma di lettura + if (!empty($post['read_notify'])) { + $mail->ConfirmReadingTo = $mail->From; + } // Reply To if (!empty($template['reply_to'])) { @@ -274,6 +284,32 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { $mail->AddBCC($template['bcc']); } + // Destinatari + foreach ($post['destinatari'] as $key => $destinatario) { + $type = $post['tipo_destinatari'][$key]; + + $pieces = explode('<', $destinatario); + $count = count($pieces); + + $name = null; + if ($count > 1) { + $email = substr(end($pieces), 0, -1); + $name = substr($destinatario, 0, strpos($destinatario, '<'.$email)); + } else { + $email = $destinatario; + } + + if (!empty($email)) { + if ($type == 'a') { + $mail->AddAddress($email, $name); + } elseif ($type == 'cc') { + $mail->AddCC($email, $name); + } elseif ($type == 'bcc') { + $mail->AddBCC($email, $name); + } + } + } + // Oggetto $mail->Subject = $post['subject']; @@ -282,14 +318,18 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { $mail->AddAttachment($attachment['path'], $attachment['name']); } + // Contenuto $mail->Body = $post['body']; // Invio mail if (!$mail->send()) { - $_SESSION['errors'][] = tr("Errore durante l'invio della segnalazione").': '.$mail->ErrorInfo; + $_SESSION['errors'][] = tr("Errore durante l'invio dell'email").': '.$mail->ErrorInfo; } else { $_SESSION['infos'][] = tr('Email inviata correttamente!'); } + + redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record); + exit(); } if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso) == 'rw') { diff --git a/assets/src/css/style.css b/assets/src/css/style.css index 94171030d..ca6ed7f5c 100644 --- a/assets/src/css/style.css +++ b/assets/src/css/style.css @@ -75,6 +75,7 @@ a.disabled { } .ui-autocomplete { + z-index: 10000; min-width: 160px; padding: 10px; margin: 2px; @@ -274,7 +275,6 @@ span.form-control { margin-top: 0; } - /* Aggiustamenti per i widget */ .widget li { @@ -301,7 +301,6 @@ span.form-control { opacity: 0.1; } - /* Tooltip dark */ .ui-tooltip { @@ -448,12 +447,11 @@ span.form-control { margin: 5px; } - /* Personalizzazione del plugin Select2 */ .select2-search, .select2-search__field { - width: 100% + width: 100% !important } .select2-results__option[aria-selected=true] { @@ -476,7 +474,6 @@ span.form-control { border-radius: 0px; } - /* Interventi da pianificare in Dashboard */ #external-events .fc-event { @@ -519,11 +516,9 @@ input.small-width { width: 90%; margin-top: 20px } - .main-header .logo { display: none; } - /* .content-wrapper, .right-side, @@ -554,7 +549,6 @@ input.small-width { .push { position: static; } - .signature-pad { top: 0; left: 0; diff --git a/mail.php b/mail.php index e03cf7dce..9a9a26c15 100644 --- a/mail.php +++ b/mail.php @@ -4,141 +4,149 @@ include_once __DIR__.'/core.php'; $template = Mail::getTemplate($get['id']); $module = Modules::get($id_module); +$smtp = Mail::get($template['id_smtp']); $body = $template['body']; $subject = $template['subject']; -$variables = Mail::getTemplateVariables($template); +$variables = Mail::getTemplateVariables($template['id'], $id_record); $email = $variables['email']; +// Sostituzione delle variabili di base +$replaces = []; +foreach ($variables as $key => $value) { + $replaces['{'.$key.'}'] = $value; +} + +$body = str_replace(array_keys($replaces), array_values($replaces), $body); +$subject = str_replace(array_keys($replaces), array_values($replaces), $subject); + +// Form echo ' -