<?php
function textcats() {
global  $htmlorphp,$text_catsloop,$LANGAUGE;

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

$sql = @mysql_query("SELECT * FROM  text_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 text where cat='".$Row2['id']."' AND active='1'");
$nu = mysql_num_rows($sql2);

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

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

if ($htmlorphp=="1"){
$p = "<a href='textcat-$Row2[id].html'>$Row2[name_cat]</a>";
}else{
$p = "<a href='text.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 texts() {
global $id,$htmlorphp,$LANGAUGE,$folder,$text_catsloop,$limit_text;

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

$sqlx = @mysql_query("SELECT * FROM text_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 text where cat='".$Row2['id']."' AND active='1'");
$number = mysql_num_rows($numall);

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

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

if ($htmlorphp=="1"){
$p = "<a href='textcat-$Row2[id].html'>$Row2[name_cat]</a>";
}else{
$p = "<a href='text.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_text;
$startpoint = ($page * $perpage) - $perpage;

$sql = @mysql_query("SELECT id,name,vis,date FROM text 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[296];
}else{
$printcats .= "";
}
}else{
$printcats .= "<table class='xtable' width='100%' id='AutoNumber15'>
<tr>
<td width='80%' class='xtr' align='center'>".$LANGAUGE[297]."</td>
<td width='20%' class='xtr' align='center'>".$LANGAUGE[93]."</td>
</tr>";
while ($Row = @mysql_fetch_array($sql))
{
$Row[name] = text(3,$Row[name]);

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

$printcats .= "</table>";

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

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

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

} else {
$z = "<span class='act'>$i</span>";
}
$printcats .= "$z";

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

return $printcats;
}
?>