<?php
$referrer_query=mysql_query("SELECT C.mem_userid, C.mem_username, C.mem_profileid FROM adverts AS A, members AS B, members AS C WHERE A.adv_userid = '$WUserID' AND A.adv_approved='1' And A.adv_userid=B.mem_userid And B.mem_referrer = C.mem_userid") or die(mysql_error());
$referrer_TOTAL = mysql_num_rows($referrer_query);

$liked_query=mysql_query("SELECT enc_viewerid, enc_userid, mem_username, mem_profileid, mem_fullname FROM encounters LEFT JOIN members ON (enc_viewerid=mem_userid) WHERE enc_userid='$WUserID' and enc_viewdate>'".$_SESSION['Sess_LastVisit']."' ORDER BY RAND()",$link) or die(mysql_error());
$liked_count = mysql_num_rows($liked_query);

$friend=mysql_query("SELECT mem_userid, mem_username, mem_profileid, mem_fullname FROM my_friends LEFT JOIN members ON (uid=mem_userid) WHERE friend_uid ='$WUserID' AND approved='0' AND status='P'");
$count_friend=mysql_num_rows($friend);

function cutword($cutstring) {
	 $_data = explode(" ", ucwords($cutstring));
    foreach($_data as $value) {
        if (strlen($value)>9) {
				echo wordwrap($value, 7, " ", true)." ";
        } else {
		  		echo $value." ";
		  }
    }
}										 
?>
</div>
</div>

<div id="ads_panel">
	<div class="sidebox">
		<div class="title titleBlue">TIPS TO GO</div>
		<div class="content"><span class="grey_12_xb">Get your profile complete and explore your needs to social world today.</span></div>
	</div>
	<!-- start sponsor ----------------------------------------------------------------------------------------------->
<?php if ($_SESSION['Sess_JustRegistered']==true) { ?>
<div class="sidebox">
	<div class="title">YOUR INTRODUCER</div>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content">
		<tr>
			<td><div class="content_10">
					<?php 
$referrer = mysql_fetch_object($referrer_query);
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$referrer->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error());
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "members/$referrer->mem_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($referrer->mem_userid);
}

if ($referrer->mem_profileid != null) { $male1_name1= $referrer->mem_profileid; }
else { $male1_name1= $referrer->mem_username; }

$fullname = $referrer->mem_username;
?>
					<div class="smallBox"><span class="w50_h50 pb10"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($fullname)?>" class="img_b_p3"/></a></span>
<a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>">
						<?=cutword($fullname);?>
						</a> </div><div class="smallBox2">Get updates with me. I'll tell you more!</div>
				</div></td>
		</tr>
	</table>
</div>
<?php } ?>
<!-- end sponsor ----------------------------------------------------------------------------------------------->

	<!-- start Likes ----------------------------------------------------------------------------------------------->
	<?php if ($liked_count > 0) { ?>
	<div class="sidebox">
		<div class="title"><a href="javascript: void(null)" title="Who Viewed Me" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/viewed-me.php'}, this.title, 'likesAll'); return false;" rel="facebox">WHO VIEWED ME <br />
			SINCE LAST LOGIN  (
			<?=$liked_count?>
			)</a></div>
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content">
			<tr>
				<td><div class="content_10">
						<?php 
$i = 0;
while (($liked = mysql_fetch_object($liked_query)) && ($i<3)) {
$i++;
if ($WUserID==$liked->enc_viewerid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$liked->enc_viewerid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$liked->enc_viewerid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "members/$liked->mem_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($liked->enc_viewerid);
}

if ($liked->mem_profileid != null) { $male1_name1= $liked->mem_profileid; }
else { $male1_name1= $liked->mem_username; }

$fullname = $liked->mem_username;
if ($i%3 == 1) echo '<div class="clear"><img src="images/spacer.gif"></div>';
?>
						<div class="smallBox"><span class="w50_h50 pb10"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($fullname)?>" class="img_b_p3"/></a></span><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>">
							<?=cutword($liked->mem_username);?>
							</a> </div>
						<? 
				} 
				if ($liked_count > 3) echo '<div class="clear"><img src="images/spacer.gif" height="5"></div><div class="right"><a href="javascript: void(null)" title="Who Viewed Me" onclick="javascript: jQuery.facebox({ajax:\''.$CONST_LINK_ROOT.'/viewed-me.php\'}, this.title, \'likesAll\'); return false;" rel="facebox"><span  class="red_10">More...</span></a></div>';
?>
					</div></td>
			</tr>
		</table>
	</div>
	<?php } ?>
	<!-- end Likes ----------------------------------------------------------------------------------------------->
	<!-- start Request ----------------------------------------------------------------------------------------------->
	<?php if ($count_friend > 0) { ?>
	<div class="sidebox">
		<div class="title"><a href="javascript: void(null)" title="Requested Connection" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/alert-invitation.php'}, this.title, 'likesAll'); return false;" rel="facebox">SOMEBODY REQUEST  (
			<?=$count_friend?>
			)</a></div>
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content">
			<tr>
				<td><div class="content_10">
						<?php 
