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 Modules\Emails\Account ;
2021-07-27 10:16:10 +02:00
2017-09-22 11:13:36 +02:00
include_once __DIR__ . '/../../core.php' ;
2021-07-27 10:16:10 +02:00
echo '
2018-02-23 16:04:50 +01:00
< form action = " " method = " post " id = " edit-form " >
2017-09-22 11:13:36 +02:00
< input type = " hidden " name = " op " value = " update " >
< input type = " hidden " name = " backto " value = " record-edit " >
<!-- DATI -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2021-07-27 10:16:10 +02:00
< h3 class = " panel-title " > '.tr(' Dati ').' </ h3 >
2017-09-22 11:13:36 +02:00
</ div >
< div class = " panel-body " >
< div class = " row " >
2017-09-22 15:16:56 +02:00
< div class = " col-md-6 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " text " , " label " : " '.tr('Nome account').' " , " name " : " name " , " value " : " $name $ " , " required " : 1 ]}
2017-09-22 11:13:36 +02:00
</ div >
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Indirizzo PEC').' " , " name " : " pec " , " value " : " $pec $ " ]}
2017-09-22 15:16:56 +02:00
</ div >
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Indirizzo predefinito').' " , " name " : " predefined " , " value " : " $predefined $ " , " help " : " '.tr('Account da utilizzare per l \ 'invio di tutte le email dal gestionale.').' " ]}
2017-09-22 11:13:36 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-6 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " text " , " label " : " '.tr('Nome visualizzato').' " , " name " : " from_name " , " value " : " $from_name $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
2018-12-27 19:08:23 +01:00
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " email " , " label " : " '.tr('Email mittente').' " , " name " : " from_address " , " value " : " $from_address $ " , " required " : 1 ]}
2017-09-22 11:13:36 +02:00
</ div >
2019-08-26 18:02:05 +02:00
2018-12-27 19:08:23 +01:00
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Non verificare il certificato SSL').' " , " name " : " ssl_no_verify " , " value " : " $ssl_no_verify $ " ]}
2018-12-27 19:08:23 +01:00
</ div >
2019-08-26 18:02:05 +02:00
2017-09-22 11:13:36 +02:00
</ div >
< div class = " row " >
< div class = " col-md-6 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " text " , " label " : " '.tr('Server SMTP').' " , " name " : " server " , " required " : 1 , " value " : " $server $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " number " , " label " : " '.tr('Porta SMTP').' " , " name " : " port " , " required " : 1 , " class " : " text-center " , " decimals " : " 0 " , " max-value " : " 65535 " , " value " : " $port $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " select " , " label " : " '.tr('Sicurezza SMTP').' " , " name " : " encryption " , " values " : " list= \" \" : \" '.tr('Nessuna').' \" , \" tls \" : \" TLS \" , \" ssl \" : \" SSL \" " , " value " : " $encryption $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-6 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " text " , " label " : " '.tr('Username SMTP').' " , " name " : " username " , " value " : " $username $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
2019-08-29 14:48:14 +02:00
< div class = " col-md-3 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " password " , " label " : " '.tr('Password SMTP').' " , " name " : " password " , " value " : " $password $ " ]}
2019-08-29 14:48:14 +02:00
</ div >
< div class = " col-md-3 " >
2024-02-02 14:15:50 +01:00
{[ " type " : " number " , " label " : " '.tr('Timeout coda di invio (millisecondi)').' " , " name " : " timeout " , " value " : " $timeout $ " , " decimals " : 0 , " min-value " : 100 ]}
2017-09-22 11:13:36 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2021-07-27 10:16:10 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Note').' " , " name " : " note " , " value " : " $note $ " ]}
2017-09-22 11:13:36 +02:00
</ div >
</ div >
</ div >
2021-07-27 10:16:10 +02:00
</ div > ' ;
// Elenco provider disponibili
2021-09-23 17:13:19 +02:00
$providers = Account :: $providers ;
2021-07-27 10:16:10 +02:00
$elenco_provider = [];
foreach ( $providers as $key => $provider ) {
$elenco_provider [] = [
2021-09-23 17:13:19 +02:00
'id' => $provider [ 'class' ],
'short' => $key ,
2021-07-27 10:16:10 +02:00
'text' => $provider [ 'name' ],
'help' => $provider [ 'help' ],
];
}
2021-09-23 17:13:19 +02:00
$oauth2 = $account -> oauth2 ;
2021-07-27 10:16:10 +02:00
echo '
<!-- OAuth2 -->
< div class = " box box-info " >
< div class = " box-header " >
< h3 class = " box-title " > '.tr(' OAuth2 ').' </ h3 >
</ div >
< div class = " box-body " >
< div class = " row " >
< div class = " col-md-6 " >
2021-08-05 11:08:35 +02:00
< span class = " label label-warning pull-right hidden " id = " guida-configurazione " ></ span >
2021-09-23 17:13:19 +02:00
{[ " type " : " select " , " label " : " '.tr('Provider account').' " , " name " : " provider " , " value " : '.json_encode($oauth2->class).' , " values " : '.json_encode($elenco_provider).' , " disabled " : " '.intval(empty( $oauth2 )).' " ]}
2021-07-27 10:16:10 +02:00
</ div >
2017-09-22 11:13:36 +02:00
2021-07-27 10:16:10 +02:00
< div class = " col-md-3 " >
2021-09-23 17:13:19 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Abilita OAuth2').' " , " name " : " abilita_oauth2 " , " value " : " '.intval(!empty( $oauth2 )).' " ]}
2021-07-27 10:16:10 +02:00
</ div >
2021-09-23 17:13:19 +02:00
< div class = " col-md-3 oauth2-config " >
2022-06-15 17:38:40 +02:00
< a type = " button " class = " btn btn-success btn-block '.(empty( $oauth2->class ) || empty( $oauth2->client_id ) || empty( $oauth2->client_secret ) ? 'disabled' : '').' " style = " margin-top: 25px " href = " '.base_url().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=oauth2 " target = " _blank " >
2021-09-23 17:13:19 +02:00
< i class = " fa fa-refresh " ></ i > '.(empty($oauth2->access_token) ? tr(' Completa configurazione ') : tr(' Ripeti configurazione ')).'
</ a >
</ div >
</ div >
2021-07-27 10:16:10 +02:00
2021-09-23 17:13:19 +02:00
< div class = " row oauth2-config " >
< div class = " col-md-6 " >
{[ " type " : " text " , " label " : " '.tr('Client ID').' " , " name " : " client_id " , " value " : " '. $oauth2->client_id .' " , " disabled " : " '.intval(empty( $oauth2 )).' " ]}
</ div >
2021-08-30 16:01:25 +02:00
2021-09-23 17:13:19 +02:00
< div class = " col-md-6 " >
{[ " type " : " text " , " label " : " '.tr('Client Secret').' " , " name " : " client_secret " , " value " : " '. $oauth2->client_secret .' " , " disabled " : " '.intval(empty( $oauth2 )).' " ]}
2021-08-30 16:08:40 +02:00
</ div >
2021-09-23 17:13:19 +02:00
< div id = " provider-config " ></ div >
2021-07-27 10:16:10 +02:00
</ div >
2021-08-05 11:08:35 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr(' Durante la procedura di configurazione verrà effettuato il logout dal gestionale ').' .
</ div >
2021-07-27 10:16:10 +02:00
</ div >
</ div >
2021-08-30 16:01:25 +02:00
</ form > ' ;
// Inizializzazione dei form per campi personalizzati
foreach ( $providers as $key => $provider ) {
echo '
< div class = " hidden " id = " provider-'. $key .' " > ' ;
$config = $provider [ 'class' ] :: getConfigInputs ();
foreach ( $config as $name => $field ) {
$field [ 'name' ] = 'config[' . $name . ']' ;
2021-09-23 17:13:19 +02:00
$field [ 'value' ] = $oauth2 ? $oauth2 -> config [ $name ] : null ;
2021-08-30 16:01:25 +02:00
echo '
< div class = " col-md-6 " > '.input($field).' </ div > ' ;
}
echo '
</ div > ' ;
}
2017-09-22 11:13:36 +02:00
2021-08-30 16:01:25 +02:00
echo '
2021-07-27 10:16:10 +02:00
< script >
var abilita_oauth2 = input ( " abilita_oauth2 " );
var provider = input ( " provider " );
var client_id = input ( " client_id " );
var client_secret = input ( " client_secret " );
var guida = $ ( " #guida-configurazione " );
2021-08-30 16:08:40 +02:00
var config = $ ( " #provider-config " );
2021-07-27 10:16:10 +02:00
abilita_oauth2 . change ( function () {
const disable = ! abilita_oauth2 . get ();
provider . setDisabled ( disable );
2021-09-23 17:13:19 +02:00
const inputs = $ ( " .oauth2-config .openstamanager-input " );
2021-08-30 16:08:40 +02:00
for ( i of inputs ) {
input ( i ) . setDisabled ( disable );
}
2021-07-27 10:16:10 +02:00
});
provider . change ( function () {
const data = provider . getData ();
if ( data . id ) {
guida . removeClass ( " hidden " );
guida . html ( `<a href="${data.help}">'.tr('Istruzioni di configurazione').' <i class="fa fa-external-link"></i></a>` );
} else {
guida . addClass ( " hidden " );
}
2021-08-30 16:01:25 +02:00
// Impostazione dei dati aggiuntivi da configurare
config . html ( " " )
2023-07-11 10:10:35 +02:00
aggiungiContenuto ( config , " #provider- " + data . short , {}, true );
2021-07-27 10:16:10 +02:00
})
$ ( document ) . ready ( function () {
provider . trigger ( " change " );
})
</ script > ' ;
2018-09-05 10:43:12 +02:00
// Collegamenti diretti
// Template email collegati a questo account
2024-03-13 11:38:29 +01:00
$elementi = $dbo -> fetchArray ( 'SELECT `em_templates`.`id`, `em_templates_lang`.`name` FROM `em_templates` LEFT JOIN `em_templates_lang` ON (`em_templates`.`id` = `em_templates_lang`.`id_record` AND `em_templates_lang`.`id_lang` = ' . prepare ( \App :: getLang ()) . ') WHERE `id_account` = ' . prepare ( $id_record ));
2018-09-05 10:43:12 +02:00
if ( ! empty ( $elementi )) {
echo '
< div class = " box box-warning collapsable collapsed-box " >
< div class = " box-header with-border " >
< h3 class = " box-title " >< i class = " fa fa-warning " ></ i > '.tr(' Template email collegati : _NUM_ ' , [
2018-09-19 09:57:30 +02:00
'_NUM_' => count ( $elementi ),
2018-09-05 10:43:12 +02:00
]) . ' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
</ div >
</ div >
< div class = " box-body " >
< ul > ' ;
foreach ( $elementi as $elemento ) {
echo '
< li > '.Modules::link(' Template email ', $elemento[' id '], $elemento[' name ']).' </ li > ' ;
}
echo '
</ ul >
</ div >
</ div > ' ;
} else {
echo '
2017-09-22 11:13:36 +02:00
< a class = " btn btn-danger ask " data - backto = " record-list " >
2018-09-05 10:43:12 +02:00
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a > ' ;
}