2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
|
|
|
* Copyright (C) DevCode s.n.c.
|
|
|
|
*
|
|
|
|
* 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-08-04 16:28:16 +02:00
|
|
|
|
2020-10-16 21:35:19 +02:00
|
|
|
use Models\Setting;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
switch (filter('op')) {
|
2020-10-16 21:35:19 +02:00
|
|
|
case 'salva':
|
|
|
|
$id = filter('id');
|
|
|
|
$valore = filter('valore');
|
|
|
|
|
|
|
|
$impostazione = Setting::find($id);
|
|
|
|
if (!$impostazione->editable) {
|
|
|
|
echo json_encode([
|
|
|
|
'result' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = Settings::setValue($impostazione->id, $valore);
|
|
|
|
echo json_encode([
|
|
|
|
'result' => $result,
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
flash()->info('Impostazione modificata con successo!');
|
|
|
|
} else {
|
|
|
|
flash()->error('Errore durante il salvataggio!');
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ricerca':
|
|
|
|
$search = filter('search');
|
|
|
|
$sezioni = Setting::select('sezione')
|
|
|
|
->where('sezione', 'like', '%'.$search.'%')
|
|
|
|
->orWhere('nome', 'like', '%'.$search.'%')
|
|
|
|
->groupBy(['sezione'])
|
|
|
|
->get()->pluck('sezione');
|
|
|
|
|
|
|
|
echo json_encode($sezioni);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
case 'update':
|
2018-07-09 10:44:54 +02:00
|
|
|
$is_all_valid = true;
|
|
|
|
|
2018-08-11 15:37:38 +02:00
|
|
|
foreach (post('setting') as $id => $value) {
|
2020-01-30 13:53:45 +01:00
|
|
|
$result = Settings::get($id);
|
2020-02-05 14:51:39 +01:00
|
|
|
|
2020-01-30 13:53:45 +01:00
|
|
|
if (preg_match("/multiple\[(.+?)\]/", $result['tipo'], $m)) {
|
2020-02-05 14:51:39 +01:00
|
|
|
$value = implode(',', $value);
|
2020-01-30 13:53:45 +01:00
|
|
|
}
|
|
|
|
|
2020-02-07 18:13:48 +01:00
|
|
|
//Se è un'impostazione editabile
|
2020-02-11 11:43:59 +01:00
|
|
|
if ($result->editable) {
|
2020-02-07 18:13:48 +01:00
|
|
|
$is_valid = Settings::setValue($id, $value);
|
|
|
|
|
|
|
|
if (!$is_valid) {
|
|
|
|
// integer
|
|
|
|
if ($result['tipo'] == 'integer') {
|
|
|
|
flash()->error(tr('Il valore inserito del parametro _NAME_ deve essere un numero intero!', [
|
|
|
|
'_NAME_' => '"'.$result['nome'].'"',
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// list
|
|
|
|
// verifico che il valore scelto sia nella lista enumerata nel db
|
|
|
|
elseif (preg_match("/list\[(.+?)\]/", $result['tipo'], $m)) {
|
|
|
|
flash()->error(tr('Il valore inserito del parametro _NAME_ deve essere un compreso tra i valori previsti!', [
|
|
|
|
'_NAME_' => '"'.$result['nome'].'"',
|
|
|
|
]));
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 10:44:54 +02:00
|
|
|
$is_all_valid &= $is_valid;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 10:44:54 +02:00
|
|
|
if ($is_all_valid) {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Impostazioni aggiornate correttamente!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|