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

include ("config.php");

include ("header.html");
?>
<table width='950' cellspacing='0' cellpadding='0' align='center'>
<?php
include ("right.html");
?>

<td width='760' valign='top' class='continut'>

<table cellspacing='0' cellpadding='10'  width='100%'>
<tr><td>

<!-- CONTINUTUL !!!! -->
<script type="text/javascript">
function hover(pid, status) {

if (status == true) {
   document.getElementById(pid).style.background = "yellow";
   document.getElementById("fd").style.display = "block";
   }
else {
    document.getElementById(pid).style.background = "white";
     }
}
function doconfirm() {
 document.getElementById("fdc").style.display = "block";
}
</script>

<table width='100%'  cellspacing='0' cellpadding='0'>

<tr>
<td width='40%' valign='top'>
<div class='hl'>Latest 15 files</div>
</td>
<td width='60%'>

</td>
</tr>
</table>
<table width='100%'  cellspacing='0' cellpadding='4'  class='tbnail border'>
<tr>

<td width='60%' valign='top'>

<table width='100%' >
<tr>

<?php
$rezultate_maxime_in_linie = 3;
$rezultate_maxime_in_jos = 5;

$result = mysql_query('SELECT * FROM `fisiere` LIMIT 15');
$totale = mysql_num_rows($result);

