<?php session_start(); ?>
<?php
include("stop.php");
?>
<?php
include ("config.php");


if(isset($_SESSION['nume'])) {
      	$username = ''.$_SESSION['nume'].'';
$stare = "Show Last File Uploads";
if(!$act){mysql_query("UPDATE utilizatori SET stare='$stare' WHERE nume='$username'");}
}

include ("uploads.html");

echo "<table width='950' cellspacing='0' cellpadding='0' align='center'>";

include ("right.html");

echo "<td width='720' valign='top' class='continut'>";
echo "<table cellspacing='0' cellpadding='10'  width='100%'>";
echo "<tr>";
echo "<td>";
?>
<!-- CONTINUTUL !!!! -->
<?
echo "<div class='hl'>Latest Uploads</div><center>";
echo "</center>";

include"config.php";

$result = mysql_query("SELECT * FROM fisiere WHERE id");
$num_rows = mysql_num_rows($result);

echo "<left>We've got: <b>$num_rows </b>files.</left></font></br>";
?>
<table width='100%'>
<tr>
<td align='50%'>
<br/>
<small>
<small>
</small>
</small>
</td>
<td align='right' style='text-align: right;'>
</td>
</tr>
</table>
<table width='100%'  cellspacing='0' cellpadding='4'  class='tbnail border'>
<tr>

<?php
if(!isset($_GET['p'])){
$page = 1;
} else {
$page = $_GET['p'];
}

$max_results = 30;

$from = (($page * $max_results) - $max_results);
$sql = mysql_query("SELECT * FROM fisiere ORDER BY id desc LIMIT $from,$max_results");

// Define the number of results per page 
echo "<table width='100%'  cellspacing='0' cellpadding='4'  class='tbnail border'><tr>";

$rezultate_maxime_in_linie = 5;
$rezultate_maxime_in_jos = 6;
$from = (($page * $max_results) - $max_results); 
$result = mysql_query('SELECT * FROM `fisiere` LIMIT 30');
$totale = mysql_num_rows($result);


if($totale == 0) echo 'Nu exista intrari ...';
elseif(!isset($_GET['pagina'])) $pagina = 1;
else $pagina = $_GET['pagina'];

	$sql = mysql_query('SELECT * FROM `fisiere` ORDER by `id` DESC LIMIT '.(($page * ($rezultate_maxime_in_jos*$rezultate_maxime_in_linie)) - ($rezultate_maxime_in_jos*$rezultate_maxime_in_linie)).', '.($rezultate_maxime_in_jos*$rezultate_maxime_in_linie).' ');

	$pagini_totale = ceil($totale / ($rezultate_maxime_in_jos*$rezultate_maxime_in_linie));

	if($pagina > $pagini_totale);
	elseif($pagini_totale > 0) {

			$seteaza = 0;
			$numar = ($pagina - 1) * ($rezultate_maxime_in_jos*$rezultate_maxime_in_linie);
		
			while($rand = mysql_fetch_array($sql)) {
				$numar++;

				if($seteaza == $rezultate_maxime_in_linie) {
				echo "</tr><tr>\n";
				$seteaza = 1;
				} else $seteaza++;

$sz = $rand['size'];
 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";}

$filename = $rand['file'];
$filename=str_replace("_"," ",$filename);
$filename=str_replace("."," ",$filename);
$filename = substr($filename,0,35);
$file = $rand['file'];
$ftype = $rand['ftype'];
$pid = $rand['id'];
$abuse = $rand["abuse"];
if(in_array($abuse,array("1","2","3","4")))
	  {

$ban = " bgcolor='#F8CCCC' ";
	   }else{
$ban = " ";
		}  
echo "<td width='20%' $ban id='". $rand["id"] ."'> ";
echo "<a href='file.php?id=". $rand["id"] ."' title='". $rand["file"] .", $sz, ". $rand["download"] ." downloads by ". $rand["user"] ."' style='height:115'>";
if(in_array($ftype,array("gif","jpg","jpeg","png")))
	  {
		echo "<img src='thumb/".$rand['file']."' align='absmiddle' />";
	   }else{
		 echo "<img src='interfata/res/". $rand["ftype"] .".gif' align='absmiddle' />";
		} 
echo "<br/>$filename</a><div class='hl abuseL normalfont'> $sz | <a href='report.php?id=". $rand["id"] ."' title='Report abuse/bad file' />!</a></div>";
echo "</td>";

			}

}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as id FROM fisiere"),0);
$total_pages = ceil($total_results / $max_results);

echo "</tr><tr></tr></table>";
echo "<br/><div class='hl'>Navigation</div>
<table width='100%' cellpadding=''3'><tr><td bgcolor='#E2EDF6'>";
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=$prev\">&#171;Prev </a> | ";
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=$next\"> Next&#187;</a>";
}
$i = 1; $i <= $total_pages; $i++ ;
if ($total_pages>2)
{
echo "<br/>Jump To Page: ($page/$total_pages):
<br/>";
echo "<form action=\"uploads.php\" method=\"get\">
<input type=\"text\" name=\"p\" style='-wap-input-format: \"5N\"' value=\"$page\" />
<input type=\"submit\"  value=\"Dute!\"/>
</form>";
}
?>
</tr>
<tr>
</tr>
</table>
</div>

<!-- SFARSIT CONTINUT!!! -->

<br />
</td>
</tr>
</table>
<tr>
<td width='180'>
</td>
<?php
include ("flooter.html");
?>