<?php
include("connect.php");
include("includes/func_book.php");
$folder=$folderbook;
$action = $_GET['action'];
if(!isset($action)) $action = "home";

IF ($action=="home"){
$m1=$d3;
$m2=$k3;
tpl_header($LANGAUGE[52]);
bar($namelinks1,$LANGAUGE[52],"","");
table($LANGAUGE[52],bookcats(),1);
tpl_footer();

}ELSEIF ($action=="book_cat"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from book_cat where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}

$sql = mysql_query("update book_cat set vis=vis+1 where id='$id'") or die ("Query failed");

$Row['name'] = text(3,$Row['name']);

tpl_header($Row['name']);
bar($namelinks1,$namelinks3,$Row['name'],"");
table($Row['name'],booksall(),1);
tpl_footer();

}ELSEIF ($action=="showbook"){
$id = intval($_GET["id"]);

$sql = @mysql_query("select * from book_all where id='$id' AND active='1'");
$Row = @mysql_fetch_array($sql);
if (!$Row)
{
error();
exit;
}

$sql = @mysql_query("update book_all set vis=vis+1 where id='$id'") or die ("Query failed");

$n = text(3,$Row['name']);
$c = $Row['cat'];
$ex= text(3,$Row['ext']);
$text = text(2,$Row['text']);
$Row[writerbook] = text(3,$Row[writerbook]);
$Row[image] = text(3,$Row[image]);
$Row['downloads'] = text(3,$Row['downloads']);

$d = date("j/n/Y",$Row['date']);

$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>';
}


$sql3 = @mysql_query("SELECT * FROM book_cat where id='$c'") or die ("Query failed");
$ncat = @mysql_fetch_array($sql3);
$namecat = text(3,$ncat['name']);
$idcat   = $ncat['id'];

if ($htmlorphp=="1"){
$xxcat = "<a href='book_cat-$idcat.html'>$namecat</a>";
}else{
$xxcat = "<a href='book.php?action=book_cat&id=$idcat'>$namecat</a>";
}

tpl_header($n);
bar($namelinks1,$namelinks3,$xxcat,$n);

if($text == ""){
$tt = "";
}else{
$tt = "<tr><td width='100%' colspan='2' class='xtd'>".nl2br($text)."</td></tr>";
}

if($Row[writerbook] == ""){
$w = "<tr>
<td width='30%' class='xtr'>".$LANGAUGE[95]." :</td>
<td width='70%' class='xtd'>".$LANGAUGE[99]."</td>
</tr>";
}else{
$w = "<tr>
<td width='30%' class='xtr'>".$LANGAUGE[95]." :</td>
<td width='70%' class='xtd'>$Row[writerbook]</td>
</tr>";}

if($Row[image] == ""){
$i = "";
}else{
$i = "<tr>
<td width='30%' class='xtr'>".$LANGAUGE[101]." :</td>
<td width='70%' class='xtd'><img border='0' src='$Row[image]' alt='$n' /></td>
</tr>";
}


$zxz = "<table class='xtable' width='100%' id='AutoNumber1f5'>
$tt
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[94]." :</td>
      <td width='70%' class='xtd'>$n</td>
    </tr>
$w
$i
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[103]." :</td>
      <td width='70%' class='xtd'>".$ro."</td>
    </tr>

    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[84]." :</td>
      <td width='70%' class='xtd'>$Row[vis]</td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[83]." :</td>
      <td width='70%' class='xtd'>$d</td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE[212]."</td>
      <td width='70%' class='xtd'>$xxcat</td>
    </tr>
  </table>";

table($n,$zxz,1);

tpl_footer();
}
?>