$ids=1;

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

	$cerereSQL = mysql_query('SELECT * FROM `fisiere` ORDER by `id` DESC LIMIT '.(($pagina * ($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($cerereSQL)) {
				$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);
$down = $rand['download'];
$userup = $rand['user'];
$ftype = $rand['ftype'];
$uid = $rand["id"];
$file = $rand['file'];
$pid = $rand["id"];
$abuse = $rand["abuse"];
$lastac = $rand["uploaded"];


if(in_array($abuse,array("1","2","3","4")))
	  {

$ban = " bgcolor='#F8CCCC' ";
	   }else{
$ban = "";
		} 
?>

<td width='33%'<?php echo "$ban";?> id='<?php echo "$seteaza" ?>'>
<a href='file.php?id=<?php echo "$uid";?>' title='<?php echo "$file"; ?>,  <?php echo "$sz"; ?>, 
<?php echo "$down"; ?> downloads , by <?php echo "$userup"; ?>' style='height:115'>
<?php
if(in_array($ftype,array("gif","jpg","jpeg","png")))
	  {

		echo "<img src='thumb/".$rand['file']."' alt='$filename' align='absmiddle' />";
	   }else{

		 echo "<img src='interfata/res/$ftype.gif' alt='$filename' align='middle'' />";

}
?>  
<br/><?php echo "$filename";?></a>
</td>

<?php
}
}
$ids=1;
?>
</tr></table>
	
<table>
<tr>
<td colspan='4'>
<a href='uploads.php'>&rsaquo;&rsaquo; Browse all files </a>
</td>
</tr>
</table>

</td>

<td width='40%' valign='top' class='border1'>
<div class='hl'>Hot today</div>
<table width='100%' cellspacing='5' cellpading='3'>
<tr>
<td width='85%'>
</td><td width='15%'>
</td>
</tr>
<?php
$top_time=time()-86400;
$top=mysql_query("SELECT * FROM fisiere WHERE time>$top_time ORDER BY download DESC LIMIT 21");

while($row = mysql_fetch_array($top)){
    // Build your formatted results here.
    $file = substr($row['file'],0,30).'...';
$filename = $row['file'];
$id = $row['id'];
$down = $row['download'];
echo "<tr>
<td>
<a href='file.php?id=$id'>$file</a>
</td>
<td><small>($down)</small></td>
</tr>";

}
?>
</tr></table>
<div class='txt'>
<a href='topdl.php'>&rsaquo;&rsaquo; View top downloads </a><br/>
</div></td>
</tr>
</table>
<table width='100%' cellspacing='5' cellpadding='0'>
<tr>
<td width='50%' valign='top' class='border'>
<div class='hl'>Top played media</div>
<table width='100%' cellspacing='5' cellpadding='3' class='border_jos2'>
<tr><td width='90%'>
</td><td width='10%'>
</td></tr>

<?php
$media = mysql_query("SELECT * FROM fisiere WHERE ftype='mp3' ORDER BY download DESC LIMIT 0,15");
while($row = mysql_fetch_array($media)){
    
$filemp3 = substr($row['file'],0,39)."&nbsp; ...";
$fid = $row['id'];
$downfile = $row['download'];
$filemp3=str_replace("wWw"," ",$filemp3);
$filemp3=str_replace("_"," ",$filemp3);
$filemp3=str_replace("["," ",$filemp3);
$filemp3=str_replace("by"," ",$filemp3);
$filemp3=str_replace(".Net"," ",$filemp3);
$filemp3=str_replace(".Extrem"," ",$filemp3);
$filemp3=str_replace(".mp3"," ",$filemp3);

echo "<tr>
<td>
<a href='file.php?id=" .$fid. "' title='Play $filemp3'><small>$filemp3</small></a>
</td>
<td align='right'>  <small><small>" .$downfile. "</small></small>";
echo "</td>
</tr>";
}
?>
</td></table>
<td width='50%' valign='top' class='border'>
<div class='hl'>Last 10 comments</div>
<table width='100%' cellspacing='5' cellpadding='3' class='border_jos2'>
<tr><td width='30%'>
</td><td width='70%'>
</td></tr>

<?php
// Define the number of results per page 
$max_results = 10; 
// Figure out the limit for the query based 
// on the current page number. 
$from = (($max_results) - $max_results); 

$sql = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT $max_results");
while($row = mysql_fetch_array($sql)){ 
$id = $row['id'];
$uname = $row['uname'];
$file = $row['file'];
$date = $row['date'];

$tofile = "<a href='file.php?id=$file' title='Read More'> more...<a/>";

$date_formated = date('H:i:s d-m-Y', $date);
$comment = substr($row['comment'],0,75)."&nbsp;". $tofile."";

$getusersonline = mysql_query("SELECT * FROM utilizatori WHERE nume='$uname'"); //grab from sql users on in last 15 minutes
while($getusersonline3=mysql_fetch_array($getusersonline))
{
$avat = $getusersonline3["setavatar"];
$id = $getusersonline3["id"];
$mod = $getusersonline3["color"];
$avatar = $getusersonline3["avatar"];
print "<tr>
<td>";
}
 if($avat[0]=="1")
	  {
		echo "<img src='avatar/$avatar' alt='$uname' />";
	   }else{
		 echo "";
		}  
print "<small><a href='profile.php?id=$id' class='$mod'>$uname</a></small>
   </td>
<td><small><small>  ". $comment. " <br/> " . $date_formated. " <br/></small></small></td>
   </tr>";

}
?>
</tr></table>
<div class='txt'></div>
<table class='tbnail'><tr>
<td></td></tr></table>
</td></tr><tr>
<td width='50%' valign='top' class='border'>
<div class='hl'>Detalies</div>
<div class='txt'>
<?php
$total = mysql_result(mysql_query("SELECT COUNT(*) as id FROM fisiere"),0);
$totalusers = mysql_result(mysql_query("SELECT COUNT(*) as id FROM utilizatori"),0);

echo "<b> Total users:</b> ".$totalusers."<a href='ulist.php'>&rsaquo;&rsaquo;  View List</a><br/>";
echo "<b> Total files:</b> ".$total."<br/>";
echo "<b>Top 3 Uploaders:</b> ";

$sqltop = mysql_query("SELECT * FROM utilizatori WHERE fisiere ORDER BY fisiere DESC LIMIT 3");
$nr=1;
while($row = mysql_fetch_array($sqltop)){
$topname = $row["nume"];    
$topid = $row["id"];
$topcolor = $row["color"];
$total = $row["fisiere"];
echo "<a href='profile.php?id=$topid' class='$topcolor'><small><small><sup>$nr</sup>$topname ($total) &nbsp; </small></small></a>";
$nr++;
}
?>
<br/></div>
</div></td>
<td width='50%' valign='top' class='border'>
<div class='hl'>Statistics</div>
<div class='txt'>
<?php
$sql = mysql_query("SELECT * FROM setting WHERE id = '1' ");
while($row = mysql_fetch_array($sql))
{
$count = $row["hit"];   
$count = $count + 1;
echo "Total hits: <b>$count</b> ";
}

echo "<br />Last Users: ";

$ultimate = mysql_query("SELECT * FROM utilizatori WHERE id ORDER BY id DESC LIMIT 0,10");
$i=1;
$color=1;
while($row=mysql_fetch_array($ultimate))
{
	$data=explode(" ",$row['id']);
	$data=explode("-",$data['0']);


echo ", <a href='profile.php?id=". $row["id"] ."'><small><small>". $row["nume"] ."</small></small></a>";
}
echo ".";
?>
</div></td></tr>
</table><br/>
<table width='100%'  cellspacing='0' cellpadding='0'>
<tr><td width='100%' valign='top'>
<div class='hl'>Online users</div>
</td></tr></table>
<table width='100%'  cellspacing='0' cellpadding='4'  class='border'>
<tr><td>
<?
if(isset($_SESSION['nume'])) {
      	$username = ''.$_SESSION['nume'].'';
  $getuser = mysql_query("SELECT * from utilizatori where nume='$username'");
  $getuser3=mysql_fetch_array($getuser);
  $thedate=date("U");
  $checktime=$thedate-200;
  $uprecords="Update utilizatori set lasttime='$thedate' where id='$getuser3[id]'";
  mysql_query($uprecords) or die("Could not update records");
if($getuser3[tsgone]<$checktime)
  {
    $updatetime="Update utilizatori set tsgone='$thedate', oldtime='$getuser3[tsgone]' where id='$getuser3[id]'";
    mysql_query($updatetime) or die("Could not update time");
  }
  }
?>
<?php
include("useronline.php");
?>
</td></tr></table><br/><br/>
</td></tr></table></td>
</tr><td width='180'></td>
<?php
include ("flooter.html");
?>