mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 00:46:44 +01:00
Introduzione dell'invio email
This commit is contained in:
parent
99865fbd61
commit
ae4d6b1d98
118
actions.php
118
actions.php
@ -15,7 +15,7 @@ if (!empty($id_plugin)) {
|
||||
$permesso = $id_module;
|
||||
}
|
||||
|
||||
$upload_dir = $docroot.'/files/'.basename($directory);
|
||||
$upload_dir = DOCROOT.'/files/'.basename($directory);
|
||||
|
||||
$dbo->query('START TRANSACTION');
|
||||
|
||||
@ -214,32 +214,108 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
||||
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename')));
|
||||
|
||||
download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']);
|
||||
} elseif (filter('op') == 'send-email') {
|
||||
$template = Mail::getTemplate($post['template']);
|
||||
|
||||
$final_attachments = [];
|
||||
|
||||
$prints = Prints::getModulePrints($id_module);
|
||||
foreach ($prints as $print) {
|
||||
if (!empty($post['print-'.$print['id']])) {
|
||||
$filename = $upload_dir.'/'.$print['title'].' - '.$id_record.'.pdf';
|
||||
|
||||
Prints::render($print['id'], $id_record, $filename);
|
||||
|
||||
$final_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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Preparazione email
|
||||
$mail = new Mail();
|
||||
|
||||
$mail->AddAddress($post['email']);
|
||||
|
||||
// Reply To
|
||||
if (!empty($template['reply_to'])) {
|
||||
$mail->AddReplyTo($template['reply_to']);
|
||||
}
|
||||
|
||||
// CC
|
||||
if (!empty($template['cc'])) {
|
||||
$mail->AddCC($template['cc']);
|
||||
}
|
||||
|
||||
// BCC
|
||||
if (!empty($template['bcc'])) {
|
||||
$mail->AddBCC($template['bcc']);
|
||||
}
|
||||
|
||||
// Oggetto
|
||||
$mail->Subject = $post['subject'];
|
||||
|
||||
// Allegati
|
||||
foreach ($final_attachments as $attachment) {
|
||||
$mail->AddAttachment($attachment['path'], $attachment['name']);
|
||||
}
|
||||
|
||||
$mail->Body = $post['body'];
|
||||
|
||||
// Invio mail
|
||||
if (!$mail->send()) {
|
||||
$_SESSION['errors'][] = tr("Errore durante l'invio della segnalazione").': '.$mail->ErrorInfo;
|
||||
} else {
|
||||
$_SESSION['infos'][] = tr('Email inviata correttamente!');
|
||||
}
|
||||
}
|
||||
|
||||
if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso) == 'rw') {
|
||||
if (!empty($info['script'])) {
|
||||
// Inclusione di eventuale plugin personalizzato
|
||||
if (file_exists($docroot.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script'])) {
|
||||
include $docroot.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script'];
|
||||
} elseif (file_exists($docroot.'/modules/'.$info['module_dir'].'/plugins/'.$info['script'])) {
|
||||
include $docroot.'/modules/'.$info['module_dir'].'/plugins/'.$info['script'];
|
||||
if (file_exists(DOCROOT.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script'])) {
|
||||
include DOCROOT.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script'];
|
||||
} elseif (file_exists(DOCROOT.'/modules/'.$info['module_dir'].'/plugins/'.$info['script'])) {
|
||||
include DOCROOT.'/modules/'.$info['module_dir'].'/plugins/'.$info['script'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
|
||||
if (file_exists($docroot.$directory.'/custom/modutil.php')) {
|
||||
include_once $docroot.$directory.'/custom/modutil.php';
|
||||
} elseif (file_exists($docroot.$directory.'/modutil.php')) {
|
||||
include_once $docroot.$directory.'/modutil.php';
|
||||
if (file_exists(DOCROOT.$directory.'/custom/modutil.php')) {
|
||||
include_once DOCROOT.$directory.'/custom/modutil.php';
|
||||
} elseif (file_exists(DOCROOT.$directory.'/modutil.php')) {
|
||||
include_once DOCROOT.$directory.'/modutil.php';
|
||||
}
|
||||
|
||||
// Lettura risultato query del modulo
|
||||
if (file_exists($docroot.$directory.'/custom/init.php')) {
|
||||
include $docroot.$directory.'/custom/init.php';
|
||||
} elseif (file_exists($docroot.$directory.'/init.php')) {
|
||||
include $docroot.$directory.'/init.php';
|
||||
if (file_exists(DOCROOT.$directory.'/custom/init.php')) {
|
||||
include DOCROOT.$directory.'/custom/init.php';
|
||||
} elseif (file_exists(DOCROOT.$directory.'/init.php')) {
|
||||
include DOCROOT.$directory.'/init.php';
|
||||
}
|
||||
|
||||
if (Modules::getPermission($permesso) == 'rw') {
|
||||
@ -250,10 +326,10 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
|
||||
$id_records = array_unique($id_records);
|
||||
|
||||
$bulk = null;
|
||||
if (file_exists($docroot.$directory.'/custom/bulk.php')) {
|
||||
$bulk = include $docroot.$directory.'/custom/bulk.php';
|
||||
} elseif (file_exists($docroot.$directory.'/bulk.php')) {
|
||||
$bulk = include $docroot.$directory.'/bulk.php';
|
||||
if (file_exists(DOCROOT.$directory.'/custom/bulk.php')) {
|
||||
$bulk = include DOCROOT.$directory.'/custom/bulk.php';
|
||||
} elseif (file_exists(DOCROOT.$directory.'/bulk.php')) {
|
||||
$bulk = include DOCROOT.$directory.'/bulk.php';
|
||||
}
|
||||
$bulk = (array) $bulk;
|
||||
|
||||
@ -261,10 +337,10 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
|
||||
redirect(ROOTDIR.'/controller.php?id_module='.$id_module, 'js');
|
||||
} else {
|
||||
// Esecuzione delle operazioni del modulo
|
||||
if (file_exists($docroot.$directory.'/custom/actions.php')) {
|
||||
include $docroot.$directory.'/custom/actions.php';
|
||||
} elseif (file_exists($docroot.$directory.'/actions.php')) {
|
||||
include $docroot.$directory.'/actions.php';
|
||||
if (file_exists(DOCROOT.$directory.'/custom/actions.php')) {
|
||||
include DOCROOT.$directory.'/custom/actions.php';
|
||||
} elseif (file_exists(DOCROOT.$directory.'/actions.php')) {
|
||||
include DOCROOT.$directory.'/actions.php';
|
||||
}
|
||||
|
||||
// Operazioni generiche per i campi personalizzati
|
||||
|
145
mail.php
Normal file
145
mail.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__.'/core.php';
|
||||
|
||||
$template = Mail::getTemplate($get['id']);
|
||||
$module = Modules::get($id_module);
|
||||
|
||||
$body = $template['body'];
|
||||
$subject = $template['subject'];
|
||||
|
||||
$variables = Mail::getTemplateVariables($template);
|
||||
$email = $variables['email'];
|
||||
|
||||
echo '
|
||||
<form action="" method="post" id="add-form">
|
||||
<input type="hidden" name="op" value="send-email">
|
||||
<input type="hidden" name="backto" value="record-edit">
|
||||
|
||||
<input type="hidden" name="template" value="'.$template['id'].'">
|
||||
|
||||
<!-- Dati -->
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Dati').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type": "text", "label": "'.tr('Oggetto').'", "name": "subject", "value": "'.$subject.'", "required": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
{[ "type": "email", "label": "'.tr('Destinatario').'", "name": "email", "value": "'.$email.'", "required": 1 ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type": "textarea", "label": "'.tr('Contenuto').'", "name": "body", "value": '.json_encode($body).' ]}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
<div class="row">
|
||||
|
||||
<!-- Stampe -->
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Stampe').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">';
|
||||
|
||||
$selected_prints = $dbo->fetchArray('SELECT id_print FROM zz_email_print WHERE id_email = '.prepare($template['id']));
|
||||
$selected = array_column($selected_prints, 'id_print');
|
||||
|
||||
$prints = Prints::getModulePrints($id_module);
|
||||
foreach ($prints as $print) {
|
||||
echo '
|
||||
{[ "type": "checkbox", "label": "'.$print['title'].'", "name": "print-'.$print['id'].'", "value": "'.in_array($print['id'], $selected).'" ]}';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Allegati -->
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Allegati').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">';
|
||||
|
||||
$attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record));
|
||||
|
||||
if (empty($attachments)) {
|
||||
echo '
|
||||
<p>'.tr('Nessun allegato disponibile').'.</p>';
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
echo '
|
||||
{[ "type": "checkbox", "label": "'.$attachment['nome'].'", "name": "attachment-'.$attachment['id'].'" ]}';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Anagrafica -->
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Anagrafica').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">';
|
||||
|
||||
$attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')");
|
||||
|
||||
if (empty($attachments)) {
|
||||
echo '
|
||||
<p>'.tr('Nessun allegato disponibile').'.</p>';
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
echo '
|
||||
{[ "type": "checkbox", "label": "'.$attachment['nome'].'", "name": "default-'.$attachment['id'].'" ]}';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<button type="submit" class="btn btn-primary"><i class="fa fa-envelope"></i> '.tr('Invia').'</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>';
|
||||
|
||||
echo '
|
||||
<script src="'.$rootdir.'/assets/dist/js/ckeditor/ckeditor.js"></script>';
|
||||
|
||||
echo '
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
CKEDITOR.replace("body");
|
||||
});
|
||||
</script>';
|
||||
|
||||
echo '
|
||||
<script src="'.$rootdir.'/lib/init.js"></script>';
|
@ -45,6 +45,8 @@ if (empty($records[0]['firma_file'])) {
|
||||
|
||||
{( "name": "button", "type": "print", "id_module": "<?php echo $id_module; ?>", "id_record": "<?php echo $id_record; ?>" )}
|
||||
|
||||
{( "name": "button", "type": "email", "id_module": "<?php echo $id_module; ?>", "id_record": "<?php echo $id_record; ?>" )}
|
||||
|
||||
<button type="submit" class="btn btn-success"><i class="fa fa-check"></i> <?php echo tr('Salva modifiche'); ?></button>
|
||||
<div class="clearfix" > </div>
|
||||
</div>
|
||||
|
@ -32,6 +32,15 @@ class ButtonManager implements ManagerInterface
|
||||
'title' => $print['title'],
|
||||
'icon' => $print['icon'],
|
||||
];
|
||||
} else {
|
||||
$template = \Mail::getTemplate($options['id']);
|
||||
|
||||
$result = [
|
||||
'link' => ROOTDIR.'/mail.php?id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id='.$options['id'],
|
||||
'title' => $template['name'],
|
||||
'icon' => $template['icon'],
|
||||
'type' => 'modal',
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -49,8 +58,23 @@ class ButtonManager implements ManagerInterface
|
||||
$icon = !empty($options['icon']) ? $options['icon'] : $info['icon'];
|
||||
$icon = str_replace('|default|', $info['icon'], $icon);
|
||||
|
||||
return '
|
||||
<a '.$class.' href="'.$info['link'].'" target="_blank"><i class="'.$icon.'"></i> '.$title.'</a>';
|
||||
// Modal
|
||||
if (isset($info['type']) && $info['type'] == 'modal') {
|
||||
$result = '
|
||||
<a '.$class.' data-href="'.$info['link'].'" data-toggle="modal" data-title="'.$title.'" data-target="#bs-popup">';
|
||||
}
|
||||
|
||||
// Link normale
|
||||
else {
|
||||
$result = '
|
||||
<a '.$class.' href="'.$info['link'].'" target="_blank">';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
<i class="'.$icon.'"></i> '.$title.'
|
||||
</a>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getList($options)
|
||||
@ -59,6 +83,8 @@ class ButtonManager implements ManagerInterface
|
||||
|
||||
if ($options['type'] == 'print') {
|
||||
$results = \Prints::getModulePrints($options['id_module']);
|
||||
} else {
|
||||
$results = \Mail::getModuleTemplates($options['id_module']);
|
||||
}
|
||||
|
||||
return $results;
|
||||
@ -67,10 +93,11 @@ class ButtonManager implements ManagerInterface
|
||||
protected function dropdown($options)
|
||||
{
|
||||
$list = $this->getList($options);
|
||||
$count = count($list);
|
||||
|
||||
$options['class'] = isset($options['class']) ? $options['class'] : 'btn-info';
|
||||
|
||||
if (count($list) > 1) {
|
||||
if ($count > 1) {
|
||||
$result = '
|
||||
<div class="btn-group">';
|
||||
|
||||
@ -81,6 +108,7 @@ class ButtonManager implements ManagerInterface
|
||||
$result .= $this->link([
|
||||
'type' => $options['type'],
|
||||
'id' => $element['id'],
|
||||
'id_module' => $options['id_module'],
|
||||
'id_record' => $options['id_record'],
|
||||
'class' => $options['class'],
|
||||
]);
|
||||
@ -100,6 +128,7 @@ class ButtonManager implements ManagerInterface
|
||||
<li>'.$this->link([
|
||||
'type' => $options['type'],
|
||||
'id' => $element['id'],
|
||||
'id_module' => $options['id_module'],
|
||||
'id_record' => $options['id_record'],
|
||||
'class' => false,
|
||||
]).'</li>';
|
||||
@ -108,13 +137,16 @@ class ButtonManager implements ManagerInterface
|
||||
$result .= '
|
||||
</ul>
|
||||
</div>';
|
||||
} else {
|
||||
} elseif ($count == 1) {
|
||||
$result = $this->link([
|
||||
'type' => $options['type'],
|
||||
'id' => $list[0]['id']['id'],
|
||||
'id_module' => $options['id_module'],
|
||||
'id_record' => $options['id_record'],
|
||||
'class' => $options['class'],
|
||||
]);
|
||||
} else {
|
||||
$result = ' ';
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -126,6 +158,8 @@ class ButtonManager implements ManagerInterface
|
||||
|
||||
if ($options['type'] == 'print') {
|
||||
$result = '<i class="fa fa-print"></i> '.tr('Stampe');
|
||||
} else {
|
||||
$result = '<i class="fa fa-envelope"></i> '.tr('Email');
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
32
src/Mail.php
32
src/Mail.php
@ -113,6 +113,33 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
|
||||
return self::getTemplates()[$template];
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce le informazioni relative a un singolo template specificato.
|
||||
*
|
||||
* @param string|int $template
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getTemplateVariables($template)
|
||||
{
|
||||
$template = self::getTemplate($template);
|
||||
$module = Modules::get($template['id_module']);
|
||||
|
||||
$directory = DOCROOT.'/modules/'.$module['directory'].'|custom|/variables.php';
|
||||
|
||||
$original_file = str_replace('|custom|', '', $directory).'form.php';
|
||||
$custom_file = str_replace('|custom|', '/custom', $directory).'form.php';
|
||||
|
||||
// Lettura delle variabili nei singoli moduli
|
||||
if (file_exists($custom_file)) {
|
||||
$variables = require $custom_file;
|
||||
} elseif (file_exists($original_file)) {
|
||||
$variables = require $original_file;
|
||||
}
|
||||
|
||||
return (array) $variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce le informazioni relative ai template di un singolo modulo specificato.
|
||||
*
|
||||
@ -124,6 +151,8 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
|
||||
{
|
||||
$module_id = Modules::get($module)['id'];
|
||||
|
||||
self::getTemplates();
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ((array) self::$modules[$module_id] as $value) {
|
||||
@ -169,6 +198,9 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
|
||||
}
|
||||
}
|
||||
|
||||
$this->From = $config['from_address'];
|
||||
$this->FromName = $_SESSION['from_name'];
|
||||
|
||||
$this->WordWrap = 78;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user