fix: corriger le suivi médical et les styles publics

This commit is contained in:
Alexandre NOEL 2026-09-22 18:05:38 +02:00
commit a55d27935f
15 changed files with 206 additions and 24 deletions

View file

@ -4,6 +4,53 @@ declare(strict_types=1);
final class DewormingController
{
public static function renameProduct(): void
{
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
http_response_code(405);
return;
}
if (!PermissionService::can('medical', 'edit')) {
http_response_code(403);
return;
}
$tables = ['dewormer' => 'ref_dewormers', 'medication' => 'ref_medications', 'vaccine' => 'ref_vaccines'];
$category = (string) ($_POST['category'] ?? '');
$table = $tables[$category] ?? null;
$id = (int) ($_POST['product_id'] ?? 0);
$animalId = (int) ($_POST['animal_id'] ?? 0);
$name = trim((string) ($_POST['name'] ?? ''));
if ($table === null || $id <= 0 || $animalId <= 0 || $name === '' || mb_strlen($name) > 150) {
http_response_code(400);
echo h(t('error.bad_request'));
return;
}
$db = DB::pdo();
$stmt = $db->prepare("SELECT name FROM $table WHERE id=:id");
$stmt->execute([':id' => $id]);
$previous = $stmt->fetchColumn();
if ($previous === false) {
http_response_code(404);
echo h(t('error.not_found'));
return;
}
$duplicate = $db->prepare("SELECT 1 FROM $table WHERE name=:name COLLATE NOCASE AND id<>:id");
$duplicate->execute([':name' => $name, ':id' => $id]);
if ($duplicate->fetchColumn()) {
http_response_code(409);
echo h(t('catalog.name_exists'));
return;
}
$db->prepare("UPDATE $table SET name=:name WHERE id=:id")->execute([':name' => $name, ':id' => $id]);
AuditService::log('catalog_renamed', '/animal/product/rename', 'Intitulé de produit corrigé', 'animal', $animalId, [
'category' => $category,
'product_id' => $id,
'previous_name' => $previous,
'new_name' => $name,
]);
header('Location: /animal?id=' . $animalId . '#tab-med');
}
public static function save(): void
{
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {