<?php
session_start();
?>
<?
include ("../var.php");
?>
<?
include("../stop.php");
?>
<?php
if($cat=="$cid"){

$cat = $_GET["cat"];
$cid = $_GET["cat"];

include("header.php");

include('config.php');
echo "<div class='hl'>Categoryes</div>";
$pg=$_GET['pg'];
if(!$pg){
if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 
}
if($pg){$page =
 $pg;}
// Define the number of results per page 
$max_results = 20; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 
$sql = mysql_query("SELECT * FROM `fisiere` WHERE categorie='$cid' ORDER by `id` DESC LIMIT $from,$max_results"); 
if(!$sql){ echo "No files was uploaded yet.<br/>";}
while($row = mysql_fetch_array($sql)){ 
    // Build your formatted results here.
    $file = $row['file'];
$filename = $row['file'];
$user = $row['user'];
$desc = $row['description'];
$sz = $row['size'];
$id = $row['id'];
$ftype = $row['ftype'];
$from = $from+1;

 if ($sz<1024) {$sz="$sz bytes";}
 elseif (($sz>=1024)&&($sz<1048576)) {$sz=strtr(round($sz/1024,2),".",",")." KB";}
 elseif ($sz>=1048576) {$sz=strtr(round($sz/1024/1024,2),".",",")." MB";}


echo "$from.<a href=\"file.php?id=".$id."\">$filename</a>($sz)<br/>";


    
    
} 
// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as id FROM fisiere WHERE categorie='$cid'"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 
if($page > $total_pages){echo "<b><font color=\"red\">The page you requested does not exists.</font></b><br/><a href=\"uploads.php?pg=1\">go to first page</a><br/><a href=\"uploads.php?pg=$total_pages\">go to last page known($total_pages)</a>";
include("flooter.php");
die;
}
echo "<div class='hl'>Navigation</div>";

// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?cat=$cid&page=$prev\">&#171; Prev</a>|"; 
} 
// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?cat=$cid&page=$next\">Next &#187;</a><br/>"; 
} 

$i = 1; $i <= $total_pages; $i++ ;
echo "Page $page of $total_pages<br/>";
if ($total_pages>2)
{
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">Jump To Page: <input type=\"text\" name=\"pg\" style='-wap-input-format: \"5N\" ' size=\"3\" value=\"$page\"/>";
echo "<input type=\"submit\" name=\"p\" value=\"Go\"></form>";
 }

include("flooter.php");
}
?>