News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Congratulating a user that is having a birthday

Started by Compuart, October 08, 2005, 07:55:25 AM

Previous topic - Next topic

Compuart

Suppose you want to make changes to your templates, if it's someones birthday, for instance by greeting him/her with a special message. Here's how to do it.

Step 1. Calculate whether it's a birthday and store it in $user_info.

Code (search: Load.php) Select
$user_info['groups'] = array_unique($user_info['groups']);


Code (add after) Select
if (isset($user_settings['birthdate']))
{
$cur_date = getdate(forum_time());
$user_info['today_is_birthday'] = $cur_date['mon'] == substr($user_settings['birthdate'], 5, 2) && $cur_date['mday'] == substr($user_settings['birthdate'], 8);
}




Step 2. Pass the value to the template $context variable.

Code (search: Load.php) Select
'email' => &$user_info['email']


Code (replace) Select
'email' => &$user_info['email'],
'today_is_birthday' => &$user_info['today_is_birthday'],




Step 3. Use the $context value to tweak the template

for instance:
Code (search: index.template.php) Select
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';


Code (replace) Select
if ($context['user']['today_is_birthday'])
echo '
CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';



Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

cotdagoo

I get Undefined index: time_offset errors trying to apply this in 1.1b3

Compuart

Odd. Can you confirm that the additional code in step 1 is put after this block of code?

	
// Set up the $user_info array.
	
$user_info += array(
	
	
'username' => $username,
	
	
'name' => isset($user_settings['realName']) ? $user_settings['realName'] : '',
	
	
'email' => isset($user_settings['emailAddress']) ? $user_settings['emailAddress'] : '',
	
	
'passwd' => isset($user_settings['passwd']) ? $user_settings['passwd'] : '',
(...)
	
	
'permissions' => array()
	
);
	
$user_info['groups'] = array_unique($user_info['groups']);

Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

cotdagoo

Hmm.. looks like vWarnMod has re-arranged that piece of code in Load.php - and it's now appearing above like this:

// we do this here, so we don't have to do it for warnings seperately ;)
$user_info['groups'] = array_unique($user_info['groups']);

// only warning-groups in this one :D
$user_info['warnings'] = array_intersect($user_info['groups'], array_keys($warningGroups));
}
// If the user is a guest, initialize all the critial user settings.
else
{
// This is what a guest's variables should be.
$username = '';
$user_info = array('groups' => array(-1), 'warnings' => array());
$user_settings = array();

if (isset($_COOKIE[$cookiename]))
$_COOKIE[$cookiename] = '';
}

// Set up the $user_info array.

Compuart

It can be put it the very end of the loadUserSettings() function, doesn't really matter. As long as $user_info['time_offset'] has been set.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

DomP

I like this mod :)

I think my install was okay  too.......

I changed birthday but get an template error now, this only affects me. Other users don't have the problem So I think it only happens during that day for everyone who has a birthday.

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in .../Themes/default/index.template.php on line 234

225: if (!empty($context['user']['avatar']))
226: echo '<td valign="middle">', $context['user']['avatar']['image'], '</td>';
227:
228: echo '<td valign="top" class="smalltext" style="width: 100%; font-family: verdana, arial, sans-serif;">';
229:
230: // If the user is logged in, display stuff like their name, new messages, etc.
231: if ($context['user']['is_logged'])
232: {
233: echo '

234: if ($context['user']['today_is_birthday'])

235: echo '
236: CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
237: else
238: echo '



It's also causing an template error at the bridged Coppermine Gallery

Hope this helps

Compuart

remove the
echo '
from line 233, should do the trick.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

DomP

I fixed that, only problem is still with the gallery ...

Fatal error: Call to undefined function forum_time() in /home/online16/public_html/gallery/bridge/smf.inc.php(127) : eval()'d code on line 158


158:   // get first 50 chars
159:     $HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
160:     $REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);


Any idea ?

Compuart

Make sure that before the bridge calls the loadUserSettings() function it first includes the Subs.php file.

So replace (at some point in the bridge):
loadUserSettings();

by:
require_once($sourcedir . '/Subs.php');
loadUserSettings();
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

DomP

Did that... now it gives me:

Fatal error: Cannot redeclare db_query() (previously declared in /home/online16/public_html/gallery/include/functions.inc.php:71) in /home/online16/public_html/forum/Sources/Subs.php on line 322

Subs.php

317:     // Debugging.
318:     if (isset($GLOBALS['db_show_debug']) && $GLOBALS['db_show_debug'] === true)
319: $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
320:
321: return $ret;
322:    }


I'm lost ;)

Compuart

maybe instead of
require_once($sourcedir . '/Subs.php');

define the missing function:
function forum_time($use_user_offset = true, $timestamp = null)
{
global $user_info, $modSettings;

if ($timestamp === null)
$timestamp = time();
elseif ($timestamp == 0)
return 0;

return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
}

