getConnection();
if (!isset($iduserlogin)) {
header("Location: login.php");
exit;
}
if ((int)$kindofrole !== ROLE_ADMIN) {
header("Location: index.php");
exit;
}
function e(?string $v): string
{
return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}
function getFlash(): ?array
{
if (!isset($_SESSION['flash'])) return null;
$f = $_SESSION['flash'];
unset($_SESSION['flash']);
return $f;
}
// --- Filtri ---
$q_search = trim($_GET['q'] ?? '');
$q_active = $_GET['active'] ?? ''; // '', '1', '0'
$where = ["1=1"];
$params = [];
if ($q_search !== '') {
$where[] = "(sh.name LIKE ? OR sh.city LIKE ? OR sh.email LIKE ?)";
$like = '%' . $q_search . '%';
array_push($params, $like, $like, $like);
}
if ($q_active === '1' || $q_active === '0') {
$where[] = "sh.active = ?";
$params[] = (int)$q_active;
}
$whereSql = implode(' AND ', $where);
$sql = "
SELECT sh.id, sh.name, sh.city, sh.province, sh.address, sh.zip_code,
sh.phone, sh.email, sh.logo, sh.active, sh.created_at,
CONCAT(u.first_name, ' ', u.last_name) AS owner_name, u.email AS owner_email,
(SELECT COUNT(*) FROM staff st WHERE st.shop_id = sh.id) AS staff_count,
(SELECT COUNT(*) FROM appointments a WHERE a.shop_id = sh.id) AS appt_count
FROM shops sh
LEFT JOIN auth_users u ON sh.owner_id = u.id
WHERE $whereSql
ORDER BY sh.created_at DESC
";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$shops = $stmt->fetchAll(PDO::FETCH_ASSOC);
$flash = getFlash();
$ret = http_build_query(array_filter(['q' => $q_search, 'active' => $q_active], fn($v) => $v !== '' && $v !== null));
?>
Gestione Saloni
= e($flash['text']) ?>
| Salone |
Titolare |
Città |
Staff |
Appunt. |
Stato |
Azioni |
| Nessun salone trovato. |
(int)$sh['id'],
'name' => $sh['name'],
'address' => $sh['address'],
'city' => $sh['city'],
'province' => $sh['province'],
'zip_code' => $sh['zip_code'],
'phone' => $sh['phone'],
'email' => $sh['email'],
], JSON_UNESCAPED_UNICODE));
?>
= e($initial) ?>
= e($sh['name']) ?>
= e($sh['email'] ?: '—') ?>
|
= e($sh['owner_name'] ?: '—') ?>
= e($sh['owner_email'] ?: '') ?>
|
= e($sh['city']) ?>= $sh['province'] ? ' (' . e($sh['province']) . ')' : '' ?> |
= (int)$sh['staff_count'] ?> |
= (int)$sh['appt_count'] ?> |
= $isOn ? 'Attivo' : 'Disattivato' ?>
|
|