<?php
function indexcats() {
global  $htmlorphp,$catsloop,$LANGAUGE;

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

$sql = @mysql_query("SELECT * FROM news_cat where active='1' AND sub='0' 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 news where cat='".$Row2['id']."' AND active='1'") or die ("Query failed");
$nu = mysql_num_rows($sql2);

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

if ($htmlorphp=="1"){
$printcats .= "<td width='$width' class='category'><div><a href='news_cat-$Row2[id].html'>".text(3,$Row2['name'])."</a></div></td>
$tslslats";
}else{
$printcats .= "<td width='$width' class='category'><div><a href='news.php?action=cat&id=$Row2[id]'>".text(3,$Row2['name'])."</a></div></td>
$tslslats";
}
}
$printcats .= "</table>";
}
return $printcats;
}


function catstext() {
global $id,$htmlorphp,$folder,$threadsloop,$LANGAUGE,$catsloop;

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

$sqlq = @mysql_query("SELECT * FROM news_cat where active='1' AND sub='".$id."' order by order_cat");
$nuq = mysql_num_rows($sqlq);
if($nuq == 0 ){
$printcats = "";
}else{
$printcats = "<table border='0' width='100%' id='AutoNumber2' style='border-collapse: collapse'>";
$tslsls = '0';
while ($Row2 = @mysql_fetch_array($sqlq))
{
$sql2 = @mysql_query("SELECT id FROM news where cat='".$Row2['id']."' AND active='1'") or die ("Query failed");
$nu = mysql_num_rows($sql2);

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

if ($htmlorphp=="1"){
$printcats .= "<td width='$width' class='category'><div><a href='news_cat-$Row2[id].html'>".text(3,$Row2['name'])."</a></div></td>
$tslslats";
}else{
$printcats .= "<td width='$width' class='category'><div><a href='news.php?action=cat&id=$Row2[id]'>".text(3,$Row2['name'])."</a></div></td>
$tslslats";
}
}
$printcats .= "</table>
<br />";
}





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


$sql = @mysql_query("SELECT id,sub,date,vis FROM news where cat='$id' AND active='1' order by id desc LIMIT $startpoint,$perpage");
$nu = mysql_num_rows($sql);
if($nu == 0 ){
if($nuq==0){
$printcats .= $LANGAUGE[140];
}else{
$printcats .= "";
}
}else{

$printcats .= "<table class='xtable' width='100%' id='AutoNumber15'>
    <tr>
      <td width='70%' class='xtr' align='center'>".$LANGAUGE[82]."</td>
      <td width='20%' class='xtr' align='center'>".$LANGAUGE[83]."</td>
      <td width='10%' class='xtr' align='center'>".$LANGAUGE[84]."</td>
    </tr>";
while ($Row = @mysql_fetch_array($sql))
{
$text = text(3,$Row['sub']);
$d = date("j/n/Y",$Row['date']);

if ($htmlorphp=="1"){
$printcats .= "<tr>
<td width='70%' class='xtd'><a href='news-$Row[id].html'>$text</a></td>
<td width='20%' class='xtd' align='center'>$d</td>
<td width='10%' class='xtd' align='center'>$Row[vis]</td>
</tr>";
}else{
$printcats .= "<tr>
<td width='70%' class='xtd'><a href='news.php?action=view&id=$Row[id]'>$text</a></td>
<td width='20%' class='xtd' align='center'>$d</td>
<td width='10%' class='xtd' align='center'>$Row[vis]</td>
</tr>";
}
$colorcss++;
}

$printcats .= "</table>";

$pagesnum = @ceil(mysql_num_rows(mysql_query("select `id` from `news` 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='news-pages-$id-$i.html'>$i</a>";
}else{
$z = "<a href='news.php?action=cat&id=$id&page=$i'>$i</a>";
}

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

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

return $printcats;
}


function archivethreads() {
global $htmlorphp,$folder,$archivethreadsnumber,$LANGAUGE;

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

$sql = @mysql_query("SELECT id,sub,date,vis FROM news where active='1' order by id DESC LIMIT $startpoint,$perpage");
$nu = mysql_num_rows($sql);
if($nu == 0 ){
$printcats = $LANGAUGE[140];
}else{

$printcats = "<table class='xtable' width='100%' id='AutoNumber15'>
    <tr>
      <td width='70%' class='xtr' align='center'>".$LANGAUGE[82]."</td>
      <td width='15%' class='xtr' align='center'>".$LANGAUGE[83]."</td>
      <td width='15%' class='xtr' align='center'>".$LANGAUGE[84]."</td>
    </tr>";
while ($Row = @mysql_fetch_array($sql))
{
$text = text(3,$Row['sub']);
$d = date("j/n/Y",$Row['date']);

if ($htmlorphp=="1"){
$printcats .= "<tr>
<td width='70%' class='xtd'><a href='news-$Row[id].html'>$text</a></td>
<td width='15%' class='xtd' align='center'>$d</td>
<td width='15%' class='xtd' align='center'>$Row[vis]</td>
</tr>";
}else{
$printcats .= "<tr>
<td width='70%' class='xtd'><a href='news.php?action=view&id=$Row[id]'>$text</a></td>
<td width='15%' class='xtd' align='center'>$d</td>
<td width='15%' class='xtd' align='center'>$Row[vis]</td>
</tr>";
}
}

$printcats .= "</table>";

$pagesnum = @ceil(mysql_num_rows(mysql_query("select `id` from `news` where 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='archive-$i.html'>$i</a>";
}else{
$z = "<a href='news.php?action=archive&page=$i'>$i</a>";
}

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

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

return $printcats;
}
?>