<?php
include 'includes/db.php';

$id = intval($_GET['id']);

// Ștergem fișierele documente
$docs = $conn->query("SELECT fisier FROM documents WHERE car_id = $id");
while ($d = $docs->fetch_assoc()) {
  $f = 'uploads/' . $d['fisier'];
  if (file_exists($f)) unlink($f);
}
$conn->query("DELETE FROM documents WHERE car_id = $id");

// Ștergem pozele
$photos = $conn->query("SELECT filename FROM car_photos WHERE car_id = $id");
while ($p = $photos->fetch_assoc()) {
  $f = 'uploads/' . $p['filename'];
  if (file_exists($f)) unlink($f);
}
$conn->query("DELETE FROM car_photos WHERE car_id = $id");

// Ștergem mașina
$conn->query("DELETE FROM cars WHERE id = $id");

header("Location: deleted.php");
exit();
?>
