2018-07-03 11:12:32 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2018-07-03 14:46:39 +02:00
if ( Update :: isUpdateAvailable () || ! $dbo -> isInstalled ()) {
return ;
}
$has_azienda = $dbo -> fetchNum ( " SELECT `an_anagrafiche`.`idanagrafica` FROM `an_anagrafiche`
LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche` . `idanagrafica` = `an_tipianagrafiche_anagrafiche` . `idanagrafica`
LEFT JOIN `an_tipianagrafiche` ON `an_tipianagrafiche` . `idtipoanagrafica` = `an_tipianagrafiche_anagrafiche` . `idtipoanagrafica`
2018-07-17 11:15:31 +02:00
WHERE `an_tipianagrafiche` . `descrizione` = 'Azienda' AND `an_anagrafiche` . `deleted_at` IS NULL " ) != 0;
2018-07-03 14:46:39 +02:00
$has_user = $dbo -> fetchNum ( 'SELECT `id` FROM `zz_users`' ) != 0 ;
2018-07-03 11:12:32 +02:00
2018-07-09 10:44:54 +02:00
$settings = [
2018-09-27 12:54:57 +02:00
'Regime Fiscale' => true ,
'Tipo Cassa' => true ,
'Conto predefinito fatture di vendita' => true ,
'Conto predefinito fatture di acquisto' => true ,
" Percentuale ritenuta d'acconto " => false ,
" Causale ritenuta d'acconto " => false ,
2018-07-09 10:44:54 +02:00
];
2018-09-27 15:50:03 +02:00
if ( ! empty ( setting ( " Percentuale ritenuta d'acconto " ))) {
2018-09-27 12:54:57 +02:00
$settings [ " Causale ritenuta d'acconto " ] = true ;
}
2018-07-09 10:44:54 +02:00
$has_settings = true ;
2018-09-27 12:54:57 +02:00
foreach ( $settings as $setting => $required ) {
if ( empty ( setting ( $setting )) && $required ) {
2018-07-09 10:44:54 +02:00
$has_settings = false ;
break ;
}
}
if ( $has_azienda && $has_user && $has_settings ) {
2018-07-03 11:12:32 +02:00
return ;
}
$pageTitle = tr ( 'Inizializzazione' );
include_once App :: filepath ( 'include|custom|' , 'top.php' );
// Controllo sull'esistenza di nuovi parametri di configurazione
if ( post ( 'action' ) == 'init' ) {
// Azienda predefinita
if ( ! $has_azienda ) {
Filter :: set ( 'post' , 'op' , 'add' );
$id_module = Modules :: get ( 'Anagrafiche' )[ 'id' ];
include DOCROOT . '/modules/anagrafiche/actions.php' ;
// Logo stampe
if ( ! empty ( $_FILES ) && ! empty ( $_FILES [ 'blob' ][ 'name' ])) {
2018-07-03 21:22:29 +02:00
$file = Uploads :: upload ( $_FILES [ 'blob' ], [
2018-07-03 11:12:32 +02:00
'name' => 'Logo stampe' ,
'id_module' => $id_module ,
'id_record' => $id_record ,
]);
2018-07-09 10:44:54 +02:00
Settings :: setValue ( 'Logo stampe' , $file );
2018-07-03 11:12:32 +02:00
}
}
// Utente amministratore
if ( ! $has_user ) {
$admin = $dbo -> selectOne ( 'zz_groups' , [ 'id' ], [
'nome' => 'Amministratori' ,
]);
2019-02-21 15:41:27 +01:00
// Creazione utente Amministratore
2018-07-03 11:12:32 +02:00
$dbo -> insert ( 'zz_users' , [
'username' => post ( 'admin_username' ),
'password' => Auth :: hashPassword ( post ( 'admin_password' )),
'email' => post ( 'admin_email' ),
'idgruppo' => $admin [ 'id' ],
'idanagrafica' => isset ( $id_record ) ? $id_record : 0 ,
'enabled' => 1 ,
]);
2019-02-21 15:41:27 +01:00
// Creazione token API per l'amministratore
$dbo -> insert ( 'zz_tokens' , [
'id_utente' => $dbo -> lastInsertedID (),
'token' => secure_random_string (),
]);
2018-07-03 11:12:32 +02:00
}
2018-07-09 10:44:54 +02:00
if ( ! $has_settings ) {
2018-09-27 12:54:57 +02:00
foreach ( $settings as $setting => $required ) {
2018-07-09 10:44:54 +02:00
$setting = Settings :: get ( $setting );
2018-09-27 15:50:03 +02:00
$value = post ( 'setting' )[ $setting [ 'id' ]];
if ( ! empty ( $value )) {
Settings :: setValue ( $setting [ 'nome' ], $value );
}
2018-07-09 10:44:54 +02:00
}
}
2018-07-03 11:12:32 +02:00
redirect ( ROOTDIR , 'js' );
exit ();
}
$img = App :: getPaths ()[ 'img' ];
// Visualizzazione dell'interfaccia di impostazione iniziale, nel caso il file di configurazione sia mancante oppure i paramentri non siano sufficienti
echo '
< div class = " box box-center-large box-warning " >
< div class = " box-header with-border text-center " >
< img src = " '. $img .'/logo.png " alt = " '.tr('OSM Logo').' " >
< h3 class = " box-title " > '.tr(' OpenSTAManager ').' </ h3 >
</ div >
< div class = " box-body " >
< form action = " " method = " post " id = " init-form " enctype = " multipart/form-data " >
< input type = " hidden " name = " action " value = " init " > ' ;
if ( ! $has_user ) {
echo '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Amministrazione ').' </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " text " , " label " : " '.tr('Username').' " , " name " : " admin_username " , " value " : " '. $osm_password .' " , " placeholder " : " '.tr( " Digita l 'username dell' amministratore " ).' " , " required " : 1 ]}
</ div >
< div class = " col-md-6 " >
2019-01-03 12:57:17 +01:00
{[ " type " : " password " , " label " : " '.tr('Password').' " , " id " : " password " , " name " : " admin_password " , " value " : " '. $osm_password .' " , " placeholder " : " '.tr( " Digita la password dell 'amministratore").' " , " required " : 1, " icon - after " : " < i onclick = \ " if ( $ (this).parent().find( \ 'i \ ').hasClass( \ 'fa-eye \ ')) { $ ( \ '#password \ ').attr( \ 'type \ ', \ 'text \ '); $ (this).parent().find( \ 'i \ ').removeClass( \ 'fa-eye \ ').addClass( \ 'fa-eye-slash \ '); $ (this).parent().find( \ 'i \ ').attr( \ 'title \ ', \ 'Nascondi password \ '); } else { $ ( \ '#password \ ').attr( \ 'type \ ', \ 'password \ '); $ (this).parent().find( \ 'i \ ').removeClass( \ 'fa-eye-slash \ ').addClass( \ 'fa-eye \ '); $ (this).parent().find( \ 'i \ ').attr( \ 'title \ ', \ 'Visualizza password \ '); } \" title= \" '.tr('Visualizza password').' \" class= \" fa fa-eye clickable \" ></i> " ]}
2018-07-03 11:12:32 +02:00
</ div >
< div class = " col-md-6 " >
{[ " type " : " email " , " label " : " '.tr('Email').' " , " name " : " admin_email " , " value " : " '. $osm_email .' " , " placeholder " : " '.tr( " Digita l 'indirizzo email dell' amministratore " ).' " ]}
</ div >
</ div >
</ div >
</ div > ' ;
}
if ( ! $has_azienda ) {
echo '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Azienda predefinita ').' </ h3 >
</ div >
< div class = " panel-body " > ' ;
$idtipoanagrafica = $dbo -> fetchArray ( " SELECT idtipoanagrafica FROM an_tipianagrafiche WHERE descrizione='Azienda' " )[ 0 ][ 'idtipoanagrafica' ];
$readonly_tipo = true ;
ob_start ();
include DOCROOT . '/modules/anagrafiche/add.php' ;
$anagrafica = ob_get_clean ();
echo str_replace ( '</form>' , '' , $anagrafica );
echo '
< div class = " box box-success collapsed-box " >
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Logo stampe ').' </ 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 collapse " >
< div class = " col-md-12 " >
{[ " type " : " file " , " placeholder " : " '.tr('File').' " , " name " : " blob " ]}
</ div >
2019-01-03 12:57:17 +01:00
< p >& nbsp ; </ p >< div class = " col-md-12 alert alert-info text-center " > '.tr(' Per impostare il logo delle stampe , caricare un file " .jpg " . Risoluzione consigliata 302 x111 pixel ').' .</ div >
2018-07-03 11:12:32 +02:00
</ div >
</ div > ' ;
echo '
</ div >
</ div > ' ;
}
2018-07-09 10:44:54 +02:00
if ( ! $has_settings ) {
echo '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Impostazioni di base ').' </ h3 >
</ div >
< div class = " panel-body " > ' ;
2018-09-27 12:54:57 +02:00
foreach ( $settings as $setting => $required ) {
2018-09-27 15:50:03 +02:00
if ( empty ( setting ( $setting ))) {
echo '
2018-07-09 10:44:54 +02:00
< div class = " col-md-6 " >
2018-09-27 12:54:57 +02:00
'.Settings::input($setting, $required).'
2018-07-09 10:44:54 +02:00
</ div > ' ;
2018-09-27 15:50:03 +02:00
}
2018-07-09 10:44:54 +02:00
}
echo '
</ div >
</ div > ' ;
}
2018-07-03 11:12:32 +02:00
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-4 " >
< span >*< small >< small > '.tr(' Campi obbligatori ').' </ small ></ small ></ span >
</ div >
< div class = " col-md-4 text-right " >
< button type = " submit " id = " config " class = " btn btn-success btn-block " >
< i class = " fa fa-cog " ></ i > '.tr(' Configura ').'
</ button >
</ div >
</ div >
</ form >
</ div >
</ div > ' ;
echo '
< script >
$ ( document ) . ready ( function (){
$ ( " button[type=submit] " ) . not ( " #config " ) . remove ();
});
</ script >
< script src = " '. $rootdir .'/lib/functions.js " ></ script >
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;
include_once App :: filepath ( 'include|custom|' , 'bottom.php' );
exit ();