<?php
///////////////////////////////////////////////////
//2010 (C)
//Карпухин Павел
///////////////////////////////////////////////////
require_once "utils/chlang_osn.php";

$title = $TEXT['menu-btn30-title'];

require_once "config.php";
require_once "utils/functions.php";
require_once "utils/top.php";

if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "utils/bottom.php"; exit();}
$_GET['k'] = rep($_GET['k']);
if(empty($_GET['k'])) {$_GET['k']=0;}
$stop_r = $_GET['k'];
if($stop_r == 0) {$lim_ogr = "10";}
else {$lim_ogr = $stop_r.",10";}

$ktblvis = $stop_r+10;
$str = $ktblvis/10;
?>
<table align="center" border="0" cellpadding="3" cellspacing="0" width="90%">
<tbody id="tab" >
<?php
     $query_body = "SELECT 
     tbl_book.book_name, 
     tbl_book.book_id, 
     tbl_book.book_rating, 
     tbl_book.cicle_id AS cicl_book, 
     tbl_cicle.cicle
     FROM tbl_book
     LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
     WHERE tbl_book.visible ='1'
     ORDER BY tbl_book.book_rating DESC, tbl_book.book_name ASC 
     LIMIT $lim_ogr ";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom.php"; exit();}
       $result_rows = mysqli_num_rows($result_body);
       if($result_rows  > 0)
         {
          while($result_body_book= mysqli_fetch_array($result_body))
            {
               if($result_body_book['book_rating'] > 0)
               {
                $book_rating = ", <span class='ogl'>".$TEXT['book-rating']." = ".$result_body_book['book_rating']."</span>";
                $book_rating2 = " (<span class='ogl'>".$TEXT['book-rating']." = ".$result_body_book['book_rating']."</span>)";
               }
                else
                {
                 $book_rating = "";
                 $book_rating2 = "";
                }

               if($result_body_book['cicle'] !== '---')
               {
               $query_book_cicle = mysqli_query($dbcnx,"SELECT COUNT(tbl_book.book_id) AS co_book_id FROM tbl_book WHERE tbl_book.cicle_id='".$result_body_book['cicl_book']."'");
	        $coun_book_cicle = mysqli_fetch_array($query_book_cicle);

               $book = "<a href=extsearch.php?cicle_id=".$result_body_book['cicl_book']."&amp;cicle_ch=on title='".$TEXT['search-all-cicl']."'>  (".$TEXT['book-cicle']." - ".$result_body_book['cicle'].", ".$TEXT['global-now-book']." - ".$coun_book_cicle['co_book_id'].$book_rating.")</a>";
               $book_name = "<a href=info.php?book_id=".$result_body_book['book_id']." title='".$TEXT['aut-viewtit']."'><span class='zagolovok'>".rep_back($result_body_book['book_name'])."</span></a>";

               echo "<tr>";
               echo "<td align= 'right' width='50%'>".$book_name."</td>";
               echo "<td align= 'left' width='50%'>".$book."</td>";
               echo "</tr>";
               }
               else
               {
               $book = $book_rating2;
               $book_name = "<a href=info.php?book_id=".$result_body_book['book_id']." title='".$TEXT['aut-viewtit']."'><span class='zagolovok'>".rep_back($result_body_book['book_name'])."</span></a>";

               echo "<tr>";
               echo "<td align= 'right' width='50%'>".$book_name."</td>";
               echo "<td align= 'left' width='50%'>".$book."</td>";
               echo "</tr>";
               }
             }
         }
?>
</tbody>
</table>
     <?php
       $query_count = mysqli_query($dbcnx,"SELECT COUNT(book_id) AS c_book_id FROM tbl_book WHERE visible ='1'");
	       $coun_rows = mysqli_fetch_array($query_count);
               $pag = $coun_rows['c_book_id']/10;
               if($pag<1) {$pag = ceil($pag);}
                else
                {
                 ?>
                  <hr size="3" width="98%" />
                  <table align="center" border="0" cellpadding="0" cellspacing="0" width="60%" >
                   <tr align="center">
                    <td>
                <?php
                $pag=ceil($pag);
                $strn = $str-5;
                if($strn<1) {$strn=1;}
                $strk = $str+5;
                for($i=$strn; $i<=$pag; $i++)
                 {
                  if($i<=$strk)
                  {
                    if($i==$str)
                    {
                      $k = $i*10-10;
                      $kvis=$k+10;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='reating-search.php?k=".$k."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*10-10;
                    $kvis=$k+10;
                    $nvis=$k;
                    echo $pg = " <a href='reating-search.php?k=".$k."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>[".$i."]</a>";
                    }
                  }
                 }
                 ?>
                    <select name='k' onchange=window.location.href=this.options[this.selectedIndex].value;>
                    <?php
                    for($j=1; $j<=$pag; $j++)
                    {
                     $k = $j*10-10;
                     if($k == $_GET['k']) {echo "<option selected value=reating-search.php?k=".$k.">".$j."</option>";}
                       else {echo "<option value=reating-search.php?k=".$k.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
  require_once "utils/bottom.php";
?>