<?php /*
 UserCake Version: 2.0.2
 http://usercake.com
 */

    require_once ("models/config.php");
    if(!securePage($_SERVER['PHP_SELF']))
    {
        die();
    }
    require_once ("models/header.php");
    include ("main-nav.php");
    require_once ("paginator.class.2.php");
    
//Ako nisi ulogovan - begaj odavde :)
if(!isUserLoggedIn()) :
	header("Location: index.php");
	die(); 
endif;

    $pages = new Paginator;
    
    // Num rows
    $pages->items_total = countImages(1);
    
    // Mid range
    $pages->mid_range = 7;
    
    // Paginate
    $pages->paginate();
    
    // Sorting
    $najnoviji_link = "<a class='sort_list' href = 'http://homepage.rs" . $_SERVER['PHP_SELF'] . "?&order_by=new'>Najnovije</a>";
    $najpopularniji_link = "<a class='sort_list' href = 'http://homepage.rs" . $_SERVER['PHP_SELF'] . "?&order_by=top'>Najpopularnije</a>";
    
    if(!isset($_GET['order_by']) || $_GET['order_by'] == 'new')// Oredr by new
    {
        $rows = getImages($pages->limit, "new");
    }
    elseif($_GET['order_by'] == 'top')// Oredr by top
    {
        $rows = getImages($pages->limit, "top");
    }
    else
    {
        echo "greska u query stringu";
    }
    $url = explode('/', $_SERVER['PHP_SELF']);
?>
<section>
	<h2>Top lista</h2>

	<div class="sorting">
		<?php echo $najpopularniji_link; ?> <?php echo $najnoviji_link; ?>
	</div>
<div class="top_list_holdera">
	<?php foreach($rows as $row) :	?>
	<div class="row_holder">
	    <div class="row_image">
	        <a href = "https://homepage.rs/<?php echo $url[1] . "/single-image.php?img=" . $row['image_id']; ?>"><img src="ccphotos/<?php echo $row['filename']; ?>.jpg" /></a>
	    </div>
      <div class="row_name">
	        <a href = "https://homepage.rs/<?php echo $url[1] . "/single-image.php?img=" . $row['image_id']; ?>"><?php  echo $row['display_name']; ?></a>
          <div class="row_votes">
            <a href = "https://homepage.rs/<?php echo $url[1] . "/single-image.php?img=" . $row['image_id']; ?>">
              <?php 
                 if(!$row['broj']){echo "0";}
                 else{echo $row['broj'];}
              ?>
            </a>
          </div>
         
	    </div>
	</div>

	<?php endforeach; ?>
</div>
	<div class="pagination">
		<?php echo $pages->display_pages(); ?>
		<?php echo $pages->display_jump_menu(); ?>
	</div>

</section>
<?php require_once("models/footer.php");


?>