<div id="content">

<div class="huge_box">

<?php 
switch ($orby) {
	case 'day_asc': {
		$ordby = ' r.DailyFans ASC ';
		break;
	} case 'day_desc': {
		$ordby = ' r.DailyFans DESC ';
		break;
	} case 'month_asc': {
		$ordby = ' r.MonthlyFans ASC ';
		break;
	} case 'month_desc': {
		$ordby = ' r.MonthlyFans DESC ';
		break;
	} case 'week_asc': {
		$ordby = ' r.WeeklyFans ASC ';
		break;
	} case 'week_desc': {
		$ordby = ' r.WeeklyFans DESC ';
		break;
	} case 'total_asc': {
		$ordby = ' r.TotalFans ASC ';
		break;
	} default: {
		$orby = 'total_desc';
		$ordby = ' r.TotalFans DESC ';
		break;
	} 
}


switch ($sbm) {
	case 'mes': {
		$subm = '  ';
		break;
	} case 'my': {
		$subm = '  ';
		break;
	} case 'nf': {
		$subm = '  ';
		break;
	} default : {
		$subm = ' ';
		break;
	} 
}



if (isset($_GET['pg'])) {
	$pg = $_GET['pg'];
} else {
	$pg = 0;	
}
$displaying = 10;
$pagination = " LIMIT " . $pg . ", " . $displaying;
$currentpage = floor($pg / $displaying) + 1;

include ("components/page_tabs.php");
 ?>
<div class="huge_box_header">
<div class="title">Pages</div>
<div class="nums"><a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php if ($orby == 'total_desc') echo 'total_asc'; else echo 'total_desc'; if ($search!= '') echo "&searchbox=".$search; ?>">Total</a></div>
<div class="nums"><a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php if ($orby == 'month_desc') echo 'month_asc'; else echo 'month_desc'; if ($search!= '') echo "&searchbox=".$search; ?>">Monthly</a></div>
<div class="nums"><a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php if ($orby == 'week_desc') echo 'week_asc'; else echo 'week_desc'; if ($search!= '') echo "&searchbox=".$search; ?>">Weekly</a></div>
<div class="nums"><a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php if ($orby == 'day_desc') echo 'day_asc'; else echo 'day_desc'; if ($search!= '') echo "&searchbox=".$search; ?>">Daily</a></div>
</div>
<div class="huge_box_content">
<?php
$addSearch = "";
if ($search != '') {
	$addSearch = " AND p.Title REGEXP '$search' ";
}

$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 " . $viewPrivatePages . " r.TotalFans <> 0 
					AND p.Verified = 1   
					AND DATE(r.Date) = (SELECT MAX(DATE(Date)) FROM report) ". $viewUserPages . $addSearch ) or die ("error");

$nr = mysql_num_rows ($res);
$numresults = $nr;
$totalpages = floor(($nr - 1) / $displaying) + 1;


$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 " . $viewPrivatePages . " r.TotalFans <> 0 AND p.Verified = 1 AND DATE(r.Date) = (SELECT MAX(DATE(Date)) FROM report) ". $viewUserPages . $addSearch." ORDER BY " . $ordby .  $pagination ) or die ("error");
$nr = mysql_num_rows ($res);

if ($nr == 0) {
	?>
    <div class="huge_box_item">
	
    <div class="avatar"></div>
	<div class="description">
	<div class="title">No matches for query <?php echo $search; ?>.</div>
    </div>
    </div>
    <?php
}

if ($nr == 1 and $pg==0) {
	$row = mysql_fetch_array ($res);
		extract ($row);
		?>
 		<script type="text/javascript">
		window.location = '?page=page&id=<?php echo $Id; ?>&uid=<?php echo $uid; ?><? if ($search!= '') echo "&searchbox=".$search; ?>';
    	</script>
        <?php	
}

while ($nr > 0) {
	$row = mysql_fetch_array ($res);
	extract ($row);
	?>
    <?php if ($Public != '1') { ?>
    <div class="private_huge_box">
    <?php } ?>
    
	<div class="huge_box_item">
	
    <div class="avatar"><a href="index.php?page=page&id=<?php echo $Id; ?>&uid=<?php echo $uid; ?>"><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">
    <div class="total"><?php echo number_format($TotalFans, 0, ',', '.'); ?></div>
    </div>
    
    <div class="fans">
	<?php if ($MonthlyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
	echo number_format($MonthlyFans, 0, ',', '.'); ?></div>
	</div>
    
	<div class="fans">
	<?php if ($WeeklyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
	echo number_format($WeeklyFans, 0, ',', '.'); ?></div>
	</div>
	
    <div class="fans">
    <?php if ($DailyFans < 0 ) { ?><div class="negative"><?php } else { ?><div class="positive">+<?php } 
	echo number_format($DailyFans, 0, ',', '.'); ?></div>
	</div>
	
    </div>
    <?php if ($Public != '1') { ?>
    </div>
    <?php } ?>
    
    <?
	$nr--;
}

?>
</div>
<div class="huge_box_footer">
<?php if ($totalpages > 0) { ?>
	<div class="pagination">
	<?php if ($currentpage>2) { ?>
    	<a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php echo $orby; ?><? if ($search!= '') echo "&searchbox=".$search; ?>&pg=0" title="first">&nbsp;&lt;&lt;&nbsp;</a>
	<?php } ?>
	<?php if ($currentpage>1) { ?>
    	<a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php echo $orby; ?><? if ($search!= '') echo "&searchbox=".$search; ?>&pg=<?php echo $pg - $displaying; ?>" title="prev">&nbsp;&lt;&nbsp;</a>
	<?php } ?>
&nbsp;&nbsp;<?php echo $currentpage."/".$totalpages; ?>&nbsp;&nbsp;
	<?php if ($currentpage<$totalpages) { ?>
    	<a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php echo $orby; ?><? if ($search!= '') echo "&searchbox=".$search; ?>&pg=<?php echo ($currentpage) * $displaying; ?>" target="_self" title="next">&nbsp;&gt;&nbsp;</a>
    <?php } ?>
	<?php if ($currentpage<$totalpages-1) { ?>
    	<a href="?page=pages&uid=<?php echo $uid; ?>&my=<?php echo $my; ?>&orby=<?php echo $orby; ?><? if ($search!= '') echo "&searchbox=".$search; ?>&pg=<?php echo ($totalpages - 1) * $displaying; ?>" target="_self" title="last">&nbsp;&gt;&gt;&nbsp;</a>
    <?php } ?>
	</div>
<?php } ?>
<div class="results">Total results: <?php echo $numresults; ?>.</div>
</div>
</div>

<?php 
include ('components/submit_page.php');
include ('components/sign_in.php');
include ('components/my_pages.php');

//include ("components/ads.php"); 


?>

</div>
