openstamanager/modules/smtp/actions.php

88 lines
2.7 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'add':
$dbo->insert('zz_smtps', [
2018-07-19 15:33:32 +02:00
'name' => post('name'),
'from_name' => post('from_name'),
'from_address' => post('from_address'),
]);
$id_record = $dbo->lastInsertedID();
2018-07-19 17:29:21 +02:00
flash()->info(tr('Nuovo account email aggiunto!'));
break;
case 'update':
2018-09-27 12:54:57 +02:00
$predefined = post('predefined');
if (!empty($predefined)) {
$dbo->query('UPDATE zz_smtps SET predefined = 0');
}
$dbo->update('zz_smtps', [
2018-07-19 15:33:32 +02:00
'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'),
2018-12-28 08:07:56 +01:00
'ssl_no_verify' => post('ssl_no_verify'),
2018-09-27 12:54:57 +02:00
'predefined' => $predefined,
], ['id' => $id_record]);
2018-07-19 17:29:21 +02:00
flash()->info(tr('Informazioni salvate correttamente!'));
2018-03-02 19:01:30 +01:00
// Validazione indirizzo email mittente
2018-07-19 15:33:32 +02:00
$check_email = Validate::isValidEmail(post('from_address'));
2018-03-02 19:01:30 +01:00
// Se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
if (!empty($check_email)) {
2018-07-19 17:29:21 +02:00
flash()->info(tr('Sintassi email verificata'));
if (is_object($check_email) && $check_email->smtp) {
if ($check_email->smtp_check) {
2018-07-19 17:29:21 +02:00
flash()->info(tr('SMTP email verificato'));
} elseif (!$check_email->smtp_check) {
2018-07-19 17:29:21 +02:00
flash()->warning(tr('SMTP email non verificato'));
} else {
2018-07-19 17:29:21 +02:00
flash()->error(tr("Attenzione: l'SMTP email _EMAIL_ sembra non essere valido", [
'_EMAIL_' => $check_email->email,
]));
}
2018-03-01 22:05:54 +01:00
}
} else {
2018-07-19 17:29:21 +02:00
flash()->error(tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [
'_EMAIL_' => $check_email->email,
]));
if (is_object($check_email) && !empty($check_email->error->info)) {
2018-07-19 17:29:21 +02:00
flash()->error($check_email->error->info);
}
}
break;
case 'test':
2018-06-29 16:19:48 +02:00
$mail = new Mail($id_record);
2019-04-12 01:11:32 +02:00
echo json_encode([
'test' => $mail->testSMTP(),
]);
2018-06-29 16:19:48 +02:00
break;
case 'delete':
2018-07-17 12:08:52 +02:00
$dbo->query('UPDATE zz_smtps SET deleted_at = NOW() WHERE id='.prepare($id_record));
2018-07-19 17:29:21 +02:00
flash()->info(tr('Account email eliminato!'));
break;
}