= htmlspecialchars($row['title']) ?>
= htmlspecialchars($row['company_name']) ?>
'', 'class'=>'open']; $now = new DateTime('now'); $exp = DateTime::createFromFormat('Y-m-d H:i:s', $ymd . ' 23:59:59'); if (!$exp) $exp = new DateTime($ymd . ' 23:59:59'); $diff = (int)$now->diff($exp)->format('%r%a'); // <0 prošlo, 0 danas, >0 budućnost if ($diff < 0) return ['text'=>'Oglas istekao', 'class'=>'closed']; if ($diff === 0) return ['text'=>'Oglas je aktivan još danas!', 'class'=>'expiring today']; if ($diff <= 3) return ['text'=>'Oglas je aktivan još ' . $diff . ' ' . ($diff===1?'dan':'dana'), 'class'=>'expiring']; return ['text'=>'Oglas je aktivan', 'class'=>'open']; } function initialsFromName($name) { $parts = preg_split('/\s+/', trim($name)); $ini = ''; if (isset($parts[0][0])) $ini .= mb_strtoupper(mb_substr($parts[0],0,1,'UTF-8'),'UTF-8'); if (isset($parts[1][0])) $ini .= mb_strtoupper(mb_substr($parts[1],0,1,'UTF-8'),'UTF-8'); return $ini ?: 'CO'; } function logoExists($path) { if (!$path) return false; $abs = __DIR__ . '/' . ltrim($path,'/'); return is_file($abs); } // vrati broj preostalih dana do datuma (0 ako je već isteklo) function daysLeft($dateStr) { if (empty($dateStr)) return 0; $now = new DateTime('today'); $to = new DateTime($dateStr); if ($to <= $now) return 0; return (int)$now->diff($to)->format('%a'); } // === Tekst za bedž isteka === function expiryBadge(?string $ymd): string { if (!$ymd || $ymd === '0000-00-00') return ''; $today = new DateTime('today'); $exp = new DateTime($ymd); $diff = (int)$today->diff($exp)->format('%r%a'); // <0 prošlo, 0 danas, >0 budućnost if ($diff < 0) return 'Oglas istekao'; if ($diff === 0) return 'Oglas je aktivan još danas'; return 'Ističe za ' . $diff . ' ' . ($diff === 1 ? 'dan' : 'dana'); } /* ------------------------------------------- Dropdown liste za filter ------------------------------------------- */ $cityRes = $db->query(" SELECT DISTINCT location_city AS city FROM jobs WHERE status='active' AND date_expires >= CURDATE() AND location_city<>'' ORDER BY location_city ASC "); $cities = []; while ($row = $cityRes->fetch_assoc()) $cities[] = $row['city']; $catRes = $db->query(" SELECT DISTINCT category FROM jobs WHERE status='active' AND date_expires >= CURDATE() AND category<>'' ORDER BY category ASC "); $categories = []; while ($row = $catRes->fetch_assoc()) $categories[] = $row['category']; /* ------------------------------------------- Filter logika ------------------------------------------- */ $where = "WHERE status='active' AND date_expires >= CURDATE()"; $params = []; if (!empty($_GET['q'])) { $q = trim($_GET['q']); $qEsc = $db->real_escape_string($q); $where .= " AND (title LIKE '%$qEsc%' OR company_name LIKE '%$qEsc%')"; $params['q'] = $q; } if (!empty($_GET['grad'])) { $grad = trim($_GET['grad']); $gradEsc = $db->real_escape_string($grad); $where .= " AND location_city = '$gradEsc'"; $params['grad'] = $grad; } if (!empty($_GET['kategorija'])) { $kat = trim($_GET['kategorija']); $katEsc = $db->real_escape_string($kat); $where .= " AND category = '$katEsc'"; $params['kategorija'] = $kat; } /* ------------------------------------------- Brojači ------------------------------------------- */ $countActiveRow = $db->query(" SELECT COUNT(*) AS c FROM jobs WHERE status='active' AND date_expires >= CURDATE() ")->fetch_assoc(); $countActive = (int)($countActiveRow['c'] ?? 0); $citiesCounts = []; $ccRes = $db->query(" SELECT location_city AS city, COUNT(*) AS cnt FROM jobs WHERE status='active' AND date_expires >= CURDATE() AND location_city <> '' GROUP BY location_city ORDER BY cnt DESC, city ASC LIMIT 12 "); while ($row = $ccRes->fetch_assoc()) $citiesCounts[] = $row; /* Kategorije + broj oglasa po kategoriji (za dropdown) */ $categoryCounts = []; $katCntRes = $db->query(" SELECT category AS cat, COUNT(*) AS cnt FROM jobs WHERE status='active' AND date_expires >= CURDATE() AND category <> '' GROUP BY category ORDER BY cnt DESC, cat ASC LIMIT 50 "); while ($row = $katCntRes->fetch_assoc()) $categoryCounts[] = $row; /* ------------------------------------------- Reklamni baneri sa overlay ------------------------------------------- */ $adsRes = $db->query(" SELECT image_path, link, headline, subheadline, cta_label, position, text_color, bg_darkness, show_overlay, offset_top, offset_left, offset_right, offset_bottom FROM ads WHERE is_active=1 ORDER BY sort_order ASC, id DESC "); $ads = []; if ($adsRes) while($r = $adsRes->fetch_assoc()) $ads[] = $r; /* ------------------------------------------- Izdvojeni i glavna lista ------------------------------------------- */ $featuredRes = $db->query(" SELECT id, title, company_name, location_city, category, work_type, date_posted, logo_path FROM jobs WHERE status='active' AND is_featured=1 AND date_expires >= CURDATE() ORDER BY date_posted DESC LIMIT 6 "); $featuredRes = $db->query(" SELECT id, title, company_name, location_city, category, work_type, date_posted, date_expires, logo_path FROM jobs WHERE status='active' AND is_featured=1 AND date_expires >= CURDATE() ORDER BY date_posted DESC LIMIT 12 "); $hasFilter = (!empty($_GET['q']) || !empty($_GET['grad']) || !empty($_GET['kategorija'])); $res = $db->query(" SELECT id, title, company_name, location_city, category, work_type, date_posted, logo_path FROM jobs $where ORDER BY date_posted DESC "); ?>
= htmlspecialchars($row['company_name']) ?>