Initial import of fitme3070.pt platform
Plain-PHP fleet platform with id.andmore.pt SSO. Wires shared/platform-tools as a submodule (platform_update, backups, git/migration tools) like the other platforms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
e68d357177
2330 files changed
+215968
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../../config/db.php';
|
||||
require __DIR__ . '/../../../config/functions.php';
|
||||
$user = ["id"=>1,"name"=>"Teste","email"=>"teste@fitme3070.pt","role"=>"sysadmin"]; $_SESSION["user_id"] = 1; $_SESSION["user"] = $user; // require_admin();
|
||||
|
||||
$errors = [];
|
||||
$name = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
csrf_check();
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
if ($name === '') $errors[] = 'O nome é obrigatório.';
|
||||
if (!$errors) {
|
||||
$id = db_gallery_create($pdo, $name);
|
||||
session()->setFlashdata('success', 'Galeria criada.');
|
||||
header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page_title = 'Nova Galeria';
|
||||
include __DIR__ . '/../../../includes/header.php';
|
||||
?>
|
||||
<div class="container" style="max-width:500px;">
|
||||
<h1 class="h3 mb-4">Nova Galeria</h1>
|
||||
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
|
||||
|
||||
<form method="POST" class="card shadow-sm"><div class="card-body">
|
||||
<?= csrf_field() ?>
|
||||
<div class="mb-3"><label class="form-label">Nome da galeria <span class="text-danger">*</span></label>
|
||||
<input class="form-control" name="name" required value="<?= htmlspecialchars($name) ?>" placeholder="ex: Instalações">
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">Guardar</button>
|
||||
<a class="btn btn-outline-secondary" href="index.php">Cancelar</a>
|
||||
</div>
|
||||
</div></form>
|
||||
</div>
|
||||
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../../config/db.php';
|
||||
require __DIR__ . '/../../../config/functions.php';
|
||||
$user = ["id"=>1,"name"=>"Teste","email"=>"teste@fitme3070.pt","role"=>"sysadmin"]; $_SESSION["user_id"] = 1; $_SESSION["user"] = $user; // require_admin();
|
||||
|
||||
$id = (int) ($_GET['id'] ?? 0);
|
||||
if (!$id) { header('Location: index.php'); exit; }
|
||||
|
||||
$gallery = db_gallery_get($pdo, $id);
|
||||
if (!$gallery) { header('Location: index.php'); exit; }
|
||||
|
||||
$errors = [];
|
||||
$name = $gallery['name'];
|
||||
$images = db_gallery_images($pdo, $id);
|
||||
|
||||
// Rename gallery
|
||||
if (isset($_POST['rename'])) {
|
||||
csrf_check();
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
if ($name === '') $errors[] = 'O nome é obrigatório.';
|
||||
elseif (db_gallery_update($pdo, $id, $name)) {
|
||||
session()->setFlashdata('success', 'Galeria renomeada.');
|
||||
header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Upload image
|
||||
if (isset($_FILES['image']) && $_FILES['image']['error'] !== UPLOAD_ERR_NO_FILE) {
|
||||
csrf_check();
|
||||
$result = db_gallery_image_upload($pdo, $id, $_FILES['image']);
|
||||
if ($result) session()->setFlashdata('success', 'Imagem carregada.');
|
||||
else session()->setFlashdata('error', 'Falha no upload. Verifique o formato.');
|
||||
header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Optimize existing images (resize/compress to the gallery cap)
|
||||
if (isset($_POST['optimize'])) {
|
||||
csrf_check();
|
||||
$stats = img_optimize_dir(__DIR__ . '/../../../uploads/gallery/' . $id . '/', IMG_MAX_GALLERY);
|
||||
session()->setFlashdata($stats['failed'] ? 'warning' : 'success', img_stats_message($stats));
|
||||
header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete image
|
||||
if (isset($_GET['del_img']) && is_numeric($_GET['del_img'])) {
|
||||
csrf_check();
|
||||
db_gallery_image_delete($pdo, (int) $_GET['del_img'], $id);
|
||||
session()->setFlashdata('success', 'Imagem removida.');
|
||||
header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id));
|
||||
exit;
|
||||
}
|
||||
|
||||
$page_title = 'Gerir Galeria';
|
||||
include __DIR__ . '/../../../includes/header.php';
|
||||
?>
|
||||
<div class="container" style="max-width:900px;">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0"><?= htmlspecialchars($gallery['name']) ?></h1>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="index.php"><i class="bi bi-arrow-left me-1"></i>Voltar</a>
|
||||
</div>
|
||||
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-md-4">
|
||||
<div class="card shadow-sm"><div class="card-body">
|
||||
<h2 class="h6 mb-3">Renomear</h2>
|
||||
<form method="POST">
|
||||
<?= csrf_field() ?>
|
||||
<div class="mb-3">
|
||||
<input class="form-control" name="name" value="<?= htmlspecialchars($name) ?>">
|
||||
</div>
|
||||
<button type="submit" name="rename" class="btn btn-primary btn-sm">Renomear</button>
|
||||
</form>
|
||||
</div></div>
|
||||
|
||||
<div class="card shadow-sm mt-3"><div class="card-body">
|
||||
<h2 class="h6 mb-3">Adicionar imagem</h2>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<?= csrf_field() ?>
|
||||
<div class="mb-3">
|
||||
<input type="file" class="form-control" name="image" accept=".jpg,.jpeg,.png,.gif,.webp">
|
||||
<div class="form-text">JPG, PNG, GIF ou WebP.</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-sm"><i class="bi bi-cloud-arrow-up me-1"></i>Carregar</button>
|
||||
</form>
|
||||
</div></div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-sm"><div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h2 class="h6 mb-0">Imagens (<?= count($images) ?>)</h2>
|
||||
<?php if ($images): ?>
|
||||
<form method="POST" class="mb-0">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" name="optimize" value="1" class="btn btn-sm btn-outline-success"
|
||||
title="Redimensiona e comprime as imagens desta galeria para o máximo de <?= IMG_MAX_GALLERY ?>px"
|
||||
onclick="return confirm('Otimizar todas as imagens desta galeria (máx. <?= IMG_MAX_GALLERY ?>px)? Os ficheiros originais serão substituídos.')">
|
||||
<i class="bi bi-arrows-angle-contract me-1"></i>Otimizar imagens
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!$images): ?>
|
||||
<p class="text-muted">Nenhuma imagem nesta galeria.</p>
|
||||
<?php else: ?>
|
||||
<div class="row g-2">
|
||||
<?php foreach ($images as $img): ?>
|
||||
<div class="col-6 col-lg-4 position-relative">
|
||||
<img src="<?= base_url('uploads/gallery/' . $id . '/' . $img['i_file_name']) ?>"
|
||||
alt="" class="img-thumbnail w-100" style="height:140px;object-fit:cover;" loading="lazy">
|
||||
<a class="btn btn-sm btn-danger position-absolute top-0 end-0 m-1 rounded-circle"
|
||||
href="?id=<?= $id ?>&del_img=<?= $img['i_id'] ?>"
|
||||
onclick="return confirm('Remover esta imagem?')"
|
||||
style="width:28px;height:28px;display:flex;align-items:center;justify-content:center;font-size:12px">×</a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../../config/db.php';
|
||||
require __DIR__ . '/../../../config/functions.php';
|
||||
$user = ["id"=>1,"name"=>"Teste","email"=>"teste@fitme3070.pt","role"=>"sysadmin"]; $_SESSION["user_id"] = 1; $_SESSION["user"] = $user; // require_admin();
|
||||
|
||||
// Handle delete BEFORE any output
|
||||
if (isset($_GET['delete']) && is_numeric($_GET['delete'])) {
|
||||
csrf_check();
|
||||
db_gallery_delete($pdo, (int) $_GET['delete']);
|
||||
session()->setFlashdata('success', 'Galeria apagada.');
|
||||
header('Location: ' . base_url('views/admin/galerias/index.php'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Optimize every image in every gallery (resize/compress to the gallery cap)
|
||||
if (isset($_POST['optimize_all'])) {
|
||||
csrf_check();
|
||||
$stats = ['resized' => 0, 'skipped' => 0, 'failed' => 0, 'saved' => 0];
|
||||
foreach (glob(__DIR__ . '/../../../uploads/gallery/*', GLOB_ONLYDIR) ?: [] as $dir) {
|
||||
foreach (img_optimize_dir($dir . '/', IMG_MAX_GALLERY) as $k => $v) $stats[$k] += $v;
|
||||
}
|
||||
session()->setFlashdata($stats['failed'] ? 'warning' : 'success', img_stats_message($stats));
|
||||
header('Location: ' . base_url('views/admin/galerias/index.php'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$galleries = db_gallery_list($pdo);
|
||||
$page_title = 'Galerias';
|
||||
include __DIR__ . '/../../../includes/header.php';
|
||||
?>
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="h3 mb-0">Galerias</h1>
|
||||
<div class="d-flex gap-2">
|
||||
<form method="POST" class="mb-0">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" name="optimize_all" value="1" class="btn btn-outline-success"
|
||||
title="Redimensiona e comprime as imagens de todas as galerias para o máximo de <?= IMG_MAX_GALLERY ?>px"
|
||||
onclick="return confirm('Otimizar as imagens de todas as galerias (máx. <?= IMG_MAX_GALLERY ?>px)? Os ficheiros originais serão substituídos.')">
|
||||
<i class="bi bi-arrows-angle-contract me-1"></i>Otimizar imagens
|
||||
</button>
|
||||
</form>
|
||||
<a class="btn btn-primary" href="<?= base_url('views/admin/galerias/create.php') ?>"><i class="bi bi-plus-lg me-1"></i>Nova Galeria</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm"><div class="card-body p-0">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light"><tr>
|
||||
<th>Nome</th><th style="width:120px">Ações</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<?php if (!$galleries): ?>
|
||||
<tr><td colspan="2" class="text-center text-muted py-4">Nenhuma galeria.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($galleries as $g): ?>
|
||||
<tr>
|
||||
<td><strong><?= htmlspecialchars($g['name']) ?></strong></td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-outline-primary" href="edit.php?id=<?= $g['id'] ?>"><i class="bi bi-pencil"></i> Gerir</a>
|
||||
<a class="btn btn-sm btn-outline-danger" href="?delete=<?= $g['id'] ?>" onclick="return confirm('Apagar esta galeria e todas as suas imagens?')"><i class="bi bi-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div></div>
|
||||
</div>
|
||||
<?php include __DIR__ . '/../../../includes/footer.php';
|
||||
Reference in new issue
Block a user