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

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

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

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);
 if ($check_count > 0) {
 $check_array = mysql_fetch_object($check_query);
 $VUserID = $check_array->mem_userid; }
 else { echo "<script>location.href='" . $CONST_LINK_ROOT . "/index.php'</script>"; die; }
} else {
$VUserID = $WUserID;
}
if ($VUserID == $WUserID && $WUserID!=0) {
echo "<script>location.href='" . $CONST_LINK_ROOT . "/home.php'</script>"; die; 
}

$common_query=mysql_query("SELECT C.mem_userid, C.mem_profileid, C.mem_username, SUBSTRING(C.mem_username,1,9) as shortname, C.mem_fullname FROM members AS C, my_friends AS F1, my_friends AS F2 WHERE '$VUserID'!='$WUserID' And F1.uid='$VUserID' And F2.uid='$WUserID' And F1.friend_uid=F2.friend_uid And C.mem_userid=F1.friend_uid And F1.approved='1' And F2.approved='1' order by mem_username",$link) or die(mysql_error());
$common_TOTAL = mysql_num_rows($common_query);

$comment=mysql_query("SELECT COUNT(com_memid) FROM profile_comment WHERE com_memid ='$VUserID' AND com_approved = '2' ORDER BY com_time DESC",$link) or die(mysql_error());

if (isset($WUserID)) { 
$liked_query=mysql_query("SELECT mem_userid, mem_username, mem_profileid FROM like_list LEFT JOIN members ON (fav_advid=mem_userid) WHERE fav_userid='$VUserID' ORDER BY RAND()",$link) or die(mysql_error());
$liked_count = mysql_num_rows($liked_query);
}

$member_query=mysql_query("SELECT *,(YEAR(CURDATE())-YEAR(adv_dob)) - (RIGHT(CURDATE(),5) < RIGHT(adv_dob,5)) AS age,DATE_FORMAT(mem_lastvisit, '%d-%b-%Y, %r') as mem_lastvisit, 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 = '$VUserID' AND adv_approved='1'") or die(mysql_error());
$sql_array = mysql_fetch_object($member_query);
$TOTAL = mysql_num_rows($member_query);

if (empty ($_SESSION['ref_id'])) {
$_SESSION['ref_id'] = $sql_array->mem_referCode;
}

function cutword($cutstring) {
	 $_data = explode(" ", ucwords($cutstring));
    foreach($_data as $value) {
        if (strlen($value)>10) {
				echo wordwrap($value, 8, " ", true)." ";
        } else {
		  		echo $value." ";
		  }
    }
}										 

?>
<script type="text/javascript">

    jQuery(document).ready(function($) {
	 	$('#loadingBox').html('<img src="images/small_loader.gif">');
		$.get('myprofile_scover.php?VUserID=<?=$VUserID?>', function(data) {
	 	$('#tab_cover').attr("class", "active");
		$('#loadingBox').html('');
 		$('#contentBox').html(data);
			});
		
      $('a[rel*=facebox]').click(function (e) {
            e.preventDefault();
        });  
		  
		$("#tab_cover").click(function(){

	 	$('#loadingBox').html('<img src="images/small_loader.gif">');
		$.get('myprofile_scover.php?VUserID=<?=$VUserID?>', function(data) {
	 	$('a[rel=subTab]').removeClass('active');
	 	$('#tab_cover').attr("class", "active");
	 	$('#loadingBox').html('');
 		$('#contentBox').html(data);
			});
    	});

		$("#tab_member").click(function(){

	 	$('#loadingBox').html('<img src="images/small_loader.gif">');
		$.get('myprofile_smember.php?VUserID=<?=$VUserID?>', function(data) {
	 	$('a[rel=subTab]').removeClass('active');
	 	$('#tab_member').attr("class", "active");
	 	$('#loadingBox').html('');
 		$('#contentBox').html(data);
			});
    	});
 
		$("#tab_media").click(function(){

	 	$('#loadingBox').html('<img src="images/small_loader.gif">');
		$.get('myprofile_smedia.php?VUserID=<?=$VUserID?>&VUserNAME=<?=$sql_array->adv_username?>', function(data) {
	 	$('a[rel=subTab]').removeClass('active');
	 	$('#tab_media').attr("class", "active");
	 	$('#loadingBox').html('');
 		$('#contentBox').html(data);
			});
    	});
  
		$("#tab_thought").click(function(){

	 	$('#loadingBox').html('<img src="images/small_loader.gif">');
		$.get('myprofile_sthought.php?VUserID=<?=$VUserID?>&VUserNAME=<?=$sql_array->adv_username?>', function(data) {
	 	$('a[rel=subTab]').removeClass('active');
	 	$('#tab_thought').attr("class", "active");
	 	$('#loadingBox').html('');
 		$('#contentBox').html(data);
			});
    	});
  })

</script>
<table width="800px" border="0" align="left" cellpadding="0" cellspacing="0" class="white_back_t_xb">
	<?php if (isset($WUserID)) { ?>
		<tr>
			<td width='100%' align='left' valign="top"><ul id="submenu">
					<li><a href="javascript:;" id="tab_cover" rel="subTab">Cover</a></li>
					<li><a href="javascript:;" id="tab_member" rel="subTab">Connections</a></li>
					<li><a href="javascript:;" id="tab_media" rel="subTab">Media </a></li>
					<li><a href="javascript:;" id="tab_thought" rel="subTab">Thoughts</a></li>
					<!--  <li><a href="javascript:void(null);" id="tab_contribution" rel="subTab">Contributions</a></li>
-->
				</ul>
				<div id="loadingBox" class="right"></div></td>
		</tr>
		<?php } ?>
	<tr>
		<td align='left' valign="top"><div id="contentBox"></div></td>
	</tr>
</table>