$k = 0;
while (($friends = mysql_fetch_object($friend)) && ($k<3)) {
$k++;
if ($WUserID==$friends->mem_userid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$friends->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$friends->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "members/$friends->mem_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($friends->mem_userid);
}

if ($friends->mem_profileid != null) { $male1_name1= $friends->mem_profileid; }
else { $male1_name1= $friends->mem_username; }

$fullname = $friends->mem_username;
if ($k%3 == 1) echo '<div class="clear"><img src="images/spacer.gif"></div>';
?>
						<div class="smallBox"><span class="w50_h50 pb10"><a href="javascript: void(null)" title="Requested Connection" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/alert-invitation.php'}, this.title, 'likesAll'); return false;" rel="facebox"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($fullname)?>" class="img_b_p3"/></a></span><a href="javascript: void(null)" title="Requested Connection" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/alert-invitation.php'}, this.title, 'likesAll'); return false;" rel="facebox">
							<?=cutword($friends->mem_username);?>
							</a> </div>
						<? 
				} 
				if ($count_friend > 3) echo '<div class="clear"><img src="images/spacer.gif" height="5"></div><div class="right"><a href="javascript: void(null)" title="Requested Connection" onclick="javascript: jQuery.facebox({ajax:\''.$CONST_LINK_ROOT.'/alert-invitation.php\'}, this.title, \'likesAll\'); return false;" rel="facebox"><span  class="red_10">More...</span></a></div>';
?>
					</div></td>
			</tr>
		</table>
	</div>
	<?php } ?>
	<!-- end Request-------------------------------------------------------------------------------------------------->
</div>
</div>
<div class="menu_bottom_t"><a href="wauhhBiz.php" target="_self" title="WAUHHBIZ">WAUHHBIZ</a> <a href="http://marketer.wauhaha.com/wauhhHot.php" target="_self" title="WAUHHHOT">WAUHHHOT</a> <a href="http://socializer.wauhaha.com/wauhhSoc.php" target="_self" title="WAUHHSOCIETY">WAUHHSOCIETY</a> <a href="index.php" target="_self" title="Home">HOME</a> <a href="about.php" target="_self" title="About">ABOUT</a> <a href="contactus.html" target="_self" title="Contact">CONTACT</a> <a href="career.php" target="_self" title="Careers">CAREERS</a> <a href="terms.html" target="_self" title="Terms">TERMS</a> <a href="privacy.html" target="_self" title="Privacy">PRIVACY</a> <a href="<?=$CONST_LINK_ROOT?>/hahaperParks.php#investor" title="Investor Message" target="_self">INVESTOR</a> <a href="http://www.facebook.com/pages/Wauhaha/125760707473366" target="_blank" title="Facebook Page">FB PAGE</a></div>
<div class="p5 copyright">Copyright &copy; 2011 Wauhaha.com. All Rights Reserved. Reproduction strictly prohibited.<br>
	All brand names and products are registered trademarks and patent pending of their respective companies</div>
</div>
</div>
<div id="fb-root"></div>
<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '<?php echo $facebook->getAppId(); ?>',
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true, // parse XFBML
          oauth: true
        });
        // whenever the user logs in, we refresh the page
        FB.Event.subscribe('auth.sessionChange', function() {
          window.location.reload();
        });
      };

        // whenever the user logs in, we refresh the page
        function logout (){
		  var checkSess = <?php echo json_encode($me); ?>;
		  if (checkSess!= null) {
		  FB.logout(function(response) {
				location.href = '<?=$CONST_LINK_ROOT?>/logoff.php';
        });
		  } else {
				location.href = '<?=$CONST_LINK_ROOT?>/logoff.php';
			}
		  }

      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
		  
      }());
</script>
</body></html>