hope this works.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

DomP

Kewl seems to be okay now :)

Thanx for the great mod :)

"goed weekend" ;)

Compuart

Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

ViV

Similarly, Is there a way in which a small cake can appear next to a person's name, in his posts and in user's online list, when it's his/her birthday???


Compuart

Quote from: ViV on October 20, 2005, 05:26:44 AM
Similarly, Is there a way in which a small cake can appear next to a person's name, in his posts and in user's online list, when it's his/her birthday???
This modification only works for the person who's birthday it is. The option to change a name in online lists and posts would need to compare the birthday of every member shown to the current date. For that you could adjust the loadUser function which loads the user data for most screens. But that's beyond the scope of this modification.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

TechnoDragon

Okay...i read this post and there were several code snippets all over...could someone possibly post the final tested working code in one message?

and which version of SMF is it for?
Don't tell me to get into shape...I have a shape...It is round!


Compuart

The first message still contains the right code. It'll work for both 1.1 RC1 (default theme) and 1.1 RC2 (babylon theme).
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

TechnoDragon

ok...i entered the code exactly as you have listed and it still does not show up in the status box...it just still says "hey, username"

Am i missing something?

EDIT: Never mind...figured it out!
Don't tell me to get into shape...I have a shape...It is round!


Aitsukai

Any way to send them a PM when they log in for the first time on their birthday?

SekondeR

is this can be a module?
so that we can change the message easily  etc... ?

ArkServer

Step 3. Use the $context value to tweak the template

for instance:
Code (search: index.template.php) Select
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';


Code (replace) Select
if ($context['user']['today_is_birthday'])
echo '
CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';





im not sure how to do this in 1.1 rc2

sonic


geezmo

Hopefully someone can show the codes we need to make this work in 1.1RC2 or better, make a mod from this one.

husmen73 (Gulhin)

-Kurumsal Kimlik Web Tasarım Hizmeti.
Gülhin Portal Sistemi hakkında yorumlarınızı bekliyorum.
SMF
Referanslar --> http://www.gulhin.com/referanslar-portfoy/
-Web Tasarımı ve Tema Tasarımı Sitesi www.gulhin.com
-TOPLU MAİL GÖNDERİMİ --> http://www.toplumailsms.com
E-Ticaret Sistemi yaptırmak mı istiyorsunuz?

TechnoDragon

Here is the code snippet...it also includes the good morning, afternoon, evening code as well.

        if ($context['user']['is_logged'])
        {
if ($context['user']['today_is_birthday'])
echo '<span class="normaltext">

<SCRIPT LANGUAGE="JavaScript">

<!--Begin

datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);

//  End -->

</script>

<br>Happy Birthday! <br> <b>', $context['user']['name'], '</b>, <br>have a piece of cake!<br><img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">

<!--Begin

datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);

//  End -->

</script> <br> <b>', $context['user']['name'], '</b></span>';


it should replace what is below this:
        // If the user is logged in, display stuff like their name, new messages, etc.


Sorry cannot remember what the original code was...but should go in the index template...i know that line exists in tinyportal...i'll look around and see if i can find where the original unedited code is...
Don't tell me to get into shape...I have a shape...It is round!


PrizeLive.com

Get Paid Instantly via PayPal (or other options) at PrizeLive.com!

TechnoDragon

It changes the standard "Hey [username]" to either Good morning, good afternoon, good evening, [username] as well as when it is the members birthday it changes the greeting on that day only to Happy Birthday [username], have a piece of cake, with an image of a piece of cake.
Don't tell me to get into shape...I have a shape...It is round!


geezmo

Does this code change the welcome greeting to a happy birthday greeting once the member is logged in or does it send a PM or email when it's a person's birthday? I want to have a code that sends an email or PM when it's a member's birthday.

TechnoDragon

You might be able (or someone sles) to accomplish that, but as it is written it only changes the greeting
Don't tell me to get into shape...I have a shape...It is round!


StarBuG

Thanks, this is a realy great Idea.

Implemented it in rc2 with a little tweaking.

Workes perfect

StarBuG
Elternfragen.net - Das Forum für Eltern (SMF)
Fragen und Antworten rund um das Thema Kinder, Entwicklung, Ernährung und Gesundheit unserer Kleinen.
-------------
Patientenfragen.net - Das Forum von Patienten für Patienten
Fragen und Antworten rund um das Thema Krankheit und Gesundheit.
-------------
Hiphop-Battles.com - Version 2
The new standard in online hip hop battles

Loverboy


codenaught

Quote from: LocoTurk on September 16, 2006, 10:18:46 AM
Does this work with RC3?
Almost, the one change for RC3 with use of the new default theme (Core) or themes styled after it, is for the file Themes/default/index.template.php you have to look for:

if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';


and change it to:

