<?php
include("includes/site_info.php");

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

require 'includes/facebook.php';
// 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;
  }
}

$WUserID = $_SESSION['Sess_UserId'];
$WUserName = $_SESSION['Sess_UserName'];
$request=5;

if (isset($_GET['i']) && !empty($_GET['i'])) {
$_SESSION['inv_id'] = $_GET['i'];
}

if (isset($_GET['ref_id']) && !empty($_GET['ref_id'])) {
$_SESSION['ref_id'] = $_GET['ref_id'];
} 
if (isset($_REQUEST['VUserId'])) {
 $VUserID = $_REQUEST['VUserId'];
 $check_query=mysql_query("SELECT mem_userid FROM members LEFT JOIN adverts ON (mem_userid=adv_userid) where (mem_username='$VUserID' or  mem_profileid='$VUserID') AND mem_confirm='1' AND adv_approved='1'",$link);
 $check_count=mysql_num_rows($check_query);
 $check_array = mysql_fetch_object($check_query);
 if ($check_count > 0) { $VUserID = $check_array->mem_userid; }
 else { echo "<script>location.href='" . $CONST_LINK_ROOT . "/index.php'</script>"; die; }
} else {
$VUserID = $WUserID;
}

if (isset($WUserID)) { 
$memberS_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());
$sqlS_array = mysql_fetch_object($memberS_query);

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

SELECT @rank := @rank +1 AS rank, mem_userid, @prev_val := totalRank AS 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);

}

?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta name="description" content="Wauhaha web is a social interaction media that gives people the power to create demand and get value while connected with the world. Wauhaha, Inc. produces interaction quality and solution in network and business marketing purposes enhances with multitasking system module for interacting, promoting and performing on own creation all in one space." />
<meta name="keyword" content="wauhaha, wow, wau malaysia, wau, malaysia, social network, wuahaha, wahaha, merketing malaysia, connects people, johor bahru, SEO, web developer, about malaysia, jadiatang, jadia tang, socializer, socializer malaysia, marketer, hahaper, creator, merchandiser, inventor, innovator" />
<link rel="alternate" media="handheld" href="<?=$CONST_LINK_ROOT?>" />
<base href="<?=$CONST_LINK_ROOT?>" />
<title>Wauhaha | WauhhHot
</title>
<link rel="stylesheet" type="text/css" href="wauhhstyle.css">
<link rel="stylesheet" type="text/css" href="wauhhtabs.css">
<link rel="stylesheet" type="text/css" href="wauhhbox.css">
<!--[if IE 6]>
<link href="facebox/facebox_ie.css" media="screen" rel="stylesheet" type="text/css"/>
<![endif]-->
<!--[if !IE 6]><!-->
<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/jquery.history.js"></script>
<script type="text/javascript" src="js/wauhhJS.js"></script>
<script type="text/javascript" src="facebox/facebox.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').click(function (e) {
            e.preventDefault();
        });  
    })

</script>
</head>
<body>
<div id="loading"><img src="images/spacer.gif"></div>
<div id="fullBackPanel">
	<div id="fullBackPanelTop">
		<?php if (isset($WUserID)) { ?>
		<div id="topPanel">
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td><a href="<?=$CONST_LINK_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="<?=$CONST_LINK_ROOT?>/hahaperParks.php" id="HPark">Hahapers Park</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', 'wauhhHubsBox'); return false;" rel="facebox" >Wauhh Hubs</a></td>
					<td><span class="break"><img src="images/spacer.gif" /></span></td>
<!--					<td><span class="SearchBox">
						<input type="text" value="Wauhh Search" class="input" />
						<input name="cmdSubmit" type="image" src="images/iconSearch1.gif" border="0" class="button">
						</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:;" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/mybank.php'}, 'My Bank', 'mybankBox'); return false;" rel="facebox" id="MyBankbox">My Bank</a></td>
					<td><span class="break"><img src="images/spacer.gif" /></span></td>
					<td><a href="javascript:;" id="AddFundbox">Add Funds</a></td>
					<td><span class="break"><img src="images/spacer.gif" /></span></td>
					<td><a href="<?=$CONST_LINK_ROOT?>/inbox.php" id="Mailbox">Inbox
						<?php if($msgrTOTAL>0) { echo " <span>(".$msgrTOTAL.")</span>";} ?>
						</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="<?=$CONST_LINK_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="SearchBox">
						<input type="text" value="Wauhh Search" class="input" />
						<input name="cmdSubmit" type="image" src="images/iconSearch1.gif" border="0" class="button">
						</span></td>
-->					<td><span class="break"><img src="images/spacer.gif" /></span></td>
					<td><a href="register1.php" id="tab_mysite"><span class="uppper">Join Us Now</span></a></td>
				</tr>
			</table>
		</div>
		<?php } ?>
		<div id="middleTop">
			<div id="contentWrapper">

<script type="text/javascript">
jQuery.noConflict();

