Hack: Birthday/Display Age
Posted by Ryan
August 10, 2009 11:13PM |
Registered: 21 years ago Posts: 666 |
This is a hack to allow users to enter their birthday in the Control Center. They have the option of displaying their age in their profile, and if they choose to, the age is calculated and displayed on the profile page.
If someone wants to turn this into a module, be my guest. I don't have the expertise to do it myself. Brian Moon helped with most of this, so thanks Brian!
1. Create the following custom fields: month, day, year, show_age
2. In cc_usersettings.tpl, add the following:
3. In profile.tpl, add:
-------------------------------------------
"Everything we see or seem, is but a dream within a dream." -Edgar Allan Poe
If someone wants to turn this into a module, be my guest. I don't have the expertise to do it myself. Brian Moon helped with most of this, so thanks Brian!
1. Create the following custom fields: month, day, year, show_age
2. In cc_usersettings.tpl, add the following:
Quote
<dt>Birthday: </dt>
<dd><select name="month">
<option value="">--------</option>
<?php
for ($x=1;$x<=12;$x++) {
echo "<option value=\"$x\"";
if($PHORUM["DATA"]["PROFILE"]["month"]==$x) echo " selected=\"selected\"";
echo ">".date("F", strtotime("2009-$x-1"))."</option>";
}
?>
</select>
<select name="day">
<option value="">--</option>
<?php
for ($x=1;$x<=31;$x++) {
echo "<option";
if($PHORUM["DATA"]["PROFILE"]["day"]==$x) echo " selected=\"selected\"";
echo ">".date("j", strtotime("2009-1-$x"))."</option>";
}
?>
</select>
<select name="year">
<option value="">----</option>
<?php
for($x=date("Y");$x>=date("Y")-99;$x--) {
echo "<option";
if($PHORUM["DATA"]["PROFILE"]["year"]==$x) echo " selected=\"selected\"";
echo ">$x</option>";
}
?>
</select>
Display age in profile? <input type="radio" name="show_age" value="1"{IF PROFILE->show_age "1" OR NOT PROFILE->show_age} checked="checked"{/IF} /> Yes <input type="radio" name="show_age" value="0"{IF PROFILE->show_age "0"} checked="checked"{/IF} /> No</dd>
3. In profile.tpl, add:
Quote
{IF PROFILE->month AND PROFILE->day AND PROFILE->year AND NOT PROFILE->show_age "0"}
<tr>
<td><b>Age:</b></td>
<td><?php
function birthday ($birthday) {
list($year,$month,$day) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
}
echo birthday("{$PHORUM['DATA']['PROFILE']['year']}-{$PHORUM['DATA']['PROFILE']['month']}-{$PHORUM['DATA']['PROFILE']['day']}");
?>
</td>
</tr>
{/IF}
-------------------------------------------
"Everything we see or seem, is but a dream within a dream." -Edgar Allan Poe
August 11, 2009 02:55AM |
Admin Registered: 20 years ago Posts: 8,532 |
I admire both your and Brian's stamina on getting this hack going. Reading the IRC logs what quite the job this morning ;-)
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



September 03, 2009 02:24PM |
Registered: 17 years ago Posts: 533 |
Sorry, only registered users may post in this forum.