09 Birthday Mod

Started by Mindless, July 21, 2012, 05:41:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
Credits to the original coders, dont know exactly who that was.
Xhtml valid

Run the sql

Code (sql) Select
ALTER TABLE users ADD `birthday` date default '0000-00-00';

Add to my.php/usercp.php where you want it to show

   
Code (php) Select
//==09 Birthday
    $day = $month = $year = '';
    $birthday = $CURUSER["birthday"];
    $birthday = date("Y-m-d", strtotime($birthday));
    list($year1, $month1, $day1) = split('-', $birthday);
    if ($CURUSER['birthday'] == "0000-00-00") {
    $year .= "<select name=\"year\"><option value=\"0000\">--</option>\n";
    $i = "1950";
    while ($i <= (date('Y', time())-13)) {
    $year .= "<option value=\"".$i."\">" . $i . "</option>\n";
    $i++;
    }
    $year .= "</select>\n";
    $birthmonths = array("01" => "January",
    "02" => "Febuary",
    "03" => "March",
    "04" => "April",
    "05" => "May",
    "06" => "June",
    "07" => "July",
    "08" => "August",
    "09" => "September",
    "10" => "October",
    "11" => "November",
    "12" => "December",);
    $month = "<select name=\"month\"><option value=\"00\">--</option>\n";
    foreach ($birthmonths as $month_no => $show_month) {
    $month .= "<option value=\"$month_no\">$show_month</option>\n";
    }
    $month .= "</select>\n";
    $day .= "<select name=\"day\"><option value=\"00\">--</option>\n";
    $i = 1;
    while ($i <= 31) {
    if ($i < 10) {
    $day .= "<option value=\"0".$i."\">0" . $i . "</option>\n";
    } else {
    $day .= "<option value=\"".$i."\">" . $i . "</option>\n";
    }
    $i++;
    }
    $day .= "</select>\n";
    $HTMLOUT .= tr("Birthday", $year . $month . $day , 1);
    }
    //== End

     
Next add this to takeeditcp.php/takeprofileedit.php :

   
Code (php) Select
if ($CURUSER['birthday'] == "0000-00-00") {
    $year = isset($_POST["year"]) ? 0 + $_POST["year"] : 0;
    $month = isset($_POST["month"]) ? 0 + $_POST["month"] : 0;
    $day = isset($_POST["day"]) ? 0 + $_POST["day"] : 0;
    $birthday = date("$year.$month.$day");
    if ($year == '0000')
    stderr("Error", "Please set your birth year.");
    if ($month == '00')
    stderr("Error","Please set your birth month.");
    if ($day == '00')
    stderr("Error","Please set your birth day.");
    if (!checkdate($month, $day, $year))
  stderr("Error", "<br /><div align='center'><font color='red' size='+1'>The date entered is not a valid date, please try again</font></div><br />");
    $updateset[] = "birthday = ".sqlesc($birthday);
    }

   
For displaying the birthdays i made this and its now tested and verifed  - Add to index where you want it to show :
   
index.php
           
cache version

Code (php) Select
     //==09 users birthdays
