prepare("INSERT INTO schedule (date, kegiatan) VALUES (NOW(), ?)"); $stmt->execute([$activity]); } } echo json_encode(["status" => "success"]); exit; } include_once 'koneksi.php'; date_default_timezone_set('Asia/Jakarta'); // Create table if not exists $pdo->exec("CREATE TABLE IF NOT EXISTS schedule ( id_schedule INT AUTO_INCREMENT PRIMARY KEY, date TIMESTAMP NOT NULL, kegiatan VARCHAR(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); // Current month/year $month = isset($_GET['m']) ? (int)$_GET['m'] : (int)date('m'); $year = isset($_GET['y']) ? (int)$_GET['y'] : (int)date('Y'); if($month < 1){ $month = 12; $year--; } if($month > 12){ $month = 1; $year++; } $firstDay = mktime(0,0,0,$month,1,$year); $daysInMonth = (int)date('t', $firstDay); $startWeekday = (int)date('w', $firstDay); $today = date('Y-m-d'); $pm = $month-1; $py = $year; if($pm<1){$pm=12;$py--;} $nm = $month+1; $ny = $year; if($nm>12){$nm=1;$ny++;} // Fetch events for this month $stmt = $pdo->prepare("SELECT * FROM schedule WHERE MONTH(date)=? AND YEAR(date)=? ORDER BY date ASC"); $stmt->execute([$month, $year]); $rows = $stmt->fetchAll(); $eventsByDate = []; foreach($rows as $r){ $d = substr($r['date'], 0, 10); if(!isset($eventsByDate[$d])) $eventsByDate[$d] = []; $eventsByDate[$d][] = $r; } // Activities for selected month $activities = $rows; $monthNames = ['January','February','March','April','May','June','July','August','September','October','November','December']; // Unique color per date — no repeats within the month $allColors = ['#4B49AC','#10b981','#f59e0b','#ec4899','#0891b2','#8b5cf6','#ef4444','#4b7bec', '#059669','#d946ef','#0d9488','#e11d48','#7c3aed','#ca8a04','#2563eb','#dc2626', '#16a34a','#9333ea','#0284c7','#c026d3','#ea580c','#4f46e5','#15803d','#be123c', '#6d28d9','#b45309','#0369a1','#a21caf','#c2410c','#4338ca','#047857','#9f1239']; $dateColors = []; $ci = 0; foreach($eventsByDate as $dateKey => $evts){ $dateColors[$dateKey] = $allColors[$ci % count($allColors)]; $ci++; } include 'header.php'; ?>