Here's the repaired code. I tested it on my board, and found and fixed another flaw.
- Changed birthday code to correctly handle end of year roll-over
- Separated the date headline and age calculation code
PHP Code:
// do birthdays
if ($numbirthdays) {
// Accomodate end of year roll-over
if ($btoday >= $bdaysprune) {
$users = $DB_site->query("SELECT * FROM user WHERE SUBSTRING(birthday,6)>'00-00' AND (SUBSTRING(birthday,6)>='$btoday' OR SUBSTRING(birthday,6)<='$bdaysprune') ORDER BY SUBSTRING(birthday,6) LIMIT 0,$numbirthdays");
} else {
$users = $DB_site->query("SELECT * FROM user WHERE SUBSTRING(birthday,6)>='$btoday' AND SUBSTRING(birthday,6)<='$bdaysprune' ORDER BY SUBSTRING(birthday,6) LIMIT 0,$numbirthdays");
}
if ($DB_site->num_rows($users)) {
$thisyear = date("Y");
$birthdayspreview = "$dashes\nFORTHCOMING BIRTHDAYS:\nto view the calendar, click the link below:\n$bburl/calendar.php\n$dashes\n";
// $birthdayspreview .= "DEBUG: btoday: $btoday bdaysprune: $bdaysprune\n";
while ($user = $DB_site->fetch_array($users)) {
$datebits = explode("-", $user[birthday]);
if (substr($user[birthday],6) != substr($lastbirthday,6)) {
$currentdate = date($calformat2, mktime(0,0,0,$datebits[1],$datebits[2],0));
$birthdayspreview .= "\n$currentdate:\n";
}
if ($datebits[0] != "0000") {
$age = " (".($thisyear - $datebits[0]).")";
} else {
$age = "";
}
$birthdayspreview .= " $lic $user[username]$age - $bburl/member.php?action=getinfo&userid=$user[userid]\n";
$lastbirthday = $user[birthday];
}
$birthdayspreview .= "\n\n";
}
}