<?php
function downloadcats() {
global  $htmlorphp,$download_catsloop,$LANGAUGE;

if($download_catsloop=="1"){$width = "100%";}
elseif($download_catsloop=="2"){$width = "50%";}
elseif($download_catsloop=="3"){$width = "33%";}
elseif($download_catsloop=="4"){$width = "25%";}
elseif($download_catsloop=="5"){$width = "20%";}
elseif($download_catsloop=="6"){$width = "16%";}
else{$width = "";}

$sql = @mysql_query("SELECT * FROM  download_cat where sub='0' AND active='1' order by order_cat");
$nu = mysql_num_rows($sql);
if($nu == 0){
$printcats = $LANGAUGE[91];
}else{
$printcats = "<table border='0' width='100%' id='AutoNumber2' style='border-collapse: collapse'>";

$tslsls = '0';
while ($Row2 = @mysql_fetch_array($sql))
{
$sql2 = @mysql_query("select id from download where cat='".$Row2['id']."' AND active='1'");
$nu = mysql_num_rows($sql2);

++$tslsls;
if($tslsls=="$download_catsloop"){
$tslslats = "</tr><tr>";
$tslsls="0";
}else{
$tslslats = "";
}

$Row2[name_cat] = text(3,$Row2[name_cat]);

if ($htmlorphp=="1"){
$p = "<a href='downloadcat-$Row2[id].html'>$Row2[name_cat]</a>";
}else{
$p = "<a href='download.php?action=cat&id=$Row2[id]'>$Row2[name_cat]</a>";
}

$printcats .= "<td width='$width' class='category'><div>".$p."</div></td>
$tslslats";

}
$printcats .= "</table>";
}
return $printcats;
}


function download() {
global $id,$htmlorphp,$folder,$LANGAUGE,$download_catsloop,$limit_download;

if($download_catsloop=="1"){$width = "100%";}
elseif($download_catsloop=="2"){$width = "50%";}
elseif($download_catsloop=="3"){$width = "33%";}
elseif($download_catsloop=="4"){$width = "25%";}
elseif($download_catsloop=="5"){$width = "20%";}
elseif($download_catsloop=="6"){$width = "16%";}
else{$width = "";}


$sqlx = @mysql_query("SELECT * FROM  download_cat where sub='$id' AND active='1' order by order_cat");
$nux = mysql_num_rows($sqlx);
if($nux==0){
$printcats = "";
}else{
$printcats = "<table border='0' width='100%' id='AutoNumber2' style='border-collapse: collapse'>";
$tslsls = '0';
while ($Row2 = @mysql_fetch_array($sqlx))
{
$numall = @mysql_query("select id from download where cat='$Row2[id]' AND active='1'");
$number = mysql_num_rows($numall);

$Row2[name_cat] = text(3,$Row2[name_cat]);

if ($htmlorphp=="1"){
$p = "<a href='downloadcat-$Row2[id].html'>$Row2[name_cat]</a>";
}else{
$p = "<a href='download.php?action=cat&id=$Row2[id]'>$Row2[name_cat]</a>";
}

++$tslsls;
if($tslsls=="$download_catsloop"){
$tslslats = "</tr><tr>";
$tslsls="0";
}else{
$tslslats = "";
}

if ($htmlorphp=="1"){
$p = "<a href='downloadcat-$Row2[id].html'>$Row2[name_cat]</a>";
}else{
$p = "<a href='download.php?action=cat&id=$Row2[id]'>$Row2[name_cat]</a>";
}

$printcats .= "<td width='$width' class='category'><div>".$p."</div></td>
$tslslats";
}
$printcats .= "</table>";
}


$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$page = ($page == 0 ? 1 : $page);
$perpage = $limit_download;
$startpoint = ($page * $perpage) - $perpage;

$sql = @mysql_query("SELECT id,name,vis,date,short,downloads FROM download where cat='$id' AND active='1' order by id desc limit $startpoint,$perpage");
$nu = mysql_num_rows($sql);
if($nu != 0 AND $nux != 0){
$printcats .= "<br />";
}

if($nu==0){
if($nux==0){
$printcats .= $LANGAUGE[110];
}else{
$printcats .= "";
}
}else{
$printcats .= "";
$r=0;
while ($Row = @mysql_fetch_array($sql))
{
++$r;
$d = date("j/n/Y",$Row['date']);
$dow = $Row['downloads'];
$Row[name] = text(3,$Row[name]);
$Row['short'] = text(3,$Row['short']);

if($Row['short'] == ""){
$sss = "";
}else{
$sss = "<div class='programmdesc'>".$Row['short']."</div>";
}

if ($htmlorphp=="1"){
$llll = "<a href='downloadshow-$Row[id].html'>$Row[name]</a>";
$lllx = "<a href='downloadshow-$Row[id].html'>".$LANGAUGE[250]."</a>";
}else{
$llll = "<a href='download.php?action=show&id=$Row[id]'>$Row[name]</a>";
$lllx = "<a href='download.php?action=show&id=$Row[id]'>".$LANGAUGE[250]."</a>";
}

if($r != $nu){
$sy = "<br />";
}else{
$sy = "";
}

$info = '<div class="programminfo">'.$lllx.' - '.$LANGAUGE[83].' : '.$d.' - '.$LANGAUGE[84].' : '.$Row['vis'].'</div>';

$printcats .= "<div class='programm'><h1>".$llll."</h1>".$sss."".$info."</div>".$sy;
}


$pagesnum = @ceil(mysql_num_rows(mysql_query("select `id` from `download` where cat='$id' AND active='1'")) / $perpage);

if($pagesnum > 1){
$printcats .= "<div align='center'>";
for ($i=1; $i<=$pagesnum; $i++) {
if ($i != $page) {

if ($htmlorphp=="1"){
$z = "<a href='downloadpage-$id-$i.html'>$i</a>";
}else{
$z = "<a href='download.php?action=cat&id=$id&page=$i'>$i</a>";
}

} else {
$z = "<u>$i</u>";
}
$printcats .= "[$z]";

}
$printcats .= "</div>";
}
}

return $printcats;
}
?>