<div id="content">

<div class="huge_box">

<?php 
switch ($orby) {
	case 'id_asc': {
		$ordby = ' PageId ASC ';
		break;
	} case 'id_desc': {
		$ordby = ' PageId DESC ';
		break;
	} case 'tit_asc': {
		$ordby = ' Title ASC ';
		break;
	} case 'tit_desc': {
		$ordby = ' Title DESC ';
		break;
	} case 'link_asc': {
		$ordby = ' Link ASC ';
		break;
	} case 'link_desc': {
		$ordby = ' Link DESC ';
		break;
	} case 'date_asc': {
		$ordby = ' Updated ASC ';
		break;
	} default: {
		$orby = 'date_desc';
		$ordby = ' Updated DESC ';
		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">Non Verified Pages</div>

<div style="font-size:12px; text-align:right">
<a href="?page=pages_non&orby=<?php if ($orby == 'date_desc') echo 'date_asc'; else echo 'date_desc';?>" style="font-size:12px; color:#FFF">Date</a>
 | 
<a href="?page=pages_non&orby=<?php if ($orby == 'id_desc') echo 'id_asc'; else echo 'id_desc';?>" style="font-size:12px; color:#FFF">PageId</a>
 | 
<a href="?page=pages_non&orby=<?php if ($orby == 'link_desc') echo 'link_asc'; else echo 'link_desc';?>" style="font-size:12px; color:#FFF">Link</a>
 |
<a href="?page=pages_non&orby=<?php if ($orby == 'tit_desc') echo 'tit_asc'; else echo 'tit_desc';?>" style="font-size:12px; color:#FFF">Title</a>
</div>
</div>
<?php

$res = mysql_query ("SELECT * FROM page WHERE Verified = 0 " );

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


$res = mysql_query ("SELECT p.Id AS pid, p.PageId, p.Link, p.Title, p.Public, u.Username, ups.UserId as uid 
	FROM page AS p 
	JOIN user_page_submission AS ups ON p.Id = ups.PageId 
	JOIN user AS u ON ups.UserId = u.Id 
	WHERE p.Verified = 0 
	GROUP BY p.Id  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">All pages are verified.</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_non&id=<?php echo $pid; ?>';
    	</script>
        <?php	
}

while ($nr > 0) {
	$row = mysql_fetch_array ($res);
	extract ($row);
	if (isset ($PageId)) {
	$url = 'http://graph.facebook.com/';
	$pageUrl = "" . $url . $PageId . "";
	// create curl resource
	$ch = curl_init();
	// set url
	curl_setopt($ch, CURLOPT_URL, $pageUrl);
	curl_setopt($ch,CURLOPT_HTTPHEADER,array ("Content-Type: text/xml; charset=utf-8"));
	//return the transfer as a string
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	// $output contains the output string
	$output = curl_exec($ch);
	//$output = utf8_encode($output);
	//echo $output . "<br />";

	$param = json_decode($output, true);
	
	$Link = $param['link'];
	$Title = $param['name'];
	$Image = $param['picture'];
	$Fans = $param['fan_count'];
	$Category = str_replace('_', ' ', $param['category']);
}

	?>
    <?php if ($Public != '1') { ?>
    <div style="background-color:#FDD; font-size:12px;">
	<?php } ?>
	    <div class="huge_box_item">
	
		<div class="avatar">
    	<a href="?page=page_non&id=<?php echo $pid;?>"><img src="<?php echo $Image; ?>" alt="<?php echo $Title; ?>" width="50px" height="50px" /></a>
    	</div>
		<div class="description">
		<?php echo $PageId; ?><br />
    	<?php echo $Title; ?><a href="<?php echo $Link; ?>" target="_blank"> - Visit page</a><br />
    	Submitted by: <?php echo $Username; ?>
    	</div>	
    
    	</div>

	<?php if ($Public != '1') { ?>
    </div>
	<?php } ?>
    
    
    <?
	$nr--;
}

?>

<div class="huge_box_footer">
<?php if ($totalpages > 0) { ?>
	<div class="pagination">
	<?php if ($currentpage>2) { ?>
    	<a href="?page=pages_non&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_non&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_non&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_non&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');
?>

</div>
