1, ‘title’ => ‘Lixo acumulado na praça’, ‘description’ => ‘Muito lixo jogado próximo aos bancos da praça central’, ‘location’ => ‘Praça Central, Centro’, ‘status’ => ‘pendente’, ‘image’ => ’emoji:🗑️’, ‘date’ => date(‘Y-m-d H:i:s’, strtotime(‘-2 hours’)), ‘priority’ => ‘alta’ ], [ ‘id’ => 2, ‘title’ => ‘Entulho na calçada’, ‘description’ => ‘Material de construção abandonado bloqueando a passagem’, ‘location’ => ‘Rua das Flores, 123’, ‘status’ => ’em_andamento’, ‘image’ => ’emoji:🏗️’, ‘date’ => date(‘Y-m-d H:i:s’, strtotime(‘-5 hours’)), ‘priority’ => ‘média’ ], [ ‘id’ => 3, ‘title’ => ‘Ponto de ônibus sujo’, ‘description’ => ‘Ponto de ônibus com muito lixo ao redor’, ‘location’ => ‘Av. Principal, 456’, ‘status’ => ‘resolvido’, ‘image’ => ’emoji:🚌’, ‘date’ => date(‘Y-m-d H:i:s’, strtotime(‘-1 day’)), ‘priority’ => ‘baixa’ ] ]; file_put_contents($file, json_encode($seed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); return $seed; } $json = file_get_contents($file); $data = json_decode($json, true); return is_array($data) ? $data : []; } function save_reports($file, $reports) { file_put_contents($file, json_encode($reports, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } function next_id($reports) { $max = 0; foreach ($reports as $r) { $max = max($max, (int)$r[‘id’]); } return $max + 1; } function human_time($datetime) { $ts = strtotime($datetime); $diff = time() – $ts; if ($diff < 60) return 'Agora'; $mins = floor($diff / 60); if ($mins < 60) return $mins . ' min atrás'; $hrs = floor($mins / 60); if ($hrs < 24) return $hrs . ' horas atrás'; $days = floor($hrs / 24); return $days . ' dia' . ($days>1?’s’:”) . ‘ atrás’; } function esc($s) { return htmlspecialchars($s ?? ”, ENT_QUOTES, ‘UTF-8’); } // ———————- AÇÕES (POST) ———————- $reports = load_reports($DATA_FILE); $action = $_POST[‘action’] ?? $_GET[‘action’] ?? null; if ($action === ‘add’) { $title = trim($_POST[‘title’] ?? ”); $description = trim($_POST[‘description’] ?? ”); $location = trim($_POST[‘location’] ?? ”); $priority = $_POST[‘priority’] ?? ‘média’; $imageField = ‘image’; $imageRef = ’emoji:📍’; if (!empty($_FILES[$imageField][‘name’])) { $ext = pathinfo($_FILES[$imageField][‘name’], PATHINFO_EXTENSION); $safeName = uniqid(‘img_’) . ($ext ? (‘.’ . strtolower($ext)) : ”); $dest = $UPLOAD_DIR . ‘/’ . $safeName; if (move_uploaded_file($_FILES[$imageField][‘tmp_name’], $dest)) { $imageRef = ‘file:’ . $safeName; } } if ($title && $description && $location) { $new = [ ‘id’ => next_id($reports), ‘title’ => $title, ‘description’ => $description, ‘location’ => $location, ‘status’ => ‘pendente’, ‘image’ => $imageRef, ‘date’ => date(‘Y-m-d H:i:s’), ‘priority’ => in_array($priority, [‘alta’,’média’,’baixa’]) ? $priority : ‘média’ ]; array_unshift($reports, $new); save_reports($DATA_FILE, $reports); header(‘Location: ‘ . strtok($_SERVER[‘REQUEST_URI’], ‘?’)); exit; } } if ($action === ‘status’) { $id = (int)($_POST[‘id’] ?? 0); $status = $_POST[‘status’] ?? ”; $valid = [‘pendente’,’em_andamento’,’resolvido’]; if ($id && in_array($status, $valid)) { foreach ($reports as &$r) { if ((int)$r[‘id’] === $id) { $r[‘status’] = $status; break; } } save_reports($DATA_FILE, $reports); } header(‘Location: ‘ . strtok($_SERVER[‘REQUEST_URI’], ‘?’)); exit; } if ($action === ‘delete’) { $id = (int)($_POST[‘id’] ?? 0); if ($id) { $reports = array_values(array_filter($reports, fn($r) => (int)$r[‘id’] !== $id)); save_reports($DATA_FILE, $reports); } header(‘Location: ‘ . strtok($_SERVER[‘REQUEST_URI’], ‘?’)); exit; } // ———————- HELPERS DE ESTILO ———————- function status_color($status) { return [ ‘pendente’ => ‘text-orange-600 bg-orange-100′, ’em_andamento’ => ‘text-blue-600 bg-blue-100’, ‘resolvido’ => ‘text-green-600 bg-green-100’, ][$status] ?? ‘text-gray-600 bg-gray-100’; } function status_text($status) { return [ ‘pendente’ => ‘Pendente’, ’em_andamento’ => ‘Em Andamento’, ‘resolvido’ => ‘Resolvido’, ][$status] ?? ‘Desconhecido’; } function priority_bar($p) { return [ ‘alta’ => ‘border-l-red-500’, ‘média’ => ‘border-l-yellow-500’, ‘baixa’ => ‘border-l-green-500’, ][$p] ?? ‘border-l-gray-500’; } function image_tag($image) { if (strpos($image, ‘file:’) === 0) { $path = ‘uploads/’ . substr($image, 5); return ‘imagem‘; } if (strpos($image, ’emoji:’) === 0) { return ‘‘ . esc(substr($image, 6)) . ‘‘; } return ‘📍‘; } ?> Cidade Limpa
🌱
Cidade Limpa

Cidade Limpa

Juntos por uma cidade mais limpa e organizada

$r[‘status’]===’pendente’)); $and = count(array_filter($reports, fn($r)=>$r[‘status’]===’em_andamento’)); $res = count(array_filter($reports, fn($r)=>$r[‘status’]===’resolvido’)); ?>
Pendentes
Em Andamento
Resolvidos

Relatos Recentes

Excluir