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

$title = $TEXT['cicle-title'];

require_once "../config_a.php";
require_once "../utils/functions.php";
require_once "../utils/top_adm.php";

if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}

if(strlen($_GET['cicle_id'])>5) {puterror($result2['skin'],$TEXT['error-id-long']); require_once "../utils/bottom_adm.php"; exit();}
$_GET['cicle_id'] = rep($_GET['cicle_id']);
if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "../utils/bottom_adm.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="0" cellspacing="0" width="80%">
<tr align="right">
<td><img alt="<?php echo $TEXT['add-new']; ?>" src='../skins/<?php echo $result2['skin']; ?>/add.png' />&nbsp;<a class="bold_it" href="book-add-frm.php?cicle_id=<?php echo $_GET['cicle_id']; ?>" title="<?php echo $TEXT['add-new-tit']; ?>"><?php echo $TEXT['add-new']; ?></a></td>
</tr>
</table>
<table align="center" border="0" cellpadding="3" cellspacing="0" width="80%">
 <thead><tr class='tableheadercat'>
<td><?php echo $TEXT['book-name']; ?></td>
<td><?php echo $TEXT['book-bibl']; ?></td>
<td><?php echo $TEXT['book-num']; ?></td>
<td><?php echo $TEXT['book-data']; ?></td>
<td><?php echo $TEXT['book-nal']; ?></td>
</tr>
 </thead>
<tbody id="tab" >
<?php
     $query_body = "SELECT
     tbl_book.book_name,
     tbl_book.book_id,
     tbl_book.data_izdaniya,
     tbl_book.book_num,
     tbl_book.vidano,
     tbl_biblioteka.name AS bibl_name
     FROM tbl_book
     JOIN tbl_biblioteka ON tbl_book.bibl_id=tbl_biblioteka.bibl_id
     WHERE tbl_book.cicle_id = ".$_GET['cicle_id']."
     ORDER BY bibl_name, tbl_book.book_num, tbl_book.book_name
     LIMIT $lim_ogr ";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
       $result_rows = mysqli_num_rows($result_body);
       if($result_rows > 0)
         {
         while($result_body_book= mysqli_fetch_array($result_body))
               {
                $bnt = substr($result_body_book['book_num'],0,1);
                if($bnt == '0')
                 {
                 $book_n = substr($result_body_book['book_num'],1,1);
                  if($book_n == '0')
                   {
                   $book_num = substr($result_body_book['book_num'],2,3);
                   } else {$book_num = substr($result_body_book['book_num'],1,3);}
                 } else {$book_num = $result_body_book['book_num'];}

               $bibl = $result_body_book['bibl_name'];
               $book_name = "<a href=../info.php?book_id=".$result_body_book['book_id']." target=_blank title='".$TEXT['aut-viewtit']."'>".$result_body_book['book_name']."</a>";
               $back = "<a href=book-clr.php?book_id=".$result_body_book['book_id']."&amp;cicle_id=".$_GET['cicle_id']." title='".$TEXT['cicle-delete']."'><img alt='mail' src='../skins/".$result2['skin']."/cicle-back.png' /></a>";

               if($result_body_book['vidano'] == '3') {$zakaz = "<img align='top' alt='".$TEXT['book-show5']."' src='../skins/".$result2['skin']."/zakupka.png' />";}
                else {$zakaz = "";}

               ?>
               <tr>
                <td class="informcntr"><?php echo $book_name; ?>&nbsp;<?php echo $zakaz; ?></td>
                <td><?php echo $bibl; ?></td>
                <td> <?php echo $book_num; ?></td>
                <td><?php echo $result_body_book['data_izdaniya']; ?></td>
                <td><?php echo $back; ?></td>
               </tr>
               <?php
               }
         }
?>
</tbody>
</table>
     <?php
       $query_count = mysqli_query($dbcnx,"SELECT COUNT(book_id) AS c_book_id FROM tbl_book WHERE cicle_id = ".$_GET['cicle_id']."");
	       $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='book-srch.php?k=".$k."&amp;cicle_id=".$_GET['cicle_id']."' 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='book-srch.php?k=".$k."&amp;cicle_id=".$_GET['cicle_id']."' 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=book-srch.php?k=".$k."&amp;cicle_id=".$_GET['cicle_id'].">".$j."</option>";}
                       else {echo "<option value=book-srch.php?k=".$k."&amp;cicle_id=".$_GET['cicle_id'].">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
  require_once "../utils/bottom_adm.php";
?>