<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  require_once "../utils/chlang.php";

  $title = $TEXT['search-title'];
  $button = $TEXT['btn_add_new'];
  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm.php";

  if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_POST['book_name'])) {puterror($result2['skin'],$TEXT['error-book1']); require_once "../utils/bottom_adm.php"; exit();}
  if(trim($_POST['book_name']) == "") {puterror($result2['skin'],$TEXT['error-book1']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['book_name'])>255) {puterror($result2['skin'],$TEXT['error-book2']); require_once "../utils/bottom_adm.php"; exit();}
  $_POST['book_name'] = rep($_POST['book_name']);

$query_iskh = "SELECT
tbl_book.book_id,
tbl_book.bibl_id,
tbl_book.book_name,
tbl_biblioteka.name AS biblioteka,
tbl_biblioteka.bibl_id
FROM tbl_book
JOIN tbl_biblioteka ON tbl_book.bibl_id=tbl_biblioteka.bibl_id 
WHERE LOWER(tbl_book.book_name) LIKE LOWER('%".$_POST['book_name']."%') ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
    $res_rows = mysqli_num_rows($result_iskh);
     if($res_rows == 0)
       {
        echo "<html><head><meta HTTP-EQUIV='Refresh' CONTENT='0; URL=addform.php?book_name=".rep_back($_POST['book_name'])."' /></head></html>";
       }
      else
      {
       echo "<form name='book' enctype='multipart/form-data' action='addform.php' method='post'>
             <table align='center' border='0' cellpadding='3' cellspacing='0' width='90%' >
             <tbody id='tab'>";
       while($result_iskh2 = mysqli_fetch_array($result_iskh))
       {
       $autor = "";

       $query_autor = "SELECT
       tbl_s_book_aut.*,
       tbl_autor.autor_id,
       tbl_autor.name,
       tbl_autor.familiya,
       tbl_autor.otchestvo
       FROM tbl_s_book_aut
       JOIN tbl_autor ON tbl_s_book_aut.autor_id=tbl_autor.autor_id
       WHERE book_id = '".$result_iskh2['book_id']."' ";
       $result_autor = mysqli_query($dbcnx,$query_autor);
        if(!$result_autor) {puterror($result2['skin'],$TEXT['error-tbl16']); require_once "../utils/bottom_adm.php"; exit();}
         while($result_autor2 = mysqli_fetch_array($result_autor))
         {
           $autor .=$result_autor2['name']." ".$result_autor2['otchestvo']." ".$result_autor2['familiya'].", ";
         }
         $autors =substr($autor, 0,-2);

        $book_name = "<a href=editform.php?book_id=".$result_iskh2['book_id']." title='".$TEXT['aut-viewtit']."'><h2>".rep_back($result_iskh2['book_name'])."</h2></a>";
        $book = "<h4>(".$TEXT['book-bibl2'].$result_iskh2['biblioteka']." | ".$TEXT['menu-btn23']." - ".$autors.")</h4>";

       echo "<tr>
             <td align= 'right'>".$book_name."</td>
             <td align= 'left'>".$book."</td>
             </tr>";
       }
       echo "</tbody>
             <tfoot>
             <tr>
             <td>
             <input class='button2' type='submit' value='".$button."' />
             <input type='hidden' name='book_name' value='".rep_back($_POST['book_name'])."' />
             </td>
             <td>
               <table align='right' width='25%'>
               <tr>
                <td class='search_res' width='5%'>".$TEXT['search-res-tit'].$res_rows."</td>
               </tr>
               </table>
             </td>
             </tr>
             </tfoot>
             </table>
             </form>";
      }
  require_once "../utils/bottom_adm.php";
?>