diff --git a/bug.php b/bug.php index a184885c4..677716201 100644 --- a/bug.php +++ b/bug.php @@ -76,27 +76,26 @@ if (file_exists($docroot.'/include/custom/top.php')) { include $docroot.'/include/top.php'; } -$email_to = ''; -$email_from = ''; -$rs = $dbo->fetchArray("SELECT * FROM zz_settings WHERE sezione = 'Email'"); -foreach ($rs as $r) { - if (($r['nome'] == 'Server SMTP' || $r['nome'] == 'Indirizzo per le email in uscita' || $r['nome'] == 'Destinatario') && $r['valore'] == '') { - $alert = true; - } +$email_to = Settings::get('Destinatario'); +$email_from = Settings::get('Indirizzo per le email in uscita'); - if ($r['nome'] == 'Destinatario') { - $email_to = $r['valore']; - } elseif ($r['nome'] == 'Indirizzo per le email in uscita') { - $email_from = $r['valore']; - } -} +$mail = Mail::get(); -if (!empty($alert)) { +if (empty($email_to) || empty($email_from) || empty($mail['server'])) { echo ' <div class="alert alert-warning"> <i class="fa fa-warning"></i> - <b>'.tr('Attenzione!').'</b> '.tr('Per utilizzare correttamente il modulo di segnalazione bug devi configurare alcuni parametri email nella scheda Impostazioni').'. - '.Modules::link('Impostazioni', $dbo->fetchArray("SELECT `idimpostazione` FROM `zz_settings` WHERE sezione='Email'")[0]['idimpostazione'], tr('Correggi'), null, 'class="btn btn-warning pull-right"').' + <b>'.tr('Attenzione!').'</b> '.tr('Per utilizzare correttamente il modulo di segnalazione bug devi configurare alcuni parametri riguardanti le impostazione delle email').'.'; + + if (empty($email_to) || empty($email_from)) { + echo Modules::link('Impostazioni', $dbo->fetchArray("SELECT `idimpostazione` FROM `zz_settings` WHERE sezione='Email'")[0]['idimpostazione'], tr('Correggi impostazioni'), null, 'class="btn btn-warning pull-right"'); + } + + if (empty($mail['server'])) { + echo Modules::link('Account email', $mail['id'], tr('Correggi account'), null, 'class="btn btn-warning pull-right"'); + } + + echo ' <div class="clearfix"></div> </div>'; } diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index b05d6a98d..9a9cd1669 100644 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -28,8 +28,13 @@ switch (post('op')) { 'from_address' => $post['from_address'], 'encryption' => $post['encryption'], 'pec' => $post['pec'], + 'main' => $post['main'], ], ['id' => $id_record]); + if (!empty($post['main'])) { + $dbo->query('UPDATE zz_smtp SET main = 0 WHERE id != '.prepare($id_record)); + } + $_SESSION['infos'][] = tr('Informazioni salvate correttamente!'); break; diff --git a/modules/smtp/edit.php b/modules/smtp/edit.php index 195e12d83..5cc2f98d1 100644 --- a/modules/smtp/edit.php +++ b/modules/smtp/edit.php @@ -20,12 +20,16 @@ include_once __DIR__.'/../../core.php'; <div class="clearfix"></div><br> <div class="row"> - <div class="col-md-9"> + <div class="col-md-6"> {[ "type": "text", "label": "<?php echo tr('Nome account') ?>", "name": "name", "value": "$name$", "required": 1 ]} </div> <div class="col-md-3"> - {[ "type": "checkbox", "label": "<?php echo tr('Indirizzo PEC') ?>", "name": "pec", "value": "$pec$", "placeholder": "PEC" ]} + {[ "type": "checkbox", "label": "<?php echo tr('Indirizzo PEC') ?>", "name": "pec", "value": "$pec$" ]} + </div> + + <div class="col-md-3"> + {[ "type": "checkbox", "label": "<?php echo tr('Indirizzo predefinito') ?>", "name": "main", "value": "$main$" ]} </div> </div> diff --git a/src/Mail.php b/src/Mail.php index 8487781e4..8afb6537c 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -7,20 +7,66 @@ */ class Mail extends PHPMailer { + /** @var array Elenco degli account email disponibili */ + protected static $accounts = []; + protected $infos = []; - public function __construct($exceptions = null) + /** + * Restituisce tutte le informazioni di tutti i plugin installati. + * + * @return array + */ + public static function getAccounts() + { + if (empty(self::$accounts)) { + $database = Database::getConnection(); + + $results = $database->fetchArray('SELECT * FROM zz_smtp WHERE deleted = 0'); + + $accounts = []; + + foreach ($results as $result) { + $accounts[$result['id']] = $result; + $accounts[$result['name']] = $result['id']; + + if (!empty($result['main'])) { + $accounts['default'] = $result['id']; + } + } + + self::$accounts = $accounts; + } + + return self::$accounts; + } + + /** + * Restituisce le informazioni relative a un singolo modulo specificato. + * + * @param string|int $plugin + * + * @return array + */ + public static function get($account = null) + { + if (!is_numeric($account) && !empty(self::getAccounts()[$account])) { + $account = self::getAccounts()[$account]; + } + + if (empty($account)) { + $account = self::getAccounts()['default']; + } + + return self::getAccounts()[$account]; + } + + public function __construct($account = null, $exceptions = null) { parent::__construct($exceptions); // Configurazione di base - $config = [ - 'host' => Settings::get('Server SMTP'), - 'username' => Settings::get('Username SMTP'), - 'password' => Settings::get('Password SMTP'), - 'port' => Settings::get('Porta SMTP'), - 'secure' => Settings::get('Sicurezza SMTP'), - ]; + $config = self::get($account); // Preparazione email $this->IsHTML(true); @@ -46,8 +92,8 @@ class Mail extends PHPMailer } // Impostazioni di sicurezza - if (in_array(strtolower($config['secure']), ['ssl', 'tls'])) { - $this->SMTPSecure = strtolower($config['secure']); + if (in_array(strtolower($config['encryption']), ['ssl', 'tls'])) { + $this->SMTPSecure = strtolower($config['encryption']); } } diff --git a/src/Prints.php b/src/Prints.php index d0a47e930..1df55d485 100644 --- a/src/Prints.php +++ b/src/Prints.php @@ -52,7 +52,7 @@ class Prints * * @return array */ - public static function getPrint($print) + public static function get($print) { if (!is_numeric($print) && !empty(self::getPrints()[$print])) { $print = self::getPrints()[$print]; @@ -77,7 +77,7 @@ class Prints $result = []; foreach ((array) self::$modules[$module_id] as $value) { - $result[] = self::getPrint($value); + $result[] = self::get($value); } return $result; @@ -87,7 +87,7 @@ class Prints { ob_end_clean(); - $infos = self::getPrint($print); + $infos = self::get($print); Permissions::addModule($infos['id_module']); @@ -132,7 +132,7 @@ class Prints protected static function isOldStandard($print) { - $infos = self::getPrint($print); + $infos = self::get($print); return file_exists($infos['full_directory'].'/pdfgen.'.$infos['directory'].'.php') || file_exists($infos['full_directory'].'/custom/pdfgen.'.$infos['directory'].'.php'); } @@ -144,7 +144,7 @@ class Prints protected static function oldLoader($id_print, $id_record, $filename = null) { - $infos = self::getPrint($id_print); + $infos = self::get($id_print); $options = self::readOptions($infos['options']); $database = Database::getConnection(); @@ -199,7 +199,7 @@ class Prints protected static function loader($id_print, $id_record, $filename = null) { - $infos = self::getPrint($id_print); + $infos = self::get($id_print); $options = self::readOptions($infos['options']); $database = Database::getConnection(); @@ -341,7 +341,7 @@ class Prints public static function getHref($print, $id_record, $get = '') { - $infos = self::getPrint($print); + $infos = self::get($print); if (empty($infos)) { return false; @@ -366,7 +366,7 @@ class Prints public static function getLink($print, $id_record, $btn = null, $title = null, $icon = null, $get = '') { - $print = self::getPrint($print); + $print = self::get($print); if (empty($print)) { return false; diff --git a/templates/info.php b/templates/info.php index 7a2075f62..ef6df0011 100644 --- a/templates/info.php +++ b/templates/info.php @@ -89,7 +89,7 @@ $replaces = array_merge($replaces, [ 'default_footer' => include DOCROOT.'/templates/base/footer.php', 'docroot' => DOCROOT, 'rootdir' => ROOTDIR, - 'directory' => Prints::getPrint($id_print)['full_directory'], + 'directory' => Prints::get($id_print)['full_directory'], 'footer' => !empty($footer) ? $footer : '', 'dicitura_fissa_fattura' => get_var('Dicitura fissa fattura'), ]); diff --git a/update/2_3_1.sql b/update/2_3_1.sql index 18e20a545..6bf9e73b8 100644 --- a/update/2_3_1.sql +++ b/update/2_3_1.sql @@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS `zz_smtp` ( `from_address` varchar(255) NOT NULL, `encryption` enum('','tls','ssl') NOT NULL, `pec` tinyint(1) NOT NULL, + `main` tinyint(1) NOT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB; @@ -101,6 +102,7 @@ CREATE TABLE IF NOT EXISTS `zz_emails` ( `bcc` varchar(255) NOT NULL, `body` text NOT NULL, `read_notify` tinyint(1) NOT NULL, + `main` tinyint(1) NOT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE @@ -154,3 +156,13 @@ INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `option UPDATE `zz_modules` `t1` INNER JOIN `zz_modules` `t2` ON (`t1`.`name` = 'Account email' AND `t2`.`name` = 'Gestione email') SET `t1`.`parent` = `t2`.`id`; UPDATE `zz_modules` `t1` INNER JOIN `zz_modules` `t2` ON (`t1`.`name` = 'Template email' AND `t2`.`name` = 'Gestione email') SET `t1`.`parent` = `t2`.`id`; + +-- Importazione dell'account email di default +INSERT INTO `zz_smtp` (`id`, `name`, `server`, `port`, `username`, `password`, `encryption`, `main`) VALUES (NULL, 'Account email da Impostazioni', (SELECT `valore` FROM `zz_settings` WHERE `nome` = 'Server SMTP'), (SELECT `valore` FROM `zz_settings` WHERE `nome` = 'Porta SMTP'), (SELECT `valore` FROM `zz_settings` WHERE `nome` = 'Username SMTP'), (SELECT `valore` FROM `zz_settings` WHERE `nome` = 'Password SMTP'), (SELECT `valore` FROM `zz_settings` WHERE `nome` = 'Sicurezza SMTP'), 1); + +DELETE FROM `zz_settings` WHERE +(`nome` = 'Server SMTP') OR +(`nome` = 'Porta SMTP') OR +(`nome` = 'Username SMTP') OR +(`nome` = 'Password SMTP') OR +(`nome` = 'Sicurezza SMTP');