<?php
$suroq = mysql_result(mysql_query("SELECT `value` FROM `sitesets` WHERE `id` = '2'"), 0);
$javob = $suroq['value'];
 if($javob != 0) {
  $req = mysql_query("SELECT * FROM `download` WHERE `type` = 'file' ORDER BY `time` DESC LIMIT $javob");
            echo '<div class="phdr">So\'nggi yuklamalar</div>';
	while ($newf = mysql_fetch_array($req)) {
		echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
        $fsz = filesize("$newf[adres]/$newf[name]");
        $fsz = round($fsz / 1024, 2);
        $ft = functions::format("$newf[adres]/$newf[name]");
        switch ($ft) {
            case "mp3" :
                $imt = "mp3.png";
                break;
            case "zip" :
                $imt = "rar.png";
                break;
            case "jar" :
                $imt = "jar.png";
                break;
            case "gif" :
                $imt = "gif.png";
                break;
            case "jpg" :
                $imt = "jpg.png";
                break;
            case "png" :
                $imt = "png.png";
                break;
            default :
                $imt = "file.gif";
                break;
        }
        if ($newf['text'] != "") {
            $tx = $newf['text'];
            if (mb_strlen($tx) > 100) {
                $tx = mb_substr(strip_tags($tx), 0, 90);

                $tx = "<br/>$tx...";
            }
            else {
                $tx = "<br/>$tx";
            }
        }
        else {
            $tx = "";
        }
        echo '<img src="download/img/' . $imt . '" alt=""/><a href="download/index.php?act=view&amp;file=' . $newf['id'] . '">' . htmlentities($newf['name'], ENT_QUOTES, 'UTF-8') . '</a> (' . $fsz . ' кб)' . $tx . '<br/>';
        $nadir = $newf['refid'];
        $pat = "";
        while ($nadir != "") {
            $dnew = mysql_query("select * from `download` where type = 'cat' and id = '" . $nadir . "'");
            $dnew1 = mysql_fetch_array($dnew);
            $pat = "$dnew1[text]/$pat";
            $nadir = $dnew1['refid'];
        }
        $l = mb_strlen($pat);
        $pat1 = mb_substr($pat, 0, $l - 1);
        echo "[$pat1]</div>";
        ++$i;
    }
  }
?>