0)?0:1), ($which>0)?1:0, $year); $done = FALSE; $match = 0; $inc = 3600*24; while (!$done) { if (strftime('%w', $ts) == $day-1) { $match++; } if ($match == abs($which)) { $done = TRUE; } else { $ts += (($which>0)?1:-1)*$inc; } } return $ts; } // Get events for one month in one year to be listed function load_month($year, $month, $cat) { // Empty events array $events = []; // Get approved events starting or ending in the // specified year/month, and all recurring events $result = db_query_safe( "SELECT * FROM phpcal WHERE ( ( (MONTH(sdato) = ? OR MONTH(edato) = ?) AND (YEAR(sdato) = ? OR YEAR(edato) = ?) AND tipo < 3 ) OR tipo = 3) AND category = ? AND approved = 1", [$month, $month, $year, $year, $cat] ); // Cannot get results, return with event's not found if (!$result) { echo mysql_error(); return []; } // Go through found events while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { switch($row['tipo']) { // One day event case 1: list(, , $dd) = explode('-', $row['sdato']); $events[(int)$dd][] = $row; break; // Multiple-day event case 2: list(, $mm, $dd) = explode('-', $row['sdato']); list(, $m2, $d2) = explode('-', $row['edato']); if ((int)$mm == (int)$m2) { for ($i = (int)$dd; $i <= (int)$d2; $i++) { $events[$i][] = $row; } } elseif ((int)$mm == $month) { for ($i = (int)$dd; $i < 32; $i++) { $events[$i][] = $row; } } else { for ($i = 1; $i <= (int)$d2; $i++) { $events[$i][] = $row; } } break; // Recurring event case 3: list($which,$dd) = explode(':', $row['recur']); $ts = weekday((int)$year, (int)$month, (int)$dd, (int)$which); $events[(int)strftime('%d', $ts)][] = $row; break; } } // Return events found return $events; }