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

* Navigator

Expand - Collapse

* Statistic

  • *Total Posts: 16403
  • *Total Topics: 2518
  • *Online Today: 8
  • *Most Online: 292
(12. Nov 2016, 09:37:31)
  • *Users: 0
  • *Guests: 0
  • *Spiders: 1
  • *Total: 1

  • *Yahoo!

Upcoming birthdays

Started by DirtRider, 24. Nov 2008, 19:42:22

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

Go Down

DirtRider

24. Nov 2008, 19:42:22
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
24. Nov 2008, 19:55:05
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
24. Nov 2008, 20:35:28
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
24. Nov 2008, 20:53:07
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
24. Nov 2008, 21:41:17
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
24. Nov 2008, 21:43:19
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.

digiscrap

#6
25. Nov 2008, 10:05:34
Quote from: Cool on 24. Nov 2008, 21:41:17
Feline is just GREAT :-*


Yes, she is! Thanks Feline.

Quote from: feline on 24. Nov 2008, 21:43:19
Great ..  :)
I have changed the query and a lot of columnames .. that's all.

Fel


Great script. Could it be possible, when there are no birthday's 'this' month, the block displayed a text like: No birthday's this month or simple 'Non...'. Text can be changed in the script, I think.

Now I see a blank block when there's no birthday this month.

Thanks in advance!

Vincent
Digiscrap Digitaal scrappen | Digiscrap Fotoservice

SMF2.0.5 + PortaMx v1.45
Dutch translation PortaMx1.45

feline

#7
25. Nov 2008, 10:47:27
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

#8
25. Nov 2008, 11:58:22
Thanks it works great.
"The real question is not whether machines think but whether men do. "


digiscrap

#9
25. Nov 2008, 12:52:25
Quote from: feline on 25. Nov 2008, 10:47:27
Of course ...

Fel


Nice! That looks great! thank you! I tried to change the code a bit to display the date and month (see Attachment). The date and month are  linked to the calendar. I'm not a PHP programmer so maybe I did something which is not allowed in the "PHP world". Pleas feel free to correct that.... 

Only one question... that 'justify' thing doesn't work correct (also with the original script from you). The title of the block moves correct to left or right but the content doesn't.

The changed code:
Code Select
         
         echo '<div class="smalltext" align="left"><span class="'.$class.'">';
      echo '<a href="' . $scripturl . '?action=calendar;year=' . $current_date['year'] .';month=' . $current_date['mon'] . '">' .$dob_day.'-'.$dob_month.'<a/>  ';
         echo '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>';
         echo '  ('.$age.')</span></div>';
      }
      elseif(strtolower($justify) == 'right')
      {
         echo '<div class="smalltext" align="right"><span class="'.$class.'"> ('.$age.') ';
         echo '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>';
   echo '<a href="' . $scripturl . '?action=calendar;year=' . $current_date['year'] .';month=' . $current_date['mon'] . '">' .$dob_day.'-'.$dob_month.'<a/>  ';
      }
      elseif(strtolower($justify) == 'center')
      {
         echo '<div class="smalltext" align="center"><span class="'.$class.'">';
   echo '<a href="' . $scripturl . '?action=calendar;year=' . $current_date['year'] .';month=' . $current_date['mon'] . '">' .$dob_day.'-'.$dob_month.'<a/>  ';
         echo '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>';
         echo '  ('.$age.')</span></div>';


[attachment deleted by admin]
Digiscrap Digitaal scrappen | Digiscrap Fotoservice

SMF2.0.5 + PortaMx v1.45
Dutch translation PortaMx1.45

feline

#10
25. Nov 2008, 13:20:14
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.

digiscrap

#11
25. Nov 2008, 14:34:10

Hmmmm doesn't make any sense.....   :-\

It is always displaying 'Left'... also the text from the 'left' section (I'd put in a L(left) / R(right) / C(center) into the code to check.

Vincent
Digiscrap Digitaal scrappen | Digiscrap Fotoservice

SMF2.0.5 + PortaMx v1.45
Dutch translation PortaMx1.45

feline

#12
25. Nov 2008, 19:40:35
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.

digiscrap

#13
25. Nov 2008, 20:41:59
Quote from: feline on 25. Nov 2008, 19:40:35
I have that put into a scriptblock:

Fel


That's not the problem. Sorry...

I mean.. in the script you find the 3 'automatic' settings (Left, Right and Center);

Code Select
if(strtolower($justify) == 'left')
  the 'when you select left' code
elseif(strtolower($justify) == 'right')
  the 'when you select right' code
elseif(strtolower($justify) == 'center')
  the 'when you select center' code


These will be chosen when you select (Left, Right and Center) in the block settings (see attachment).

But, please.... I'm not using these left/right/center settings for this block so I don't need them. I can ignore or remove it from the script. It was something I found which was not working correct. And of course I know it isn't your script. So, if you don't have time for it... no problem! I don't want to wast your valuable time. Altough it could be a nice 'Code Snippet'....  ;)

Gruse Vincent

[attachment deleted by admin]
Digiscrap Digitaal scrappen | Digiscrap Fotoservice

SMF2.0.5 + PortaMx v1.45
Dutch translation PortaMx1.45

feline

#14
25. Nov 2008, 20:55:48
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.

Go Up