To use this website completely, it is necessary to store cookies on your computer.
 

Upcoming birthdays

Started by DirtRider, 8 years ago

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

DirtRider

8 years ago
What I would like to see is a block that will list the upcoming birthdays for the month. It should then highlight the birthdays for that day or give some indication that those are today's birthdays. Using TP we had the following code for a block but this does not work with SFM2


Code Select

// Birthdays: list_birthdays.php
// July 01, 2008 / Tim Antley / www.BayouMX.com
// - updated 07/19: Highlights a birthday on current date

// 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();
}
}
}

"The real question is not whether machines think but whether men do. "


antechinus

#1
8 years ago
Shouldn't be hard at all. All you'd basically need to do is rip the birthday code from the 2b4 info centre and drop it in a block.
Using Internet Explorer 6 on the internet is like urinating in a public swimming pool.
It's rude, there's no excuse for it, and anyone who does it should be ashamed of themselves.

DirtRider

#2
8 years ago
I don't suppose anyone would have that code just sort of handy would they  :) 8)
"The real question is not whether machines think but whether men do. "


feline

#3
8 years ago
While the database structure AND the querys changed on SMF 2.0 you can try this:
Code Select

// Birthdays: list_birthdays.php
// July 01, 2008 / Tim Antley / www.BayouMX.com
// - updated 07/19: Highlights a birthday on current date

// 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 $smcFunc, $scripturl;

$query = $smcFunc['db_query']('', '
SELECT id_member, member_name, birthdate
FROM {db_prefix}members
WHERE birthdate LIKE {string:likestr}     
AND birthdate NOT LIKE {string:notlikestr}
ORDER BY birthdate ASC',
array(
'likestr' => '%-%'. $month_number .'%-%',
'notlikestr' => '0001-01-01',
)
);

while(($row = $smcFunc['db_fetch_assoc']($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['member_name'] . '</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['member_name'] . '</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['member_name'] . '</a>';
         echo ' ('.$age.')</span></div>';
      }
      else
      {
         echo '<b>Invalid justification specified: ("'.$justify.'")</b><br>';
         echo 'Use "left", "center", or "right" for script.<hr>';
         die();
      }
   }
}
$smcFunc['db_free_result']($query);


Fel
Many are stubborn in relation to the path, a few in relation to the target.

Cool

#4
8 years ago
as usual...it works fine

Feline is just GREAT :-*


[attachment deleted by admin]
 |I Use: SMF 2.0.5 | PortaMx 1.51
Q: What do you do when you see a bear in the woods?
A: Play Dead!
H-A-H-L = Happy Admins Have Linux

feline

#5
8 years ago
Great ..  :)
I have changed the query and a lot of columnames .. that's all.

Fel
Many are stubborn in relation to the path, a few in relation to the target.

feline

#6
8 years ago
Of course ...

Try this (after the query):
Code Select

if($smcFunc['db_num_rows']($query) == 0)
echo '<div class="smalltext"><b>No birthday\'s this month</b></div>';
else
{
while(($row = $smcFunc['db_fetch_assoc']($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['member_name'] . '</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['member_name'] . '</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['member_name'] . '</a>';
         echo ' ('.$age.')</span></div>';
      }
      else
      {
         echo '<b>Invalid justification specified: ("'.$justify.'")</b><br>';
         echo 'Use "left", "center", or "right" for script.<hr>';
         die();
      }
   }
}
$smcFunc['db_free_result']($query);
}


Fel
Many are stubborn in relation to the path, a few in relation to the target.

DirtRider

#7
8 years ago
Thanks it works great.
"The real question is not whether machines think but whether men do. "


feline

#8
8 years ago
I think, the "align" statement in div's do not work properly ..
Please try
<div class="smalltext" style="text-align:left;">
or
<div class="smalltext" style="text-align:right;">
or
<div class="smalltext" style="text-align:center;">

Fel
Many are stubborn in relation to the path, a few in relation to the target.

feline

#9
8 years ago
I have that put into a scriptblock:

<div class="smalltext" style="text-align:left;">left align</div>
<
div class="smalltext" style="text-align:center;">center align</div>
<
div class="smalltext" style="text-align:right;">right align</div>


It shows as attach.

Fel


[attachment deleted by admin]
Many are stubborn in relation to the path, a few in relation to the target.

feline

#10
8 years ago
Ahh .. now I understand what you mean  ::)
You will use the align as defined for the block Title ...

Inside a block you can use that with:
<div style="text-align:'. $this->cfg['config']['title_align'] .';">title align</div>

So you can replace this:
Code Select
         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['member_name'] . '</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['member_name'] . '</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['member_name'] . '</a>';
            echo ' ('.$age.')</span></div>';
         }
         else
         {
            echo '<b>Invalid justification specified: ("'.$justify.'")</b><br>';
            echo 'Use "left", "center", or "right" for script.<hr>';
            die();
         }


with this;
Code Select

echo '
<div class="smalltext" style="text-align:'. $this->cfg['config']['title_align'] .';">
  <span class="'.$class.'">('.$age.')
    <a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>
  </span>
</div>';


Fel
Many are stubborn in relation to the path, a few in relation to the target.

DirtRider

#11
8 years ago
Well done with the mod on this code I like it  ;)
"The real question is not whether machines think but whether men do. "


feline

#12
6 years ago
What you have coded inside the PHP block?

el
Many are stubborn in relation to the path, a few in relation to the target.

feline

#13
6 years ago
I have not tested that, but I think this works.
You are sure that you have the code copied completely and correct?

Fel
Many are stubborn in relation to the path, a few in relation to the target.

feline

#14
6 years ago
Here es a other script that show the birthdays of the current month.
Use this only with SMF 2.0 RC4 ...

PHP block code:
Code Select

global $smcFunc, $scripturl, $sourcedir, $txt;

include_once($sourcedir .'/Subs-Calendar.php');
$month = (int) strftime('%m', forum_time());
$year = (int) strftime('%Y', forum_time());

$start_data = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
if($month == 12)
{
$month = 1;
$year++;
}
else
$month++;
$end_data = date('Y-m-d', mktime(0, 0, 0, $month, 0, $year));

$calbirthdays = getBirthdayRange($start_data, $end_data);
ksort($calbirthdays);

foreach($calbirthdays as $cdate => $data)
{
list($cdt['year'], $cdt['month'], $cdt['day']) = explode('-', $cdate);
foreach($data as $vals)
echo $smcFunc['substr']($txt['months'][intval($cdt['month'])], 0, 3) .' '. $cdt['day'] .': <a href="'. $scripturl .'?action=profile;u='. $vals['id'] .'">'. $vals['name'] .(!empty($vals['age']) ? '('. $vals['age'] .')' : '') .'</a><br />';
}


Looks like the attached image ..

Fel

[attachment deleted by admin]
Many are stubborn in relation to the path, a few in relation to the target.