<?php
require 'includes/facebook.php';
$member_query=mysql_query("SELECT *,(YEAR(CURDATE())-YEAR(adv_dob)) - (RIGHT(CURDATE(),5) < RIGHT(adv_dob,5)) AS age, DATE_FORMAT(adv_dob, '%M %d') as adv_dob FROM adverts LEFT JOIN members ON (adv_userid=mem_userid) LEFT JOIN Geo_Countries ON (adv_countryid = CountryId) WHERE adv_userid = '$WUserID' AND adv_approved='1'") or die(mysql_error());
$sql_array = mysql_fetch_object($member_query);

$sponsorRank_query = mysql_query("SET @rank = 0");
$sponsorRank_query = mysql_query("SELECT rank
FROM (

SELECT @rank := @rank +1 AS rank, mem_userid, totalRank, mem_joindate
FROM (
SELECT *, COUNT( mem_referrer ) AS totalRank FROM (
SELECT B.mem_userid, A.mem_referrer, A.mem_joindate
FROM members AS B LEFT JOIN members AS A ON ( B.mem_userid = A.mem_referrer )order by A.mem_joindate desc
) as listing
GROUP BY mem_userid, mem_referrer
) as result

ORDER BY totalRank DESC , mem_joindate DESC, mem_userid ASC
) as data

WHERE mem_userid ='$WUserID'");
$sponsorRank = mysql_fetch_array($sponsorRank_query);

$suspended_list="0";
$mem_q=mysql_query("select * from blockmail where blk_receiverid='$WUserID'");
while($mem=mysql_fetch_array($mem_q))
{
$suspended_list.=",".$mem["blk_senderid"];
}

$msgr=mysql_query("SELECT * FROM messages LEFT JOIN adverts ON (msg_senderid=adv_userid) LEFT JOIN members ON (msg_senderid=mem_userid) WHERE (msg_receiverid='$WUserID') AND msg_receiverdel='N' AND adv_approved='1' AND msg_senderid not in ($suspended_list) AND msg_read='U' ORDER BY msg_dateadded DESC") or die(mysql_error());
$msgrTOTAL = mysql_num_rows($msgr);

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '132880206758943',
  'secret' => '16d42b51af2920ff3c03f9dbf7c0d5e2',
  'cookie' => true,
));

$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $me = null;
  }
}

