openstamanager/include/init/init.php

270 lines
9.7 KiB
PHP
Raw Normal View History

<?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/>.
*/
include_once __DIR__.'/../../core.php';
2024-03-22 15:52:24 +01:00
use Models\Group;
2024-03-05 16:01:45 +01:00
use Models\Module;
2024-03-12 11:32:08 +01:00
use Models\Setting;
2024-03-22 15:52:24 +01:00
use Modules\Anagrafiche\Tipo;
2024-02-05 17:07:33 +01:00
2018-07-03 14:46:39 +02:00
if (Update::isUpdateAvailable() || !$dbo->isInstalled()) {
return;
}
2024-04-18 17:44:05 +02:00
$id_tipo_azienda = Tipo::find((new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id))->id;
2024-03-28 10:42:22 +01:00
2024-02-05 17:07:33 +01:00
$has_azienda = $dbo->fetchNum('SELECT `an_anagrafiche`.`idanagrafica` FROM `an_anagrafiche`
2018-07-03 14:46:39 +02:00
LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica`
2024-02-05 17:07:33 +01:00
LEFT JOIN `an_tipianagrafiche` ON `an_tipianagrafiche`.`id`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`
2024-03-28 16:55:49 +01:00
LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id`=`an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang`='.prepare(Models\Locale::getDefault()->id).')
WHERE `an_tipianagrafiche`.`id` = '.$id_tipo_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-09 10:44:54 +02:00
$settings = [
2018-09-27 12:54:57 +02:00
'Regime Fiscale' => true,
'Tipo Cassa Previdenziale' => false,
2018-09-27 12:54:57 +02:00
'Conto predefinito fatture di vendita' => true,
'Conto predefinito fatture di acquisto' => true,
2022-01-29 19:58:06 +01:00
"Ritenuta d'acconto predefinita" => false,
2018-09-27 12:54:57 +02:00
"Causale ritenuta d'acconto" => false,
2019-08-02 13:21:21 +02:00
'Valuta' => true,
2020-02-28 00:22:12 +01:00
'Utilizza prezzi di vendita comprensivi di IVA' => false,
2023-06-12 12:36:55 +02:00
'Soft quota' => false,
2018-07-09 10:44:54 +02:00
];
2022-01-15 18:21:48 +01:00
if (!empty(setting("Ritenuta d'acconto predefinita"))) {
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) {
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');
2024-04-18 17:44:05 +02:00
$id_module = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id);
include base_dir().'/modules/anagrafiche/actions.php';
// Logo stampe
if (!empty($_FILES) && !empty($_FILES['blob']['name'])) {
$upload = Uploads::upload($_FILES['blob'], [
'name' => 'Logo stampe',
'id_module' => $id_module,
'id_record' => $id_record,
]);
Settings::setValue('Logo stampe', $upload->filename);
}
}
// Utente amministratore
if (!$has_user) {
2024-03-12 16:39:34 +01:00
$admin = Group::where('nome', '=', 'Amministratori')->first();
2019-02-21 15:41:27 +01:00
// Creazione utente Amministratore
$dbo->insert('zz_users', [
'username' => post('admin_username'),
'password' => Auth::hashPassword(post('admin_password')),
'email' => post('admin_email'),
'idgruppo' => $admin['id'],
2024-04-08 15:44:33 +02:00
'idanagrafica' => $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-09 10:44:54 +02:00
if (!$has_settings) {
2018-09-27 12:54:57 +02:00
foreach ($settings as $setting => $required) {
2024-03-12 15:14:30 +01:00
$setting = Setting::where('nome', '=', $setting)->first();
2018-07-09 10:44:54 +02:00
2024-03-12 11:32:08 +01:00
$value = post('setting')[$setting->id];
2018-09-27 15:50:03 +02:00
if (!empty($value)) {
2024-03-12 11:32:08 +01:00
Settings::setValue($setting->id, $value);
2018-09-27 15:50:03 +02:00
}
2018-07-09 10:44:54 +02:00
}
}
redirect(base_path(), 'js');
2024-01-15 15:30:45 +01:00
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 '
2024-05-16 18:02:50 +02:00
<div class="card card-center-large card-warning">
<div class="card-header text-center">
2021-08-06 10:41:53 +02:00
<img src="'.$img.'/logo_completo.png" class="logo-image" alt="'.tr('OSM Logo').'">
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">
<form action="" method="post" id="init-form" enctype="multipart/form-data">
<input type="hidden" name="action" value="init">';
if (!$has_user) {
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">'.tr('Amministrazione').'</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">
<div class="row">
2024-05-23 17:03:30 +02:00
<div class="col-md-4">
2024-05-16 18:02:50 +02:00
<div class="form-group">
<label for="admin_username">'.tr('Username').'</label>
<input type="text" class="form-control" id="admin_username" name="admin_username" placeholder="'.tr("Imposta l'username dell'amministratore").'" required>
</div>
</div>
2024-05-23 17:03:30 +02:00
<div class="col-md-4">
2023-03-10 10:12:12 +01:00
{[ "type": "password", "label": "'.tr('Password').'", "id": "password", "name": "admin_password", "value": "", "placeholder": "'.tr("Imposta la password dell'amministratore").'", "required": 1, "strength": "#config" ]}
</div>
2024-05-23 17:03:30 +02:00
<div class="col-md-4">
2024-05-16 18:02:50 +02:00
<div class="form-group">
<label for="admin_email">'.tr('Email').'</label>
<input type="email" class="form-control" id="admin_email" name="admin_email" placeholder="'.tr("Imposta l'indirizzo email dell'amministratore").'" required>
</div>
</div>
</div>
</div>
</div>';
}
if (!$has_azienda) {
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">'.tr('Azienda predefinita').'</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body" id="bs-popup">';
2024-04-18 17:44:05 +02:00
$idtipoanagrafica = (new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id);
$readonly_tipo = true;
ob_start();
include base_dir().'/modules/anagrafiche/add.php';
$anagrafica = ob_get_clean();
echo str_replace('</form>', '', $anagrafica);
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-success collapsed-card">
<div class="card-header">
<h3 class="card-title">'.tr('Logo stampe').'</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body collapse">
<div class="col-md-12">
2024-05-16 18:02:50 +02:00
<div class="form-group">
<label>'.tr('File').'</label>
<input type="file" class="form-control" name="blob">
</div>
</div>
2020-02-17 09:44:09 +01:00
2024-05-16 18:02:50 +02:00
<p>&nbsp;</p>
2024-05-23 17:03:30 +02:00
<div class="col-md-12 alert alert-info text-center">'.tr('Per impostare il logo delle stampe, caricare un file ".jpg". Risoluzione consigliata 302x111 pixel').'.
</div>
</div>
</div>';
echo '
</div>
</div>';
}
2018-07-09 10:44:54 +02:00
if (!$has_settings) {
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">'.tr('Impostazioni di base').'</h3>
2018-07-09 10:44:54 +02:00
</div>
2024-05-23 17:03:30 +02:00
<div class="card-body">
<div class="row">';
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))) {
2024-05-23 17:03:30 +02:00
echo '
<div class="col-md-4">
2019-07-22 18:54:32 +02:00
'.Settings::input($setting, $required).'
</div>';
2018-09-27 15:50:03 +02:00
}
2018-07-09 10:44:54 +02:00
}
2024-05-23 17:03:30 +02:00
echo ' </div>
</div>
2018-07-09 10:44:54 +02:00
</div>';
}
echo '
2024-05-23 17:03:30 +02:00
<!-- 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>
2024-05-23 17:03:30 +02:00
</div>
<script>
$(document).ready(function(){
$("button[type=submit]").not("#config").remove();
});
</script>
2019-07-26 18:05:19 +02:00
<script>$(document).ready(init)</script>';
include_once App::filepath('include|custom|', 'bottom.php');
2024-01-15 15:30:45 +01:00
exit;