<?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'];

$activity_query=mysql_query("SELECT * FROM (SELECT * FROM (SELECT activityText, activityID, YEAR(datetime) as year, DATE_FORMAT(datetime, '%M %d, %Y at %h:%i%p') as wYear, DATE_FORMAT(datetime, '%M %d at %h:%i%p') as wtYear, DATE_FORMAT(datetime, '%Y%m%d') as date, mem_username, mem_profileid, mem_userid FROM activities_user LEFT JOIN members ON (userID=mem_userid) WHERE userID='$WUserID' and activityID NOT IN (11, 12, 13, 14) order by datetime desc) data group by activityID,date) data order by date desc",$link) or die(mysql_error());
$activityTotal = mysql_num_rows($activity_query);

?>
	<table width="100%" border="0" cellpadding="3" cellspacing="0" class="white_back_t_xb p5">
		<tr class="grey_12 orange_row_back solid_line_separator">
			<td><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> Activities</td>
		</tr>
		<?php if($activityTotal > 0) {?>
		<tr>
			<td><div class="activityFeed" id="PopFeed">
					<?php 
		$j=0;
	 while (($activity = mysql_fetch_object($activity_query)) && ($j<12)) {

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

	 if ($activity->mem_profileid != null) { $profile_name= $activity->mem_profileid; }
	 else { $profile_name= $activity->mem_username; }

	 if ($activity->year==date('Y')) {
	 	$date = $activity->wtYear;
	 } else {
	 	$date = $activity->wYear;
	 }
?>
					<div class="p5 clear"> <span class="left img_b_p3 w50_h50 mr_10"><a href="<?=$CONST_LINK_ROOT?>/<?=$profile_name?>"><img src="<?=$CONST_LINK_ROOT?>/<?=$male1_picture1?>" border="0" title="Name:&nbsp;<?=ucwords($activity->mem_username)?>"/> </a></span>
						<?=ucwords($activity->mem_username)?> <?=$activity->activityText?>
						<span class="grey_10">
						<br /><?=$date?>
						</span> </div>
					<?php $j++;
										} ?>
				</div></td>
		</tr>
		<?php } else {?>
		<tr>
			<td>No activity yet for current!</td>
		</tr>
		<?php }?>
		<tr>
			<td>&nbsp;</td>
		</tr>
	</table>