if ($context['user']['today_is_birthday'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;">CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" /></span>
</td>';
else if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';


The changes for Load.php are the same.
Dev Consultant
Former SMF Doc Coordinator

Loverboy

Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?

xcrazyxfrogx

Quote from: akabugeyes on September 22, 2006, 07:28:54 PM
Quote from: LocoTurk on September 16, 2006, 10:18:46 AM
Does this work with RC3?
Almost, the one change for RC3 with use of the new default theme (Core) or themes styled after it, is for the file Themes/default/index.template.php you have to look for:

if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';


and change it to:

if ($context['user']['today_is_birthday'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;">CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" /></span>
</td>';
else if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';


The changes for Load.php are the same.
not working on index of site the hello thing also got removed and nothing no cake image or somthing


Money... my obsession... Wealth... my addiction... Fear... my weapon... Crazy people... don't you understand... from the smokes of fear... who I am?

digit

I would like to display a slice of cake below users avatars on the Display.template.php page.

so, I tried this...


echo '
', $context['member']['age'] . ($context['member']['today_is_birthday'] ? ' &nbsp; <img src="' . $settings['images_url'] . '/bdaycake.gif" width="40" alt="" />' : ''), '';



It didn't work.  Can someone please help me get this snippet working?

Thanks in advance.

Happily using a heavily modified 1.1.16 version of SMF!

2748011 Posts in 320998 Topics by 50986 Members


SOLD my website - thanks it was a good run - they converted to vbadvanced. (and screwed it up good!)

guilliam

@digit,

you have two single qoutation mark on your echo.

- g
----
SMF ported on Joomla:
http://www.jcip-zugbuana.org

rzx

Quote from: LocoTurk on September 23, 2006, 11:46:10 PM
Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?

Something like this would be nice.

GC

Does it not do that already? My site had sent me an e-mail on my birthday.

cmcmom

What I do is just do a NEWS item... make it bold and a large font.....it looks good....no code needed!

digit

Quote from: Loverboy on September 23, 2006, 11:46:10 PM
Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?

I would like to see this too...  my mods are overworked!
Happily using a heavily modified 1.1.16 version of SMF!

2748011 Posts in 320998 Topics by 50986 Members


SOLD my website - thanks it was a good run - they converted to vbadvanced. (and screwed it up good!)

Aileen

IS there any version of this for dummies like me?

Deaks

~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

digit

I would like a way to automatically PM members with Random Birthday greetings from predesigned Templates. :-)

Happily using a heavily modified 1.1.16 version of SMF!

2748011 Posts in 320998 Topics by 50986 Members


SOLD my website - thanks it was a good run - they converted to vbadvanced. (and screwed it up good!)

Aileen


Deaks

hi Aileen, this is possible, however his feature is one of the features that have been announced when smf2 is released as stable... if you can wait that long... if you cant wait ill try and work the coding for you :)
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Aileen

I see, thanks Runic Warrior :) BTW when will it be released?

Deaks

~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Fallen Angel

Doe's this mod works with SMF 1.1.4 and Dilber MC theme??


  if ($context['user']['is_logged'])
        {
if ($context['user']['today_is_birthday'])
echo '<span class="normaltext">

<SCRIPT LANGUAGE="JavaScript">

<!--Begin

datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);

//  End -->

</script>

<br>Happy Birthday! <br> <b>', $context['user']['name'], '</b>, <br>have a piece of cake!<br><img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">

<!--Begin

datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);

//  End -->

</script> <br> <b>', $context['user']['name'], '</b></span>';

H

It should do. Make sure the first bit of code goes into load.php, as described in the first post. You'll then need to make sure the code for index.template.php goes in the index.template.php of the diblermc theme instead of the default theme.
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             


Sarge


    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Jessikard

sorry but i´m searching for a mod like this soon

i know there is a mod  "welcome topic" and i hope someone can help me

i´m not a specialist in coding but i think if a coder could change the request to the database
like ->birthday_field instead of ->new_registration that would be perfekt

is there an way to do it ?

agbattery

I like this detailed information brout forth in these forums.  I cant wait to share some of my knowledge and coding experience.
OEM hxxp:www.accessorygenie.com/batteries-c-1.html [nonactive], hxxp:www.accessorygenie.com/battery-chargers-c-2.html [nonactive], hxxp:www.accessorygenie.com/ac-adapters-c-3.html [nonactive], hxxp:www.accessorygenie.com/memory-cards-c-4.html [nonactive], hxxp:www.accessorygenie.com/gps-c-102.html [nonactive], hxxp:www.accessorygenie.com/radar-detectors-c-103.html [nonactive], and other hxxp:www.accessorygenie.com [nonactive]

Tyrsson

@Jessikard

You may want to try posting in this board to see if someone can help you find a solution :)

SMF Coding Discussion
PM at your own risk, some I answer, if they are interesting, some I ignore.

blanix

My SMF: 1.1.9

Advertisement: