1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-29 17:21:54 +01:00
openstamanager/modules/impostazioni/actions.php

104 lines
3.2 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/>.
*/
use Models\Setting;
include_once __DIR__.'/../../core.php';
switch (filter('op')) {
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;
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) {
$result = Settings::get($id);
2020-02-05 14:51:39 +01:00
if (preg_match("/multiple\[(.+?)\]/", $result['tipo'], $m)) {
2020-02-05 14:51:39 +01:00
$value = implode(',', $value);
}
//Se è un'impostazione editabile
if ($result->editable) {
$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'].'"',
]));
}
}
}
2018-07-09 10:44:54 +02:00
$is_all_valid &= $is_valid;
}
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!'));
}
break;
}