Upcoming Birthdays - Lists Member's Age, Avatar, And Links To Profile
This script will retrieve upcoming member birthdays for the current month. The list will have their age, avatar, and a link to their profile; does not list prior birthdays in the month. Lists one member per line.
Script is modified from my original snippet posted here (http://www.tinyportal.net/index.php?topic=24774.0) on July 1st, 2008. See that topic's second message for advanced functions.
Avatar displaying can be turned on or off by setting the variable $avatar_on to 'true' or 'false'. There is a setting for the maximum height and width for the displayed avatar, as to limit the space required for the output.
This script will require the attached 'blank_1x1.gif' image (43 bytes) to pad for members without avatars, and the path must be entered in the script variable $blank_image.
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.
Again, warranty is for 90 days or 90 feet. 8)
- Added code to not output anything if no birthdays found in database.
/*
Upcoming Member Birthdays With Avatar & Age
August 10, 2008 / Tim Antley / www.BayouMX.com
- updated to display avatars per request (Blouogies)
- updated with option to display age or not
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)
Optional: Use avatar display; can also set max height & width
Optional: Display of member's age
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!
Nobody reads all 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
$avatar_on = true; // Use avatar in output: true or false
$avatar_height = '45'; // Set height of avatar
$avatar_width = '45'; // Set width of avatar
$blank_image = 'http://www.bayoumx.com/images/blank_1x1.gif'; // URL to where you placed the blank avatar file...
$display_age = true; // Display member's age: true or false
// Warranty void if edited past this line! ;)
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++;
if(empty($row['birthdate'])) return;
$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 = '';
}
$current_ID = $row['ID_MEMBER'];
$avatar = '';
if($avatar_on) // query to retrieve member's avatar # in attachment directory; bypass if avatar_on = false
{
$avatar = '<img src="' . $blank_image . '" height="' . $avatar_height . '" width=" '. $avatar_width . '" border="0" />';
$query2 = db_query(
"SELECT ID_ATTACH
FROM {$db_prefix}attachments
WHERE ID_MEMBER = '$current_ID'", __FILE__, __LINE__);
$result = mysql_fetch_array($query2);
if(!empty($result['ID_ATTACH']))
{
$avatar = '<img src="' . $scripturl . '?action=dlattach;attach=' . $result['ID_ATTACH'] .
';type=avatar" height="' . $avatar_height . '" width=" '. $avatar_width . '" border="0" />';
}
else
{
$query3 = db_query(
"SELECT avatar
FROM {$db_prefix}members
WHERE ID_MEMBER = '$current_ID'", __FILE__, __LINE__);
$result = mysql_fetch_array($query3);
if(!empty($result['avatar']))
{
$avatar = '<img src="' . $modSettings['avatar_url'] . '/' . $result['avatar'] . '" height="' .
$avatar_height . '" width=" '. $avatar_width . '" border="0" />';
}
}
}
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">';
if($display_age)
{
$age = ' (' . $age . ') ';
}
else
{
$age = ' ';
}
if(strtolower($justify) == 'left')
{
echo'<div class="smalltext" align="left"><span class="'.$class.'">';
echo $link . $avatar . '</a>' . $age . $link . $row['memberName'] . '</a>';
echo '</span></div>';
}
elseif(strtolower($justify) == 'right')
{
echo'<div class="smalltext" align="right"><span class="'.$class.'">';
echo $link . $row['memberName'] . '</a>';
echo $age . $link . $avatar . '</a></span></div>';
}
elseif(strtolower($justify) == 'center')
{
echo'<div class="smalltext" align="center"><span class="'.$class.'">';
echo $link . $avatar . '</a> ' . $link . $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();
}
}
}
It should be noted that using the avatar display can increase your database load, potentially two extra queries for each member located... so use at your own discretion.
Thanks Ianedres
It is working perfectly!!
One question???
Is there away to make the block to disappear when there is no Birthdays that month?
Ah... yes. Will have to work on it this evening... (oops!) :buck2:
No problem ;)
Thanks Ianedres
I have inserted code to cancel the script if there are no birthdays occurring.
I'll have to reserve the right to change this to a more suitable or proper method, but I just don't have the right amount of time to do it at the moment.
Thanks Ianedres.
This will work good!!!!
Script has been updated (yet again!) in the first post to allow for the option whether or not to display the member's age.
hi! is it possible to make a scrollbar in it? The list is pretty long :)
Try this- it should make a 'scroll' CSS class, and put the output into a DIV statement with a scrollbar (if needed). Know that this is untested, as I don't have enough members with b'day info.
Adjust the height, width, and padding values to your liking. 8)
Add this to the beginning of the original script:
echo '<style type="text/css">
<!--
div.scroll {
height: 100px;
width: 170px;
overflow: auto;
padding: 8px;
}
-->
</style> ';
echo '<div class="scroll">';
Insert this after the last line of the original script: echo '</div>';
wow!
This works like a charm! thank you!!
Is it also possible if you know to have the ones who's birthday today is.. that they are separated in a other kolomn.. or maybe a separation line between it?