<?php
include("includes/site_info.php");
include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

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

if(!empty($_REQUEST['RUserID'])){
$RUserID = $_REQUEST['RUserID'];
} else {
$RUserID = 0;
}

		$i = 2;
		$j = 0;

	if(isset($_REQUEST['start'])) {
		$start=($_REQUEST['start']-1)*21; 
		$i = $_REQUEST['start']+1;
		$j = $_REQUEST['start']-1;
	} else {	
		$start=0;
	}
	
$all_hahaper_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 '$RUserID'!='$WUserID' And F1.uid='$RUserID' 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());
$all_hahaper_TOTAL = mysql_num_rows($all_hahaper_query);
$page = ceil($all_hahaper_TOTAL/21);

$myhahaper_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 '$RUserID'!='$WUserID' And F1.uid='$RUserID' 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 limit $start, 21",$link) or die(mysql_error());
$myhahaper_TOTAL = mysql_num_rows($myhahaper_query);

if ($myhahaper_TOTAL >0) {
?>

<div class="pop_box width_600">

<?php if (($page >= $i) || ($j>0)) { ?>
<div class="pagingBox">
<?php 
  if ($j>0) {
  	if (($page >= $i) && ($i!=2)) {
	echo "<a href=\"javascript: void(null)\" title=\"All MUTUAL Relations\" onclick=\"jQuery.facebox({ajax:'".$CONST_LINK_ROOT."/mutual_all.php?RUserID=".$RUserID."&start=".$j."&mode=previous'}, this.title, 'connectAll'); return false;\" rel=\"facebox\" ><div class=\"paging left\" align=\"center\">PREVIOUS</div></a>";
	}
	if ($page < $i) {
	echo "<a href=\"javascript: void(null)\" title=\"All MUTUAL Relations\" onclick=\"jQuery.facebox({ajax:'".$CONST_LINK_ROOT."/mutual_all.php?RUserID=".$RUserID."&start=".$j."&mode=previous'}, this.title, 'connectAll'); return false;\" rel=\"facebox\" ><div class=\"paging left\" align=\"center\">PREVIOUS</div></a>";
	}
	}

	if (($page >= $i) && ($i!=2)) {
	echo "<a href=\"javascript: void(null)\" title=\"All MUTUAL Relations\" onclick=\"jQuery.facebox({ajax:'".$CONST_LINK_ROOT."/mutual_all.php?RUserID=".$RUserID."&start=".$i."&mode=next'}, this.title, 'connectAll'); return false;\" rel=\"facebox\" ><div class=\"paging right\" align=\"center\">NEXT</div></a>";
	}
	if (($page >= $i) && ($i==2)) {
	echo "<a href=\"javascript: void(null)\" title=\"All MUTUAL Relations\" onclick=\"jQuery.facebox({ajax:'".$CONST_LINK_ROOT."/mutual_all.php?RUserID=".$RUserID."&start=".$i."&mode=next'}, this.title, 'connectAll'); return false;\" rel=\"facebox\" ><div class=\"paging right\" align=\"center\">NEXT</div></a>";
	}
 ?>
</div>
<div class="clear"><img src="images/spacer.gif" /></div>
<?php
} 

$k = 0;
while ($ret_pic2 = mysql_fetch_object($myhahaper_query)) {
$k++;
if ($WUserID==$ret_pic2->mem_userid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic2->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic2->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/$ret_pic2->mem_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($ret_pic2->mem_userid);
}

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

$fullname = $ret_pic2->mem_username;

$time=time();
$timeout = time()-900;
$query="SELECT COUNT(userid) FROM active_users where timestamp > $timeout AND userid=$ret_pic2->mem_userid";
$reton=mysql_query($query,$link) or die(mysql_error());
$totalon=mysql_result($reton,0,0);

if($totalon>0)
{$status="<span style=\"color:green\">Online!</span>";}
else{$status="Offline!";}

	if($ret_pic2->mem_userid==$WUserID) {
	$request=0;
	} else {
	$retval=mysql_query("SELECT * FROM my_friends WHERE (uid='$WUserID' AND friend_uid='$ret_pic2->mem_userid') or (uid='$ret_pic2->mem_userid' AND friend_uid='$WUserID')",$link);
	$sql_array = mysql_fetch_object($retval);
	$result=mysql_num_rows($retval);

	if ($result == 0) {
	$request=1;
	} elseif ($sql_array->approved == 0) {
	$request=2;
	$retval=mysql_query("SELECT * FROM my_friends WHERE uid='$ret_pic2->mem_userid' AND friend_uid='$WUserID'",$link);
	$sql_array = mysql_fetch_object($retval);
	$result=mysql_num_rows($retval);
	if ($result == 0) {
	$request=2;
	} elseif ($sql_array->approved == 0) {
	$request=4;
	}else {
	$request=2;
	}
	} else {
	$request=0;
	}
	}

?>
    <div class="left m10"><div class="image"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" width="50" title="Name:&nbsp;<?=ucwords($fullname);?>"/></a></div>
    <div class="Xfloatname"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"><span class="blue_11_b">
      <?=cutword($fullname);?>
       </span></a><br />
      <?=$status?>
    </div>
	<?php if($k%7 == 0) echo "<div class=\"clear\"><img src=\"images/spacer.gif\" /></div>";?>
	 </div>
  <?php
	} 
	?>
</div>
<?php
}

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