2017-09-22 11:13:36 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-09-22 11:13:36 +02:00
|
|
|
|
2021-09-23 17:13:19 +02:00
|
|
|
use Models\Module;
|
|
|
|
use Models\OAuth2;
|
|
|
|
use Modules\Emails\Account;
|
|
|
|
|
2017-09-22 11:13:36 +02:00
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2021-07-27 10:16:10 +02:00
|
|
|
switch (filter('op')) {
|
2017-09-22 11:13:36 +02:00
|
|
|
case 'add':
|
2019-08-26 18:02:05 +02:00
|
|
|
$dbo->insert('em_accounts', [
|
2018-07-19 15:33:32 +02:00
|
|
|
'name' => post('name'),
|
|
|
|
'from_name' => post('from_name'),
|
|
|
|
'from_address' => post('from_address'),
|
2017-09-22 11:13:36 +02:00
|
|
|
]);
|
|
|
|
|
2018-05-12 10:50:51 +02:00
|
|
|
$id_record = $dbo->lastInsertedID();
|
2017-09-22 11:13:36 +02:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Nuovo account email aggiunto!'));
|
2017-09-22 11:13:36 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'update':
|
2021-09-23 17:13:19 +02:00
|
|
|
$account = Account::find($id_record);
|
|
|
|
|
2018-09-27 12:54:57 +02:00
|
|
|
$predefined = post('predefined');
|
|
|
|
if (!empty($predefined)) {
|
2019-08-26 18:02:05 +02:00
|
|
|
$dbo->query('UPDATE em_accounts SET predefined = 0');
|
2018-09-27 12:54:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 10:16:10 +02:00
|
|
|
$abilita_oauth2 = post('abilita_oauth2');
|
|
|
|
|
2019-08-26 18:02:05 +02:00
|
|
|
$dbo->update('em_accounts', [
|
2018-07-19 15:33:32 +02:00
|
|
|
'name' => post('name'),
|
|
|
|
'note' => post('note'),
|
|
|
|
'server' => post('server'),
|
|
|
|
'port' => post('port'),
|
|
|
|
'username' => post('username'),
|
2023-11-17 16:41:52 +01:00
|
|
|
'password' => $_POST['password'],
|
2018-07-19 15:33:32 +02:00
|
|
|
'from_name' => post('from_name'),
|
|
|
|
'from_address' => post('from_address'),
|
|
|
|
'encryption' => post('encryption'),
|
|
|
|
'pec' => post('pec'),
|
2019-08-29 14:48:14 +02:00
|
|
|
'timeout' => post('timeout'),
|
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,
|
2017-09-22 11:13:36 +02:00
|
|
|
], ['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
|
|
|
|
2021-07-27 14:55:59 +02:00
|
|
|
// Rimozione informazioni OAuth2 in caso di disabilitazione
|
|
|
|
if (!$abilita_oauth2) {
|
2021-09-23 17:13:19 +02:00
|
|
|
$oauth2 = $account->oauth2;
|
|
|
|
if (!empty($oauth2)) {
|
|
|
|
$account->oauth2()->dissociate();
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$oauth2->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Aggiornamento delle informazioni per OAuth2
|
|
|
|
else {
|
|
|
|
$oauth2 = $account->oauth2 ?: OAuth2::build();
|
|
|
|
|
|
|
|
$oauth2->class = post('provider');
|
|
|
|
$oauth2->client_id = post('client_id');
|
|
|
|
$oauth2->client_secret = post('client_secret');
|
|
|
|
$oauth2->config = post('config');
|
|
|
|
|
|
|
|
// Link di redirect dopo la configurazione
|
2024-03-27 16:59:46 +01:00
|
|
|
$id_modulo_account_email = (new Module())->getByField('name', 'Account email', Models\Locale::getPredefined()->id);
|
2024-03-05 16:01:45 +01:00
|
|
|
$oauth2->after_configuration = base_path().'/editor.php?id_module='.$id_modulo_account_email.'&id_record='.$id_record;
|
2021-09-23 17:13:19 +02:00
|
|
|
|
|
|
|
$oauth2->save();
|
|
|
|
|
|
|
|
// Associazione Account-OAuth2
|
|
|
|
$account->oauth2()->associate($oauth2);
|
|
|
|
$account->save();
|
2021-07-27 14:55:59 +02:00
|
|
|
}
|
|
|
|
|
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'));
|
2019-11-19 16:08:40 +01:00
|
|
|
|
2019-09-19 10:42:20 +02:00
|
|
|
// Controllo sulla validazione
|
2019-11-19 16:08:40 +01:00
|
|
|
if (!empty($check_email['valid-format'])) {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Sintassi email verificata'));
|
2019-11-19 16:08:40 +01:00
|
|
|
} else {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->error(tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [
|
2019-10-29 11:18:15 +01:00
|
|
|
'_EMAIL_' => post('from_address'),
|
2018-07-07 13:56:22 +02:00
|
|
|
]));
|
2019-09-19 10:42:20 +02:00
|
|
|
}
|
2018-03-01 20:35:25 +01:00
|
|
|
|
2019-09-19 10:42:20 +02:00
|
|
|
// Controllo sulla verifica
|
|
|
|
if (!empty($check_email['smtp-check'])) {
|
|
|
|
flash()->info(tr('SMTP email verificato'));
|
|
|
|
} else {
|
|
|
|
flash()->warning(tr('SMTP email non verificato'));
|
2018-06-08 01:19:20 +02:00
|
|
|
}
|
2018-06-26 14:26:40 +02:00
|
|
|
|
2019-07-25 17:20:24 +02:00
|
|
|
if (isAjaxRequest()) {
|
|
|
|
echo json_encode(['id' => $id_record]);
|
|
|
|
}
|
|
|
|
|
2019-04-05 04:52:15 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'test':
|
2020-07-08 09:26:17 +02:00
|
|
|
$result = $account->testConnection();
|
2019-04-05 04:52:15 +02:00
|
|
|
|
2019-04-12 01:11:32 +02:00
|
|
|
echo json_encode([
|
2020-07-08 09:26:17 +02:00
|
|
|
'test' => $result,
|
2019-04-05 04:52:15 +02:00
|
|
|
]);
|
2018-06-29 16:19:48 +02:00
|
|
|
|
2017-09-22 11:13:36 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
2020-07-08 09:26:17 +02:00
|
|
|
$account->delete();
|
2017-09-22 11:13:36 +02:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Account email eliminato!'));
|
2017-09-22 11:13:36 +02:00
|
|
|
|
2021-07-27 10:16:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'oauth2':
|
2021-09-23 17:13:19 +02:00
|
|
|
$oauth2 = $account->oauth2;
|
2022-12-01 16:38:04 +01:00
|
|
|
redirect(base_path().'/oauth2.php?id='.$oauth2->id);
|
2021-07-27 10:16:10 +02:00
|
|
|
|
2017-09-22 11:13:36 +02:00
|
|
|
break;
|
|
|
|
}
|