2017-09-22 11:13:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
switch (post('op')) {
|
|
|
|
case 'add':
|
|
|
|
$dbo->insert('zz_smtp', [
|
|
|
|
'name' => $post['name'],
|
|
|
|
'from_name' => $post['from_name'],
|
|
|
|
'from_address' => $post['from_address'],
|
|
|
|
]);
|
|
|
|
|
2018-05-12 10:50:51 +02:00
|
|
|
$id_record = $dbo->lastInsertedID();
|
2017-09-22 11:13:36 +02:00
|
|
|
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Nuovo account email aggiunto!'));
|
2017-09-22 11:13:36 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'update':
|
|
|
|
$dbo->update('zz_smtp', [
|
|
|
|
'name' => $post['name'],
|
|
|
|
'note' => $post['note'],
|
|
|
|
'server' => $post['server'],
|
|
|
|
'port' => $post['port'],
|
|
|
|
'username' => $post['username'],
|
|
|
|
'password' => $post['password'],
|
|
|
|
'from_name' => $post['from_name'],
|
|
|
|
'from_address' => $post['from_address'],
|
|
|
|
'encryption' => $post['encryption'],
|
|
|
|
'pec' => $post['pec'],
|
2017-09-22 15:16:56 +02:00
|
|
|
'main' => $post['main'],
|
2017-09-22 11:13:36 +02:00
|
|
|
], ['id' => $id_record]);
|
|
|
|
|
2017-09-22 15:16:56 +02:00
|
|
|
if (!empty($post['main'])) {
|
|
|
|
$dbo->query('UPDATE zz_smtp SET main = 0 WHERE id != '.prepare($id_record));
|
|
|
|
}
|
|
|
|
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Informazioni salvate correttamente!'));
|
2018-03-02 19:01:30 +01:00
|
|
|
|
|
|
|
// Validazione indirizzo email mittente
|
2018-06-26 14:26:40 +02:00
|
|
|
$check_email = Validate::isValidEmail($post['from_address']);
|
2018-06-08 01:19:20 +02:00
|
|
|
|
2018-03-02 19:01:30 +01:00
|
|
|
// Se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
|
2018-06-26 14:26:40 +02:00
|
|
|
if (!empty($check_email)) {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Sintassi email verificata'));
|
2018-06-08 01:19:20 +02:00
|
|
|
|
2018-06-26 14:26:40 +02:00
|
|
|
if (is_object($check_email) && $check_email->smtp) {
|
2018-06-08 01:19:20 +02:00
|
|
|
if ($check_email->smtp_check) {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('SMTP email verificato'));
|
2018-06-26 14:26:40 +02:00
|
|
|
} elseif (!$check_email->smtp_check) {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->warning(tr('SMTP email non verificato'));
|
2018-06-26 14:26:40 +02:00
|
|
|
} else {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->error(tr("Attenzione: l'SMTP email _EMAIL_ sembra non essere valido", [
|
|
|
|
'_EMAIL_' => $check_email->email,
|
|
|
|
]));
|
2018-06-08 01:19:20 +02:00
|
|
|
}
|
2018-03-01 22:05:54 +01:00
|
|
|
}
|
2018-06-26 14:26:40 +02:00
|
|
|
} else {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->error(tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [
|
2018-06-26 14:26:40 +02:00
|
|
|
'_EMAIL_' => $check_email->email,
|
2018-07-07 13:56:22 +02:00
|
|
|
]));
|
2018-03-01 20:35:25 +01:00
|
|
|
|
2018-06-26 14:26:40 +02:00
|
|
|
if (is_object($check_email) && !empty($check_email->error->info)) {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->error($check_email->error->info);
|
2018-06-08 01:19:20 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 14:26:40 +02:00
|
|
|
|
2018-06-29 16:19:48 +02:00
|
|
|
$mail = new Mail($id_record);
|
|
|
|
if ($mail->testSMTP()) {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Connessione SMTP riuscita'));
|
2018-06-29 16:19:48 +02:00
|
|
|
} else {
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->error(tr('Connessione SMTP non riuscita'));
|
2018-06-29 16:19:48 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 11:13:36 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$dbo->query('UPDATE zz_smtp SET deleted = 1 WHERE id='.prepare($id_record));
|
|
|
|
|
2018-07-07 13:56:22 +02:00
|
|
|
App::flash()->info(tr('Account email eliminato!'));
|
2017-09-22 11:13:36 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|