Upcoming Birthdays - Lists Member's Age And Links To Profile
This script will retrieve upcoming member birthdays for the current month. The list will have their age and a link to their profile; does not list prior birthdays in the month. Lists one member per line.
Intended as a php block in TinyPortal; can set a variable in the script for left (default), center, or right justification. Uses themes 'smalltext' class for text; best in columns 170px.
Added 'limit' option to variables; '0' = All
07/19/2008 : Added highlighting to code for birthday on current date.
Some advanced options are available and explained in next post.
Guaranteed ninety days or ninety feet- whichever comes first. :coolsmiley:
// Birthdays: list_birthdays.php
// July 01, 2008 / Tim Antley / www.BayouMX.com
// - updated 07/19: Highlights a birthday on current date
// For Use With SMF & TinyPortal
// Script for retrieving upcoming member birthdays for current month.
// Calculates age and links to profile by member's name.
// Admin can justify output to the left, center, or right by $justify variable.
// Optional: Can list birthdays by month specified in URL; use ?month=xx
// Optional: Can parse birthdays from certain day to end of month; use ?day=xx
// Optional: Specify justification through URL; ?justify=right
// Optional: Set number of birthdays to return; ?limit=5 (defaults to list all)
// Note: In order to use both URL options, the second and following parameters
// MUST use an ampersand (&) instead of a question mark.
// Example: list_birthdays.php?month=7&day=15 << Will list from the 15th to end of July.
// Does not parse URL parameters for valid input; i.e. month #13 = nothing!
// Much love for Bloc and the TP Support Team (Ich, G6, Ken, and JPDeni!) Does anyone read this?
$current_date = getdate();
$month_number = sprintf("%02d", $current_date['mon']);
$justify = 'left'; // Valid options: 'left', 'center', or 'right'
$limit = 0; // Integer value for length of list
if(!empty($_GET['justify'])) $justify = $_GET['justify'];
if(!empty($_GET['limit'])) $limit = $_GET['limit'];
if(!empty($_GET['month'])) $month_number = $_GET['month'];
if(!empty($_GET['day'])) $current_date['mday'] = $_GET['day'];
if($limit == 0) $count = -1;
global $db_prefix, $scripturl;
$query = db_query(
"SELECT ID_MEMBER, memberName, birthdate
FROM {$db_prefix}members
WHERE birthdate LIKE '%-%$month_number%-%'
AND birthdate NOT LIKE '0001-01-01'
ORDER BY birthdate ASC", __FILE__, __LINE__);
while (($row = mysql_fetch_array($query)) && ($count < $limit))
{
if($limit != 0) $count++;
$dob_year = strtok($row['birthdate'], '-');
$dob_month = strtok('-');
$dob_day = strtok('-');
$age = sprintf("%2d", ($current_date['year'] - $dob_year));
if($current_date['mday'] <= $dob_day)
{
if($current_date['mday'] == $dob_day)
{
$class = 'highlight';
}
else
{
$class = '';
}
if(strtolower($justify) == 'left')
{
echo'<div class="smalltext" align="left"><span class="'.$class.'">('.$age.') ';
echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['memberName'] . '</a>';
echo '</span></div>';
}
elseif(strtolower($justify) == 'right')
{
echo'<div class="smalltext" align="right"><span class="'.$class.'">';
echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['memberName'] . '</a>';
echo ' ('.$age.')</span></div>';
}
elseif(strtolower($justify) == 'center')
{
echo'<div class="smalltext" align="center"><span class="'.$class.'">';
echo '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['memberName'] . '</a>';
echo ' ('.$age.')</span></div>';
}
else
{
echo '<b>Invalid justification specified: ("'.$justify.'")</b><br>';
echo 'Use "left", "center", or "right" for script.<hr>';
die();
}
}
}
For the most part, there is no reason to try to use the advanced options. They were added for future implementation as part of an admin calendar routine. The 'justify' option can be set permanently in the script itself, as can the 'limit' option.
In order to use the advanced functions, several minor things must be done:
a) Insert the following line at the beginning of the script, with your server's path to SSI.php: require_once('SSI.php');
It is imperative that SSI.php be accessible- such as loading on a splash page or similar non-SMF page.
b) Save the script to your server; the relative path to SSI.php is from this location.
c) Load the script - use ? to prefix the first option, & for all following options.
Examples:
list_birthdays.php (no parameters)
- defaults to left justification, list all birthdays in current month from current day to end of month.
list_birthdays.php?month=7&limit=20
- will list the next twenty July birthdays from current day
list_birthdays.php?month=10&day=20
- lists from Oct 20 to end of that month
list_birthdays.php?justify=right&month=4&day=1
- will place the list on the right, and output all birthdays for April
If you specify anything other than 'left', 'right', or 'center' for justification, it will display an error message with advice.
And, if you try to spoof the month and/or day with invalid values, it will display nothing.
Just remember that to use in this configuration, SSI.php must be loaded if you're using the script outside of SMF/TP.
looks ggood ianadres!! will have to try this out.. :D
thanks very much!! :P
Will it highlight the member on the day of his birthday say in red or something?
Will work on that later today when I get some free time.
Thanks you that will be very cool to have it work like this
I have added your request for highlighting a current birthday and updated the code in the original post.
Thanks now this is a cool mod
Ianedres is their a way that the Avatar will also be shown with the name and date?
Quote from: blouogies on August 05, 2008, 04:02:11 PM
Ianedres is their a way that the Avatar will also be shown with the name and date?
See this topic: http://www.tinyportal.net/index.php?topic=25332.msg203070#msg203070
I just created another code snippet rather than try to update this topic. :coolsmiley:
Thanks Ianedres :D