added prefernce business overview
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Salvataggio preferenze di layout per utente (usato da ui_layout.js).
|
||||
* POST action=save page=... layout={json}
|
||||
* POST action=reset page=...
|
||||
*/
|
||||
ob_start();
|
||||
include('include/headscript.php');
|
||||
require_once __DIR__ . '/class/UiPrefs.php';
|
||||
|
||||
while (ob_get_level()) ob_end_clean();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$uid = (int)($iduserlogin ?? 0);
|
||||
if ($uid <= 0 || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['ok' => false, 'message' => 'Sessione non valida']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$page = (string)($_POST['page'] ?? '');
|
||||
$action = (string)($_POST['action'] ?? '');
|
||||
|
||||
try {
|
||||
if (!UiPrefs::validPage($page)) throw new Exception('Pagina non valida');
|
||||
if ($action === 'save') {
|
||||
$raw = (string)($_POST['layout'] ?? '');
|
||||
if (strlen($raw) > 8000) throw new Exception('Layout troppo grande');
|
||||
$layout = json_decode($raw, true);
|
||||
if (!is_array($layout)) throw new Exception('Layout non valido');
|
||||
UiPrefs::save($pdo, $uid, $page, $layout);
|
||||
echo json_encode(['ok' => true]);
|
||||
} elseif ($action === 'reset') {
|
||||
UiPrefs::reset($pdo, $uid, $page);
|
||||
echo json_encode(['ok' => true]);
|
||||
} else {
|
||||
throw new Exception('Azione non valida');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['ok' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user