Files
fitme3070.pt/views/admin/team/create.php
T
andreandClaude Opus 4.8 e68d357177 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>
2026-06-12 10:44:58 +01:00

83 lines
4.2 KiB
PHP

<?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 = [];
$data = ['name' => '', 'birthday' => '', 'at' => '', 'status' => 'ativo', 'description' => ''];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$data = [
'name' => trim($_POST['name'] ?? ''),
'birthday' => trim($_POST['birthday'] ?? ''),
'at' => trim($_POST['at'] ?? ''),
'status' => $_POST['status'] ?? 'ativo',
'description' => trim($_POST['description'] ?? ''),
];
if ($data['name'] === '') $errors[] = 'O nome é obrigatório.';
// Photo upload
$photo_name = null;
if (!empty($_FILES['photo']['tmp_name']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) {
$ext = strtolower(pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION));
if (!in_array($ext, ['jpg','jpeg','png','gif','webp'])) $errors[] = 'Formato de foto inválido.';
else {
$upload_dir = __DIR__ . '/../../../uploads/team/foto/';
if (!is_dir($upload_dir)) @mkdir($upload_dir, 0775, true);
$photo_name = bin2hex(random_bytes(16)) . '.' . $ext;
if (!move_uploaded_file($_FILES['photo']['tmp_name'], $upload_dir . $photo_name)) {
$errors[] = 'Falha ao guardar a foto.';
$photo_name = null;
} else {
img_optimize($upload_dir . $photo_name, IMG_MAX_TEAM);
}
}
}
if (!$errors) {
$data['photo'] = $photo_name;
$id = db_team_create($pdo, $data);
session()->setFlashdata('success', 'Membro criado com sucesso.');
header('Location: ' . base_url('views/admin/team/edit.php?id=' . $id));
exit;
}
}
$page_title = 'Adicionar Membro';
include __DIR__ . '/../../../includes/header.php';
?>
<div class="container" style="max-width:700px;">
<h1 class="h3 mb-4">Adicionar Membro</h1>
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
<form method="POST" enctype="multipart/form-data" class="card shadow-sm"><div class="card-body">
<?= csrf_field() ?>
<div class="row g-3">
<div class="col-md-8"><label class="form-label">Nome <span class="text-danger">*</span></label>
<input class="form-control" name="name" required value="<?= htmlspecialchars($data['name']) ?>"></div>
<div class="col-md-4"><label class="form-label">Nascimento</label>
<input type="date" class="form-control" name="birthday" value="<?= htmlspecialchars($data['birthday']) ?>"></div>
<div class="col-md-4"><label class="form-label">Área</label>
<select class="form-select" name="at"><option value="">—</option>
<option value="gym" <?= $data['at'] === 'gym' ? 'selected' : '' ?>>Gym</option>
<option value="crossfit" <?= $data['at'] === 'crossfit' ? 'selected' : '' ?>>CrossFit</option>
</select></div>
<div class="col-md-4"><label class="form-label">Estado</label>
<select class="form-select" name="status">
<option value="ativo" <?= $data['status'] === 'ativo' ? 'selected' : '' ?>>Ativo</option>
<option value="inativo" <?= $data['status'] === 'inativo' ? 'selected' : '' ?>>Inativo</option>
</select></div>
<div class="col-md-4"><label class="form-label">Foto</label>
<input type="file" class="form-control" name="photo" accept=".jpg,.jpeg,.png,.gif,.webp"></div>
<div class="col-12"><label class="form-label">Descrição</label>
<textarea class="form-control" name="description" rows="3"><?= htmlspecialchars($data['description']) ?></textarea></div>
</div>
<div class="mt-4 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'; ?>