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

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

$viewed_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' ORDER BY enc_viewdate desc",$link) or die(mysql_error());
$viewed_count = mysql_num_rows($viewed_query);

if ($viewed_count >0) {
?>

<div class="pop_box">
  <?php while ($ret_pic2 = mysql_fetch_object($viewed_query)) {
if ($WUserID==$ret_pic2->enc_viewerid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic2->enc_viewerid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic2->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/$ret_pic2->mem_username/picture/$medium";
             }else{
$male1_picture1=$picture->GetProfilePicture($ret_pic2->enc_viewerid);
}

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->enc_viewerid";
$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!";}

	$retval=mysql_query("SELECT * FROM my_friends WHERE (uid='$WUserID' AND friend_uid='$ret_pic2->enc_viewerid') or (uid='$ret_pic2->enc_viewerid' 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->enc_viewerid' 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="content">
    <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="name"><a href="<?=$CONST_LINK_ROOT?>/<?=$male1_name1?>"><span class="blue_12">
      <?=ucwords($fullname);?>
      </span> </a><br />
      <?=$status?>
    </div>
    <div class="rightContent">
      <?php if ($request==1 || $request==3) { ?>
      <span id="send_request" class=""> <a href="javascript:void(null);" title="Request to Connect" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/label-me.php?RUserID=<?=$ret_pic2->enc_viewerid?>&amp;RUserName=<?=$ret_pic2->mem_username?>&amp;mode=request&amp;backmode=viewedMe'}, this.title, 'popLabel'); return false;" class="a_button" rel="facebox"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Request to Connect</a></span> <span id="confirm_request" class="none"> <span class="grey_10"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Pending Confirmation</span></span> <span id="accept_request" class="none"> <a href="javascript:void(null);" title="Respond to Request" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/label-me.php?AUserID=<?=$ret_pic2->enc_viewerid?>&amp;AUserName=<?=$ret_pic2->mem_username?>&amp;mode=respond&amp;backmode=viewedMe'}, this.title, 'popLabel'); return false;" class="a_button" rel="facebox"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Accept Request</a></span>
      <?php } ?>
      <?php if ($request==2) { ?>
      <span class="a_button_off"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Pending Confirmation</span>
      <?php } ?>
      <?php if ($request==4) { ?>
      <span id="accept_request" class=""> <a href="javascript:void(null);" title="Respond to Request" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/label-me.php?AUserID=<?=$ret_pic2->enc_viewerid?>&amp;AUserName=<?=$ret_pic2->mem_username?>&amp;mode=respond&amp;backmode=viewedMe'}, this.title, 'popLabel'); return false;" class="a_button" rel="facebox"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Respond to Request</a></span> <span id="send_request" class="none"> <a href="javascript:void(null);" title="Request to Connect" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/label-me.php?RUserID=<?=$ret_pic2->enc_viewerid?>&amp;RUserName=<?=$ret_pic2->mem_username?>&amp;mode=request&amp;backmode=viewedMe'}, this.title, 'popLabel'); return false;" class="a_button" rel="facebox"><img src="images/icon-label.gif" width="18" height="15" border="0" align="absbottom"/> Request to Connect</a></span>
      <?php } ?>
    </div>
    <div class="clear"><img src="images/spacer.gif" /></div>
  </div>
  <? 
				$i++;
				} ?>
</div>
<?php
}
?>