$birthdayusers3 ="";
$file = "./cache/birthdays.txt";
$expire = 43200; // 12 hours
if (file_exists($file) && filemtime($file) > (time() - $expire)) {
$birthdayusers3 = unserialize(file_get_contents($file));
} else {
$current_date = getdate();
$birthdayusers1 = mysql_query("SELECT id, username, birthday, class, title, warned, enabled, chatpost, leechwarn, pirate, king, donor FROM users WHERE MONTH(birthday) =".sqlesc($current_date['mon'])." AND DAYOFMONTH(birthday) = ".sqlesc($current_date['mday'])." ORDER BY username ASC") or sqlerr(__FILE__, __LINE__);
    while ($birthdayusers2 = mysql_fetch_assoc($birthdayusers1)) {
        $birthdayusers3[] = $birthdayusers2;
    }
    $OUTPUT = serialize($birthdayusers3);
    $fp = fopen($file, "w");
    fputs($fp, $OUTPUT);
    fclose($fp);
} // end else
$birthdayusers = "";
if (is_array($birthdayusers3))
foreach ($birthdayusers3 as $arr) {
    if ($birthdayusers)
    $birthdayusers .= ",\n";
    $birthdayusers .= "<span style=\"white-space: nowrap;\">";
    $arr["username"] = "<font color='#" . get_user_class_color($arr['class']) . "'> " . htmlspecialchars($arr['username']) . "</font>";
    $donator = $arr["donor"] === "yes";
    $warned = $arr["warned"] === 1;

    if ($CURUSER)
        $birthdayusers .= "<a href='{$TBDEV['baseurl']}/userdetails.php?id={$arr["id"]}'><b>{$arr["username"]}</b></a>";
    else
        $birthdayusers .= "<b>{$arr["username"]}</b>";
    if ($donator)
         $birthdayusers .= "<img src='{$TBDEV['pic_base_url']}star.gif' alt='Donated' />";
    if ($warned)
        $birthdayusers .= "<img src='{$TBDEV['pic_base_url']}warned.gif' alt='Warned' />";
    $birthdayusers .= "</span>";
}

if (!$birthdayusers)
    $birthdayusers = "{$lang['index_nobirthdays']}";
   
    $HTMLOUT .= "<div style='text-align:left;width:80%;border:1px solid blue;padding:5px;'>
    <div style='background:lightgrey;height:25px;'><span style='font-weight:bold;font-size:12pt;'>{$lang['index_birthdays']}</span></div>
";
     $HTMLOUT .="<table border='1' cellpadding='10' cellspacing='0' width='100%'>
      <tr class='table'>
      <td class='text'>{$birthdayusers}</td>";
     $HTMLOUT .="</tr></table></div>";

   
 
If your clever you'll be running memcached so here is the display code for that - tested and working perfect :
 
  memcached version
     
     Add to config.php :
     
     Note expires is set to 12 hours
     
     
Code (php) Select
$TBDEV['expires']['birthdayusers'] = 43200;
     

Add to index.php where you want it to show :

     
     
Code (php) Select
//==Start birthdayusers
     $current_date = getdate();
     $keys['birthdayusers'] = 'birthdayusers';
     $birthday_users_cache = $mc1->get_value($keys['birthdayusers']);
     if ($birthday_users_cache === false) {                     
     $birthdayusers = '';
     $birthday_users_cache = array();
     $res = mysql_query("SELECT id, username, class, donor, title, warned, enabled, chatpost, leechwarn, pirate, king, birthday FROM users WHERE MONTH(birthday) = ".sqlesc($current_date['mon'])." AND DAYOFMONTH(birthday) = ".sqlesc($current_date['mday'])." ORDER BY username ASC") or sqlerr(__FILE__, __LINE__);
     $actcount = mysql_num_rows($res);
     while ($arr = mysql_fetch_assoc($res)) {
     if ($birthdayusers)
     $birthdayusers .= ",\n";
     $birthdayusers .= '<b>'.format_username($arr).'</b>';
     }
     $birthday_users_cache['birthdayusers'] = $birthdayusers;
     $birthday_users_cache['actcount']    = $actcount;
     $mc1->cache_value($keys['birthdayusers'] , $birthday_users_cache, $TBDEV['expires']['birthdayusers']);
     }
     if (!$birthday_users_cache['birthdayusers'])
     $birthday_users_cache['birthdayusers'] = 'There is no members birthdays today.';
     $birthday_users = '<div class="headline">'.$lang['index_birthdays'].'&nbsp;('.$birthday_users_cache['actcount'].')</div>
     <div class="headbody">
     <!--<a href=\'javascript: klappe_news("a1")\'><img border=\'0\' src=\'pic/plus.gif\' id=\'pica1\' alt=\'[Hide/Show]\' /></a><div id=\'ka1\' style=\'display: none;\'>-->
      '.$birthday_users_cache['birthdayusers'].'
     </div><!--</div>-->';
     $HTMLOUT .= $birthday_users;
     //== end birthdayusers

     