jQuery(document).ready(function(){
    jQuery("#search_post").submit(function(){
	 	jQuery('#loading').show();
//	 	jQuery('#right_loading_m').show();
		
		var q = jQuery("#q").val();
		
		q=jQuery.trim(q);
		
		jQuery("#q").val(q);

		var str = jQuery(this).serialize();
	
		window.location.href = "<?=$CONST_LINK_ROOT?>/home.php#msearch?tab=search&" + str;
		return false;
    });
	 
	 jQuery(".moreCat").click(function(){
	 	var id = jQuery(this).attr("id");
	 	jQuery(this).parent().hide();
		jQuery(this).parents("span.main").height(140+jQuery('#show'+id).height());
		jQuery('#show'+id ).slideDown("slow");
	 });
});

  </script>
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
				<tr>
					<td><div class="light_orang_h">
							<div style="background-color:#FF0000; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
							Search</div>
						<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
						<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
				</tr>
				<tr>
					<td><form name="search_post" id="search_post" style="padding:0; margin:0; border:0;">
							<table width="100%" border="0" cellspacing="0" cellpadding="5">
								<tr>
									<td align="center"><input type="text" size="40" name="q" id="q" class="grey_12_xb"/>
										<input name="type" type="hidden" id="type" value="all" />
										<input name="init" type="submit" class="button" id="init" value="Search"/></td>
								</tr>
							</table>
						</form></td>
				</tr>
				<tr>
					<td><div class="light_orang_h">
							<div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10" /></div>
							Categories</div>
						<div class="dot_line"><img src="images/spacer.gif" width="1" height="1" /></div>
						<div class="solid_line"><img src="images/spacer.gif" width="1" height="1" /></div></td>
				</tr>
				<tr>
					<td><div class="mainCatAll">
					<?php
					$sql=mysql_query("select dataID, dataName from market_category_data where catID=1 and parent=0 and dataID not in (1,84,85) order by dataName asc");
					$clear = 0;
					while($row=mysql_fetch_array($sql))
					{
					$id=$row['dataID'];
					$data=$row['dataName'];
					$countQuery=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and subCat=$id");
					$countTotal = mysql_num_rows($countQuery);
					if ($clear%4==0) {
						echo "<span class=\"main clear\">";
					} else {
						echo "<span class=\"main\">";
					}
					echo "<a href=\"#mlistings?tab=categories&catID=1&dataID=$id\" onclick=\"javascript: callpage(this.href);\">".$data."&nbsp;<span class=\"orange_12\">($countTotal)</span></a>";
					$sql2=mysql_query("select dataID, dataName from market_category_data where catID=1 and parent=$id order by dataName asc");
					$sql2Total = mysql_num_rows($sql2);
					$j=0;
					while($row2=mysql_fetch_array($sql2))
					{
					$j++;
					$id2=$row2['dataID'];
					$data2=$row2['dataName'];
					if ($j==6) {
						echo "<p><a href=\"javascript:;\" class=\"moreCat\" id=\"$idn$id2\"><strong>More</strong></a></p><div id=\"show$idn$id2\" class='none'>";
					}
					$countQuery2=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and subCatsub=$id2");
					$countTotal2 = mysql_num_rows($countQuery2);
					echo "<p><a href=\"#mlistings?tab=categories&catID=1&dataID=$id&SubdataID=$id2\" onclick=\"javascript: callpage(this.href);\">".$data2."&nbsp;<span class=\"orange_12\">($countTotal2)</span></a></p>";
					if (($j==$sql2Total) &&($j>5)) {
						echo "</div> </p>";
					}
					}
					echo "</span>";
					$clear++;
					}
					?>
					<?php
					$countQuery=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and subCat in (1,84,85)");
					$countTotal = mysql_num_rows($countQuery);
					echo "<span class=\"main\"> Others <span class=\"orange_12\">($countTotal)</span>";
					$sql2=mysql_query("select dataID, dataName from market_category_data where catID=1 and parent=0 and dataID in (1,84,85) order by dataName asc");
					$sql2Total = mysql_num_rows($sql2);
					while($row2=mysql_fetch_array($sql2))
					{
					$id2=$row2['dataID'];
					$data2=$row2['dataName'];
					$countQuery=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and subCat=$id2");
					$countTotal = mysql_num_rows($countQuery);
					echo "<p><a href=\"#mlistings?tab=categories&catID=1&dataID=$id2\" onclick=\"javascript: callpage(this.href);\">".$data2."&nbsp;<span class=\"orange_12\">($countTotal)</span></a></p>";
					}
					echo "</span>";
					?>
					<?php
					$sql=mysql_query("select catID, catName from market_category where catID!=1");
					$clear = 0;
					while($row=mysql_fetch_array($sql))
					{
					$id=$row['catID'];
					$data=$row['catName'];
					$countQuery=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and mainCat=$id");
					$countTotal = mysql_num_rows($countQuery);
					if ($clear%4==0) {
						echo "<span class=\"main clear\">";
					} else {
						echo "<span class=\"main\">";
					}
					echo "<a href=\"#mlistings?tab=categories&catID=$id\" onclick=\"javascript: callpage(this.href);\">".$data."&nbsp;<span class=\"orange_12\">($countTotal)</span></a>";
					$sql2=mysql_query("select dataID, dataName from market_category_data where catID=$id and parent=0 order by dataName asc");
					$sql2Total = mysql_num_rows($sql2);
					$j=0;
					while($row2=mysql_fetch_array($sql2))
					{
					$j++;
					$id2=$row2['dataID'];
					$data2=$row2['dataName'];
					if ($j==6) {
						echo "<p><a href=\"javascript:;\" class=\"moreCat\" id=\"$idn$id2\"><strong>More</strong></a></p><div id=\"show$idn$id2\" class='none'>";
					}
					$countQuery2=mysql_query("select mainCat from market_Post where approve=1 and expDate > now() and subCat=$id2");
					$countTotal2 = mysql_num_rows($countQuery2);
					echo "<p><a href=\"#mlistings?tab=categories&catID=$id&dataID=$id2\" onclick=\"javascript: callpage(this.href);\">".$data2."&nbsp;<span class=\"orange_12\">($countTotal2)</span></a></p>";
					if (($j==$sql2Total) &&($j>5)) {
						echo "</div>";
					}
					}
					echo "</span>";
					$clear++;
					}
					?>
					</div></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
			</table></td>
	</tr>
</table>
			</div>
		</div>
		<div class="menu_bottom_t"><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></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
        });
      };

        // 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.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
		  
      }());
</script>
</body>
</html>
