<?php
function bookcats() {
global  $htmlorphp,$booksloop,$LANGAUGE;

if($booksloop=="1"){$width = "100%";}
elseif($booksloop=="2"){$width = "50%";}
elseif($booksloop=="3"){$width = "33%";}
elseif($booksloop=="4"){$width = "25%";}
elseif($booksloop=="5"){$width = "20%";}
elseif($booksloop=="6"){$width = "16%";}
else{$width = "";}
$sql = @mysql_query("SELECT * FROM  book_cat where sub='0' AND active='1' order by order_cat");
$numberx = mysql_num_rows($sql);
if($numberx==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))
{
$numall = @mysql_query("select id from book_all where cat='$Row2[id]'");
$number = mysql_num_rows($numall);

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

$Row2[name] = text(3,$Row2[name]);
$Row2[image] = text(3,$Row2[image]);
$Row2[describes] = text(3,$Row2[describes]);

if ($Row2[image]){
$imageok = "<img border='0' src='$Row2[image]' alt='$Row2[name]' /><br />";
}else{
$imageok = "";
}

if ($Row2[describes]){
$Describesok = "<br />$Row2[describes]";
}else{
$Describesok = "";
}


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

return $printcats;
}


function booksall() {
global $id,$htmlorphp,$folder,$booksloop,$booksviewloop,$LANGAUGE;

if($booksloop=="1"){$width = "100%";}
elseif($booksloop=="2"){$width = "50%";}
elseif($booksloop=="3"){$width = "33%";}
elseif($booksloop=="4"){$width = "25%";}
elseif($booksloop=="5"){$width = "20%";}
elseif($booksloop=="6"){$width = "16%";}
else{$width = "";}
$sql = @mysql_query("SELECT * FROM book_cat where sub='$id' AND active='1' order by order_cat");
$numberx = mysql_num_rows($sql);
if($numberx==0){
$printcats = "";
}else{
$printcats = "<table border='0' width='100%' id='AutoNumber2' style='border-collapse: collapse'>";
$tslsls = '0';
while ($Row2 = @mysql_fetch_array($sql))
{
$numall = @mysql_query("select id from book_all where cat='$Row2[id]' AND active='1'");
$number = mysql_num_rows($numall);

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

$Row2[name] = text(3,$Row2[name]);
$Row2[image] = text(3,$Row2[image]);
$Row2[describes] = text(3,$Row2[describes]);

if ($Row2[image]){
$imageok = "<img border='0' src='$Row2[image]' alt='$Row2[name]' /><br />";
}else{
$imageok = "";
}

if ($Row2[describes]){
$Describesok = "<br />$Row2[describes]";
}else{
$Describesok = "";
}


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



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



$sql3 = @mysql_query("SELECT * FROM book_all where cat='$id' AND active='1' order by id desc LIMIT $startpoint,$perpage");
$nut = mysql_num_rows($sql3);
if($nut==0 AND $numberx==0){
$printcats .= $LANGAUGE[100];
}elseif($nut==0 AND $numberx!=0){
$printcats .= "";
}else{

$printcats .= "<table class='xtable' width='100%' id='AutoNumber15'>
  <tr>
<td class='xtr' width='50%' align='center'>".$LANGAUGE[94]."</td>
<td class='xtr' width='30%' align='center'>".$LANGAUGE[95]."</td>
<td class='xtr' width='15%' align='center'>".$LANGAUGE[250]."</td>
<td class='xtr' width='5%' align='center'>".$LANGAUGE[93]."</td>
</tr>";
while ($Row = @mysql_fetch_array($sql3))
{
$Row[name] = text(3,$Row[name]);
$Row['downloads'] = text(3,$Row['downloads']);
$Row[writerbook] = text(3,$Row[writerbook]);
$Row[text] = text(3,$Row[text]);

$url = explode("[*]", $Row['downloads']);
$files = count($url);

$ro = "";
$ii = 0;
for($i=0;$i<$files;$i++){
$ii++;
if($ii != $files){
$fff = "&nbsp;";
}

$ro .= '<a href="'.$url[$i].'">'.typefile($url[$i],$n).$fff.'</a>';
}

if($Row[text] != ""){
$tex = "<a href='book.php?action=veiwbook&id=$Row[id]'><img border='0' src='$folder/icons/text.gif' /></a>";
}else{
$tex = "<img border='0' src='$folder/icons/table.gif' alt='".$LANGAUGE[98]." $Row[name]' />";
}

if($Row[text] != ""){
$texh = "<a href='veiwbook-$Row[id].html'><img border='0' src='$folder/icons/text.gif' /></a>";
}else{
$texh = "<img border='0' src='$folder/icons/table.gif' alt='".$LANGAUGE[98]." $Row[name]' />";
}

if($Row[writerbook] != ""){
$writer = "$Row[writerbook]";
}else{
$writer = "- - -";
}

if ($htmlorphp=="1"){
$urlll = "showbook-$Row[id].html";
}else{
$urlll = "book.php?action=showbook&id=$Row[id]";
}

$printcats .= "<tr>
<td class='xtd' width='50%'><a href='".$urlll."'>$Row[name]</a></td>
<td class='xtd' width='30%' align='center'>$writer</td>
<td class='xtd' width='15%' align='center'>".$ro."</td>
<td class='xtd' width='5%' align='center'>$Row[vis]</td>
</tr>";
}

$printcats .= "</table>";

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

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

if ($i != $page) {

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

} else {
$z = "<span class='act'>$i</span>";
}
$printcats .= "$z";
if($ddd >= 15){
$printcats .= "<br /><br />";
$ddd=0;
}

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