function HahaperAge($datefrom,$dateto=-1)
{
        // Defaults and assume if 0 is passed in that
        // its an error rather than the epoch
   
        if($datefrom==0) { return "0"; }
        if($dateto==-1) { $dateto = time(); }
       
        // Make the entered date into Unix timestamp from MySQL datetime field

        $datefrom = strtotime($datefrom);
   
        // Calculate the difference in seconds betweeen
        // the two timestamps

		  $difference = $dateto - $datefrom;
		  if($difference < 0) {
		  return false;
		  }

        // Based on the interval, determine the
        // number of units between the two dates
        // From this point on, you would be hard
        // pushed telling the difference between
        // this function and DateDiff. If the $datediff
        // returned is 1, be sure to return the singular
        // of the unit, e.g. 'day' rather 'days'
   
				if((strtotime('-1 day', $dateto) < $datefrom) || (strtotime('-1 hour', $dateto) < $datefrom) || (strtotime('-1 min', $dateto) < $datefrom)) {

            // If difference is between 1 hour and 24 hours
            // hours is a good interval
                $dateH = floor($difference / 60 / 60);
					 if($dateH > 0) {
					 $dateH = ($dateH<10) ? "0".$dateH : $dateH;
//                $res = ($dateH==1) ? $dateH.' hr ' : $dateH.' hrs ';
 					 $wordH= ($dateH==1) ? 'hour' : 'hour';
                $short = "<span title=\"$wordH\" >$dateH : </span>";
                $res = "$dateH $wordH ";
					 }

            // If difference is between 60 seconds and
            // 60 minutes, minutes is a good interval
                $difference = $difference % (60 * 60); 
					 $dateM = floor($difference / 60);
					 if($dateM > 0) {
                $dateM = ($dateM<10) ? "0".$dateM : $dateM;
//                $res .= ($dateM==1) ? $dateM.' min ' : $dateM.' mins ';
 					 $wordM= ($dateM==1) ? 'minute' : 'minutes';
                $short .= "<span title=\"$wordM\" >$dateM : </span>";
                $res .= "$dateM $wordM ";
					 }

            // If difference is less than 60 seconds,
            // seconds is a good interval of choice
                $difference = $difference % (60); 
                $dateS = floor($difference);
					 if($dateS > 0) {
                $dateS = ($dateS<10) ? "0".$dateS : $dateS;
//                $res .= ($dateS==1) ? $dateS.' sec' : $dateS.' secs';
 					 $wordS= ($dateS==1) ? 'second' : 'seconds';
                $short .= "<span title=\"$wordS\" >$dateS</span>";
                $res .= "$dateS $wordS";
					 }

				} else {

            // If difference is greater than or equal to 365
            // days, return year. This will be incorrect if
            // for example, you call the function on the 28th April
            // 2008 passing in 29th April 2007. It will return
            // 1 year ago when in actual fact (yawn!) not quite
            // a year has gone by
					 $year_difference = 1;
                while (strtotime('-'.$year_difference.' year', $dateto) >= $datefrom)
                {
                    $year_difference++;
                }
               
                $dateY = $year_difference-1;
					 if ($dateY > 0) {
                $dateY = ($dateY<10) ? "0".$dateY : $dateY;
                $res = ($dateY==1) ? $dateY.' year ' : $dateY.' years ';
                $short .= $dateY.' Y ';
//						$wordY= ($dateY==1) ? 'year' : 'years';
//                  $res = "<span title=\"$wordY\" >$dateY : </span>";
					 }

            // If difference is between 30 days and 365 days
            // months is a good interval, again, the same thing
            // applies, if the 29th February happens to exist
            // between your 2 dates, the function will return
            // the 'incorrect' value for a day
					 $months_difference = 1;
                while (strtotime('-'.$months_difference.' month', $dateto) >= $datefrom)
                {
                    $months_difference++;
                }
               
                $dateM = $months_difference-1;
					 if ($dateM > 0) {
					 if ($dateM >= 12) {
					 	$dateM -= (floor($dateM/12)*12);
					 }
                $dateM = ($dateM<10) ? "0".$dateM : $dateM;
                $res .= ($dateM==1) ? $dateM.' month ' : $dateM.' months ';
                $short .= $dateM.' M ';
//						$wordM= ($dateM==1) ? 'month' : 'months';
//                  $res .= "<span title=\"$wordM\" >$dateM : </span>";
					}

            // If difference is between 1 day and 7 days
            // days is a good interval
					 $day_difference = 1;
                while (strtotime('-'.$day_difference.' day', $dateto) >= $datefrom)
                {
                    $day_difference++;
                }
               
                $dateD = $day_difference-1;
					 if ($dateD >= 30) {
					 	if ($dateD>365) {
						$dateD -= 365;
						}
					 	$dateD -= (floor($dateD/30)*30);
					 }
                $dateD = ($dateD<10) ? "0".$dateD : $dateD;
                $res .= ($dateD==1) ? $dateD.' day' : $dateD.' days';
                $short .= $dateD.' D';
//						$wordD= ($dateD==1) ? 'day' : 'days';
//                  $res .= "<span title=\"$wordD\" >$dateD</span>";
			}
               
        return array($short,$res);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<title>Socializer - Wauhaha! Internet Routine Activity on Demand</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<?=$meta;?>
<base href="<?=$CONST_LINK_ROOT?>" />
<link rel="stylesheet" type="text/css" href="wauhhmain.css" media="screen, print">
<link rel="stylesheet" type="text/css" href="tabs.css" media="screen, print">
<!--[if IE]>
<link href="facebox/facebox_ie.css" media="screen" rel="stylesheet" type="text/css"/>
<![endif]-->
<![if !IE]>
<link href="facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<![endif]>
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="js/hahaper_tab.js"></script>
<script type="text/javascript" src="facebox/facebox.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('#loading').hide();
		$('a[rel*=facebox]').click(function (e) {
            e.preventDefault();
        });  
    })
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td><?php if (isset($WUserID)) { ?>
				<div id="topPanel">
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td><a href="<?=$SITE_MAIN_WWW_ROOT?>/home.php" id="HomeLogo" title="Wauhaha"><img src="images/iconWauhaha.gif" alt="Wauhaha" /></a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript: void(null)" id="WauhhHubs" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/wauhh_main.php'}, 'Wauhh Hubs'); return false;" rel="facebox" >Wauhh Hubs</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript:;" id="Feedbackbox">Feedback</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript:;" id="Newsbox">News</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td width="100%"><span class="extraSpace"><img src="images/spacer.gif" /></span></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript:;" id="PAbox" title="Point Available">0.00</a></td>
							<td><a href="javascript:;" id="PRbox" title="Point Reward">0.00</a></td>
							<td><a href="javascript:;" id="PDbox" title="Point Deal">0.00</a></td>
							<td><a href="javascript:;" id="PSbox" title="Point Settlement">0.00</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript:;" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/addFunds.php'}, 'Add Funds'); return false;" rel="facebox" id="AddFundbox">Add Funds</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="<?=$CONST_LINK_ROOT?>/home.php" id="Homebox">Home</a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="javascript:logout();" target="_self" id="Logoutbox">Log out</a></td>
						</tr>
					</table>
				</div>
				<?php } else { ?>
				<div id="topPanel">
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td><a href="<?=$SITE_MAIN_WWW_ROOT?>/home.php" id="HomeLogo" title="Wauhaha"><img src="images/iconWauhaha.gif" alt="Wauhaha" /></a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td width="100%"><span class="extraSpace"><img src="images/spacer.gif" /></span></td>
					<td><span class="break"><img src="images/spacer.gif" /></span></td>
					<td><a href="<?=$CONST_LINK_ROOT?>/home.php" id="Homebox">Home</a></td>
					<td><span class="break"><img src="images/spacer.gif" /></span></td>
					<td><a href="index.php" id="Logoutbox"><span class="uppper">Login</span></a></td>
							<td><span class="break"><img src="images/spacer.gif" /></span></td>
							<td><a href="<?=$SITE_MAIN_WWW_ROOT?>/register1.php" id="tab_mysite"><span class="uppper">Join Us Now</span></a></td>
						</tr>
					</table>
				</div>
				<?php } ?>
		</td>
	</tr>
	<tr>
		<td class="home-top"><table width="995" border="0" align="center" cellpadding="0" cellspacing="0" class="home-header">
				<tr>
					<td><table width="995" border="0" align="center" cellpadding="0" cellspacing="0" class="margin_t_35">
							<tr>
								<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="middle_panel">
										<tr>
											<td><div id="loading"><img src="images/spacer.gif"></div></td>
										</tr>
										<tr>
											<td><div id="main_content" style="width: 995px;">