<?php if (isset ($_SESSION['user'])) { ?>


<div class="content_box">
<div class="content_box_header"><a href="?page=pages&uid=<?php echo $_SESSION['id']; ?>">Bookmarks</a></div>

<?php
$total = 0;
$userId = $_SESSION['id'];
$res = mysql_query ("SELECT p.Id, p.Link, p.Title, p.Image, p.Category, p.Public, r.Date, r.DailyFans, r.WeeklyFans, r.MonthlyFans, r.TotalFans, r.PageId FROM page AS p JOIN report AS r ON p.Id = r.PageId WHERE r.TotalFans <> 0 AND p.Verified = 1 AND DATE(r.Date) = (SELECT MAX(DATE(Date)) FROM report) AND p.Id IN (SELECT PageId FROM user_page WHERE UserId = '$userId') ORDER BY " . $ordby) or die ("error");
$nr = mysql_num_rows ($res);
$i = 0;
while ($nr > 0 and $i < 5) {
	$row = mysql_fetch_array ($res);
	extract ($row);
	?>
    <?php if ($Public != '1') { ?>
    <div class="private_content_box">
    <?php } ?>
    
	<div class="content_box_item">
	<div class="avatar"><a href="index.php?page=page&id=<?php echo $Id;?>"><img src="<?php echo $Image; ?>" alt="<?php echo $Title; ?>" width="50" height="50" /></a></div>
	<div class="description">
	<div class="title"><a href="index.php?page=page&id=<?php echo $Id;?>"><?php echo $Title; ?></a></div>
    <div class="category">- <?php echo $Category; ?></div>
	</div>
	<div class="fans">
	<?php if ($orby == 'day_asc' or $orby == 'day_desc') { 
		$total += $DailyFans;
		if ($DailyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
		echo number_format($DailyFans, 0, ',', '.'); ?></div>
		<div class="total"><?php echo number_format($TotalFans, 0, ',', '.'); ?></div>
    <?php } else if ($orby == 'week_asc' or $orby == 'week_desc') { 
		$total += $WeeklyFans;
		if ($WeeklyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
		echo number_format($WeeklyFans, 0, ',', '.'); ?></div>
		<div class="total"><?php echo number_format($TotalFans, 0, ',', '.'); ?></div>
    <?php } else if ($orby == 'month_asc' or $orby == 'month_desc') { 
		$total += $MonthlyFans;
		if ($MonthlyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
		echo number_format($MonthlyFans, 0, ',', '.'); ?></div>
		<div class="total"><?php echo number_format($TotalFans, 0, ',', '.'); ?></div>
    <?php } else { 
		$total += $TotalFans;
		?>
        <div class="total"><br />
		<?php echo number_format($TotalFans, 0, ',', '.'); ?>
        </div>
    <?php } ?>
    </div>
	</div>
	<?php if ($Public != '1') { ?>
    </div>
    <?php } ?>
    
	<?php
	$nr--;
	$i++;
}

/* if ($nr > 0) { ?>
<div class="content_box_footer"><a href="?page=pages&uid=<?php echo $_SESSION['id']; ?>">View all</a></div>
<?php } */ ?>
<div class="content_box_footer"><a href="?page=pages&uid=<?php echo $_SESSION['id']; ?>">View all</a>
<span style="float:right;">
<?php if ($total>0) echo "+"; echo number_format($total, 0, ',', '.');  ?>
</span>
</div>

</div>

<?php } ?>