You'll need to add a delete key right under the query in takesignup.php and right under the updateset on takeeditcp.php/takeprofileedit.php incase the persons birthday is that day and outwith the cache expire value :

Code (php) Select
$mc1->delete_value('birthdayusers');


    lang/en/lang_index.php add :
   
   
Code (php) Select
'index_birthdays' => "Members birthdays",
   
   
Code (php) Select
'index_nobirthdays' => "There is no members birthdays today.",
   
     signup.php
     
     Add it where you want it to show :
     
     
Code (php) Select
//==09 Birthday mod
     $year = $month = $day ='';
     $year .= "<select name=\"year\">";
     $year .= "<option value=\"0000\">Year</option>";
     $i = "2030";
     while($i >= 1950){
     $year .= "<option value=\"".$i."\">".$i."</option>";
     $i--;
     }
     $year .= "</select>";
     $month .= "<select name=\"month\">
     <option value=\"00\">Month</option>
     <option value=\"01\">January</option>
     <option value=\"02\">Febuary</option>
     <option value=\"03\">March</option>
     <option value=\"04\">April</option>
     <option value=\"05\">May</option>
     <option value=\"06\">June</option>
     <option value=\"07\">July</option>
     <option value=\"08\">August</option>
     <option value=\"09\">September</option>
     <option value=\"10\">October</option>
     <option value=\"11\">November</option>
     <option value=\"12\">December</option>
     </select>";
     $day .= "<select name=\"day\">";
     $day .= "<option value=\"00\">Day</option>";
     $i = 1;
     while($i <= 31){
     if($i < 10){
     $day .= "<option value=\"0".$i."\">0".$i."</option>";
     }else{
     $day .= "<option value=\"".$i."\">".$i."</option>";
     }
     $i++;
     }
     $day .= "</select>";
     $HTMLOUT .= tr("Birthday<font color=\"red\">*</font>", $year . $month . $day ,1);
     //==End

     
     
     takesignup.php find :
     
     
Code (php) Select
if (!validusername($wantusername))
      stderr($lang['takesignup_user_error'], $lang['takesignup_invalidname']);


Under it add :

     
Code (php) Select
if (!(isset($_POST['day']) || isset($_POST['month']) || isset($_POST['year'])))
  stderr('Error','You have to fill in your birthday');

    if (checkdate($_POST['month'], $_POST['day'], $_POST['year']))
  $birthday = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
    else
  stderr('Error','You have to fill in your birthday correctly');

    if ((date('Y') - $_POST['year']) < 17)
     stderr('Error','You must be at least 18 years old to register.');



Then say after editsecret in the query add


     
Code (php) Select
birthday,
     
     
Code (php) Select
$birthday,
     
   
Last on userdetails.php add this where you want it :
 
    userdetails.php
   
     
   
Code (php) Select
//==09 Birthday mod
    $age = $birthday ='';
    if ($user['birthday'] != "0000-00-00") {
    $current = gmdate("Y-m-d", time());
    list($year2, $month2, $day2) = split('-', $current);
    $birthday = $user["birthday"];
    $birthday = date("Y-m-d", strtotime($birthday));
    list($year1, $month1, $day1) = split('-', $birthday);
    if ($month2 < $month1) {
        $age = $year2 - $year1 - 1;
    }
    if ($month2 == $month1) {
        if ($day2 < $day1) {
            $age = $year2 - $year1 - 1;
        } else {
            $age = $year2 - $year1;
        }
    }
    if ($month2 > $month1) {
        $age = $year2 - $year1;
    }
    $HTMLOUT .="<tr><td class='rowhead'>Age</td><td align='left'>".htmlentities($age)."</td></tr>\n";
    $birthday = date("Y-m-d", strtotime($birthday));
    $HTMLOUT .="<tr><td class='rowhead'>Birthday</td><td align='left'>".htmlentities($birthday)."</td></tr>\n";
    }
    //==End

   
Not finished yet so it will change - You can test it for now but i'll be updating the post soon. Lang is still to be completed as well but thats not important atm as the code may still need improved and updated  ^-^