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

  require_once "utils/chlang_osn.php";

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

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

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

  if(strlen($_POST['book_name'])>255) {puterror2($result2['skin'],$TEXT['error-book2']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['isbn'])>255) {puterror2($result2['skin'],$TEXT['error-book9']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['opisanie'])>1000) {puterror2($result2['skin'],$TEXT['error-book10']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['oglavlenie'])>1500){puterror2($result2['skin'],$TEXT['error-book11']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['zhanr_id'])>5){puterror2($result2['skin'],$TEXT['error-zhanr6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['cicle_id'])>5) {puterror2($result2['skin'],$TEXT['error-cicle6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['tip_izd_id'])>5) {puterror2($result2['skin'],$TEXT['error-tip-izd6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['bibl_id'])>5) {puterror2($result2['skin'],$TEXT['error-libr6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['photo_obr'])>1) {puterror2($result2['skin'],$TEXT['error-pic2']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['zal_id'])>5) {puterror2($result2['skin'],$TEXT['error-zal6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['shkaf_id'])>5) {puterror2($result2['skin'],$TEXT['error-shkaf6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['polka_id'])>5) {puterror2($result2['skin'],$TEXT['error-polka6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['izd_id'])>5) {puterror2($result2['skin'],$TEXT['error-izd6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['data_izdaniya'])>10) {puterror2($result2['skin'],$TEXT['error-book21']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['data_postupleniya'])>10) {puterror2($result2['skin'],$TEXT['error-book22']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['data_postupleniya_bol'])>10) {puterror2($result2['skin'],$TEXT['error-book22']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['autor_id'])>15) {puterror2($result2['skin'],$TEXT['error-aut14']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['ser_id'])>5) {puterror2($result2['skin'],$TEXT['error-ser6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['autor_id'])>15) {puterror2($result2['skin'],$TEXT['error-aut14']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['book_id'])>255) {puterror22($result2['skin'],$TEXT['error-book6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['bibl_id'])>5) {puterror2($result2['skin'],$TEXT['error-libr6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['cicle_id'])>5) {puterror2($result2['skin'],$TEXT['error-cicle6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['zhanr_id'])>5){puterror2($result2['skin'],$TEXT['error-zhanr6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['bibl_id'])>5) {puterror2($result2['skin'],$TEXT['error-libr6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['zal_id'])>5) {puterror2($result2['skin'],$TEXT['error-zal6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['shkaf_id'])>5) {puterror2($result2['skin'],$TEXT['error-shkaf6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['polka_id'])>5) {puterror2($result2['skin'],$TEXT['error-polka6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['izd_id'])>5) {puterror2($result2['skin'],$TEXT['error-izd6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['tip_izd_id'])>5) {puterror2($result2['skin'],$TEXT['error-tip-izd6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_GET['ser_id'])>5) {puterror2($result2['skin'],$TEXT['error-ser6']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['typepar'])>2) {puterror2($result2['skin'],$TEXT['param_err12']); require_once "utils/bottom.php"; exit();}
  if(empty($_POST['typepar'])) {
   if(empty($_GET['typepar'])) {$_POST['typepar'] = "";}
    else {$_POST['typepar'] = $_GET['typepar'];}
    } else {$_POST['typepar'] = $_POST['typepar'];}
  
  if(empty($_POST['search'])) {
   if(empty($_GET['search'])) {$_POST['search'] = "";}
    else {$_POST['search'] = $_GET['search'];}
    } else {$_POST['search'] = $_POST['search'];}

  if(empty($_POST['izd_id'])) {
   if(empty($_GET['izd_id'])) {$_POST['izd_id'] = "";}
    else {$_POST['izd_id'] = $_GET['izd_id'];}
    } else {$_POST['izd_id'] = $_POST['izd_id'];}

  if(empty($_POST['autor_id'])) {
   if(empty($_GET['autor_id'])) {$_POST['autor_id'] = "";}
    else {$_POST['autor_id'] = $_GET['autor_id'];}
    } else {$_POST['autor_id'] = $_POST['autor_id'];}

  if(strlen($_POST['bl_id'])>5) {puterror($result2['skin'],$TEXT['error-booklang6']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['typepar'] = rep($_POST['typepar']);
  $_GET['ser_id'] = rep($_GET['ser_id']);
  $_GET['bibl_id'] = rep($_GET['bibl_id']);
  $_GET['book_id'] = rep($_GET['book_id']);
  $_GET['cicle_id'] = rep($_GET['cicle_id']);
  $_GET['cicle_ch'] = rep($_GET['cicle_ch']);
  $_GET['bibl_ch'] = rep($_GET['bibl_ch']);
  $_GET['zhanr_ch'] = rep($_GET['zhanr_ch']);
  $_POST['ser_id'] = rep($_POST['ser_id']);
  $_POST['bibl_id'] = rep($_POST['bibl_id']);
  $_POST['book_id'] = rep($_POST['book_id']);
  $_POST['cicle_id'] = rep($_POST['cicle_id']);
  $_POST['cicle_ch'] = rep($_POST['cicle_ch']);
  $_POST['bibl_ch'] = rep($_POST['bibl_ch']);
  $_POST['zhanr_ch'] = rep($_POST['zhanr_ch']);
  $_POST['spisano'] = rep($_POST['spisano']);
  $_POST['e_book'] = rep($_POST['e_book']);
  $_POST['book_name'] = rep($_POST['book_name']);
  $_POST['isbn'] = rep($_POST['isbn']);
  $_POST['opisanie'] = rep($_POST['opisanie']);
  $_POST['oglavlenie'] = rep($_POST['oglavlenie']);
  $_POST['zhanr_id'] = rep($_POST['zhanr_id']);
  $_GET['zhanr_id'] = rep($_GET['zhanr_id']);
  $_POST['cicle_id'] = rep($_POST['cicle_id']);
  $_POST['tip_izd_id'] = rep($_POST['tip_izd_id']);
  $_POST['bibl_id'] = rep($_POST['bibl_id']);
  $_POST['photo_obr'] = rep($_POST['photo_obr']);
  $_POST['zal_id'] = rep($_POST['zal_id']);
  $_POST['shkaf_id'] = rep($_POST['shkaf_id']);
  $_POST['polka_id'] = rep($_POST['polka_id']);
  $_POST['data_izdaniya'] = rep($_POST['data_izdaniya']);
  $_POST['data_postupleniya'] = rep($_POST['data_postupleniya']);
  $_POST['data_postupleniya_bol'] = rep($_POST['data_postupleniya_bol']);
  $_POST['ser_id'] = rep($_POST['ser_id']);
  $_POST['autor_id'] = rep($_POST['autor_id']);
  $_POST['izd_id'] = rep($_POST['izd_id']);
  $_POST['bl_id'] = rep($_POST['bl_id']);
//  $_GET['izd_id'] = rep($_GET['izd_id']);
  $_GET['bibl_id'] = rep($_GET['bibl_id']);
  $_GET['zal_id'] = rep($_GET['zal_id']);
  $_GET['shkaf_id'] = rep($_GET['shkaf_id']);
  $_GET['polka_id'] = rep($_GET['polka_id']);
  $_GET['tip_izd_id'] = rep($_GET['tip_izd_id']);

  if($_POST['search'] !== '')
  {
    switch($_POST['typepar'])
      {
      case 1:
      $_POST['book_name'] = trim($_POST['search']);
      break;
      case 2:
      $_POST['oglavlenie'] = trim($_POST['search']);
      break;
      case 3:
      $_POST['opisanie'] = trim($_POST['search']);
      break;
      case 4:
      $_POST['isbn'] = trim($_POST['search']);
      break;
      case 5:
      $univ_srch = trim($_POST['search']);
      break;
      }
   }

  if(!empty($univ_srch)) {$univ_srch2 = " AND LOWER(tbl_book.book_name) LIKE LOWER('%".$univ_srch."%') OR LOWER(tbl_book.opisanie) LIKE LOWER('%".$univ_srch."%') OR LOWER(tbl_book.oglavlenie) LIKE LOWER('%".$univ_srch."%') OR LOWER(tbl_cicle.cicle) LIKE LOWER('%".$univ_srch."%') OR LOWER(tbl_book.isbn) LIKE LOWER('%".$univ_srch."%') ";}
    else {$univ_srch2 = "";}

  if(!empty($_GET['book_id'])) {$book_id = " tbl_book.book_id = '".$_POST['book_id']."' ";}
    else {$book_id = " tbl_book.book_id != '0' ";}

  if(!empty($_POST['book_name'])) {$book_name = "AND LOWER(tbl_book.book_name) LIKE LOWER('%".$_POST['book_name']."%') ";}
    else {$book_name = "";}

  if(!empty($_POST['isbn'])) {$isbn = "AND LOWER(tbl_book.isbn) LIKE LOWER('%".$_POST['isbn']."%') ";}
    else {$isbn = "";}

  if(!empty($_POST['opisanie'])) {$opisanie = "AND LOWER(tbl_book.opisanie) LIKE LOWER('%".$_POST['opisanie']."%') ";}
    else {$opisanie = "";}

  if(!empty($_POST['oglavlenie'])) {$oglavlenie = "AND LOWER(tbl_book.oglavlenie) LIKE LOWER('%".$_POST['oglavlenie']."%') ";}
    else {$oglavlenie = "";}

  if(!empty($_POST['data_izdaniya'])) {$data_izdaniya = "AND tbl_book.data_izdaniya LIKE '%".$_POST['data_izdaniya']."%' ";}
    else {$data_izdaniya = "";}

  if(!empty($_POST['data_postupleniya']))
   {
   if(!empty($_POST['data_postupleniya_bol'])) {$data_postupleniya = "AND tbl_book.data_postupleniya BETWEEN '".$_POST['data_postupleniya_bol']."' AND '".$_POST['data_postupleniya']."' ";}
    else {$data_postupleniya = "AND tbl_book.data_postupleniya = '".$_POST['data_postupleniya']."' ";}
   }
   else {
     if(!empty($_POST['data_postupleniya_bol'])) {$data_postupleniya = "AND tbl_book.data_postupleniya > '".$_POST['data_postupleniya_bol']."' ";}
      else {$data_postupleniya = "";}
    }

  if(empty($_POST['izd_ch'])) {
   if(empty($_GET['izd_ch'])) {$_POST['izd_ch'] = "";}
    else {$_POST['izd_ch'] = $_GET['izd_ch'];}
    } else {$_POST['izd_ch'] = $_POST['izd_ch'];}

  if(empty($_POST['autor_ch'])) {
   if(empty($_GET['autor_ch'])) {$_POST['autor_ch'] = "";}
    else {$_POST['autor_ch'] = $_GET['autor_ch'];}
    } else {$_POST['autor_ch'] = $_POST['autor_ch'];}
  
  if(empty($_POST['ser_ch'])) {$_POST['ser_ch'] = "";}
  if(empty($_POST['zhanr_ch'])) {$_POST['zhanr_ch'] = "";}
  if(empty($_POST['cicle_ch'])) {$_POST['cicle_ch'] = "";}
  if(empty($_POST['tip_izd_ch'])) {$_POST['tip_izd_ch'] = "";}
  if(empty($_POST['bibl_ch'])) {$_POST['bibl_ch'] = "";}
  if(empty($_POST['zal_ch'])) {$_POST['zal_ch'] = "";}
  if(empty($_POST['shkaf_ch'])) {$_POST['shkaf_ch'] = "";}
  if(empty($_POST['polka_ch'])) {$_POST['polka_ch'] = "";}
  if(empty($_POST['spisano'])) {$_POST['spisano'] = "";}
  if(empty($_POST['e_book'])) {$_POST['e_book'] = "";}
  if(empty($_POST['bl_ch'])) {$_POST['bl_ch'] = "";}
  if(empty($_GET['cicle_ch'])) {$_GET['cicle_ch'] = "";}
  if(empty($_GET['bibl_ch'])) {$_GET['bibl_ch'] = "";}
  if(empty($_GET['zhanr_ch'])) {$_GET['zhanr_ch'] = "";}
  if(empty($_GET['bibl_ch'])) {$_GET['bibl_ch'] = "";}
  if(empty($_GET['zal_ch'])) {$_GET['zal_ch'] = "";}
  if(empty($_GET['shkaf_ch'])) {$_GET['shkaf_ch'] = "";}
  if(empty($_GET['polka_ch'])) {$_GET['polka_ch'] = "";}
  if(empty($_GET['tip_izd_ch'])) {$_GET['tip_izd_ch'] = "";}
  if(empty($_GET['ser_ch'])) {$_GET['ser_ch'] = "";}
  if(empty($_GET['bl_ch'])) {$_GET['bl_ch'] = "";}

  if($_POST['spisano'] == "on") {$spisano = "AND tbl_book.vidano = '2' ";}
   else {$spisano = "";}

  if($_POST['zakupka'] == "on") {$zakupka = "AND tbl_book.vidano = '3' ";}
   else {$zakupka = "";}

  if($_POST['e_book'] == "on") {$e_book = "AND tbl_book.e_book != '' ";}
   else {$e_book = "";}

  if($_POST['bilingua_book'] == "on") {$bi_book = "AND tbl_book.bl_id != tbl_book.bl2_id ";}
   else {$bi_book = "";}

  if($_POST['a_book'] == "on") {$a_book = "AND tbl_book.a_book != ''  ";}
   else {$a_book = "";}

  if($_POST['cd_book'] == "on") {$cd_book = "AND tbl_book.cd_book != ''  ";}
   else {$cd_book = "";}

  if($_POST['ser_ch'] == "on") {$ser = "AND tbl_book.ser_id = '".$_POST['ser_id']."' ";}
   else
     {
       if($_GET['ser_ch'] == "on") {$ser = "AND tbl_book.ser_id = '".$_GET['ser_id']."' ";}
       else {$ser = "";}
     }

  if($_POST['zhanr_ch'] == "on") {$zhanr = "AND tbl_book.zhanr_id = '".$_POST['zhanr_id']."' ";}
   else
     {
       if($_GET['zhanr_ch'] == "on") {$zhanr = "AND tbl_book.zhanr_id = '".$_GET['zhanr_id']."' ";}
       else {$zhanr = "";}
     }

  if($_POST['cicle_ch'] == "on") {$cicle = "AND tbl_book.cicle_id = '".$_POST['cicle_id']."' ";}
   else
     {
       if($_GET['cicle_ch'] == "on") {$cicle = "AND tbl_book.cicle_id = '".$_GET['cicle_id']."' ";}
       else {$cicle = "";}
     }

  if($_POST['tip_izd_ch'] == "on") {$tip_izd = "AND tbl_book.tip_izd_id = '".$_POST['tip_izd_id']."' ";}
   else
     {
       if($_GET['tip_izd_ch'] == "on") {$tip_izd = "AND tbl_book.tip_izd_id = '".$_GET['tip_izd_id']."' ";}
       else {$tip_izd = "";}
     }

  if($_POST['bibl_ch'] == "on") {$bibl = "AND tbl_book.bibl_id = '".$_POST['bibl_id']."' ";}
   else
     {
       if($_GET['bibl_ch'] == "on") {$bibl = "AND tbl_book.bibl_id = '".$_GET['bibl_id']."' ";}
       else {$bibl = "";}
     }

  if($_POST['zal_ch'] == "on") {$zal = "AND tbl_book.zal_id = '".$_POST['zal_id']."' ";}
   else
     {
       if($_GET['zal_ch'] == "on") {$zal = "AND tbl_book.zal_id = '".$_GET['zal_id']."' ";}
       else {$zal = "";}
     }

  if($_POST['shkaf_ch'] == "on") {$shkaf = "AND tbl_book.shkaf_id = '".$_POST['shkaf_id']."' ";}
   else
     {
       if($_GET['shkaf_ch'] == "on") {$shkaf = "AND tbl_book.shkaf_id = '".$_GET['shkaf_id']."' ";}
       else {$shkaf = "";}
     }

  if($_POST['polka_ch'] == "on") {$polka = "AND tbl_book.polka_id = '".$_POST['polka_id']."' ";}
   else
     {
       if($_GET['polka_ch'] == "on") {$polka = "AND tbl_book.polka_id = '".$_GET['polka_id']."' ";}
       else {$polka = "";}
     }

  if($_POST['bl_ch'] == "on") {$bl = "AND tbl_book.bl_id = '".$_POST['bl_id']."' ";}
   else
     {
       if($_GET['bl_ch'] == "on") {$bl = "AND tbl_book.bl_id = '".$_GET['bl_id']."' ";}
       else {$bl = "";}
     }

if($_POST['autor_ch'] == "on")
{
$autor = " AND tbl_s_book_aut.autor_id = '".$_POST['autor_id']."' ";
$query_iskh = "SELECT
tbl_s_book_aut.*,
tbl_book.*,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
lang1.bl_id AS bl_id1,
lang1.booklang AS booklang1,
lang1.picture AS picture1,
lang2.bl_id AS bl_id2,
lang2.booklang AS booklang2,
lang2.picture AS picture2
FROM tbl_s_book_aut
JOIN tbl_book ON tbl_s_book_aut.book_id=tbl_book.book_id
LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
JOIN tbl_booklang AS lang1 ON tbl_book.bl_id=lang1.bl_id
JOIN tbl_booklang AS lang2 ON tbl_book.bl2_id=lang2.bl_id
WHERE $book_id $book_name $isbn $opisanie $oglavlenie $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $autor $spisano $e_book $bi_book $a_book $cd_book $zakupka
ORDER BY tbl_book.cicle_id, tbl_book.book_num, tbl_book.book_name";
}
elseif($_POST['izd_ch'] == "on")
{
$izdatelstvo = " AND tbl_s_book_izd.izd_id = '".$_POST['izd_id']."' ";
$query_iskh = "SELECT
tbl_s_book_izd.*,
tbl_book.*,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
lang1.bl_id AS bl_id1,
lang1.booklang AS booklang1,
lang1.picture AS picture1,
lang2.bl_id AS bl_id2,
lang2.booklang AS booklang2,
lang2.picture AS picture2
FROM tbl_s_book_izd
JOIN tbl_book ON tbl_s_book_izd.book_id=tbl_book.book_id
LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
JOIN tbl_booklang AS lang1 ON tbl_book.bl_id=lang1.bl_id
JOIN tbl_booklang AS lang2 ON tbl_book.bl2_id=lang2.bl_id
WHERE $book_id $book_name $isbn $opisanie $oglavlenie $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $izdatelstvo $spisano $e_book $bi_book $a_book $cd_book $zakupka
ORDER BY tbl_book.cicle_id, tbl_book.book_num, tbl_book.book_name";
}
else
{
$query_iskh = "SELECT 
tbl_book.*,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
lang1.bl_id AS bl_id1,
lang1.booklang AS booklang1,
lang1.picture AS picture1,
lang2.bl_id AS bl_id2,
lang2.booklang AS booklang2,
lang2.picture AS picture2
FROM tbl_book
LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
JOIN tbl_booklang AS lang1 ON tbl_book.bl_id=lang1.bl_id
JOIN tbl_booklang AS lang2 ON tbl_book.bl2_id=lang2.bl_id
WHERE $book_id $univ_srch2 $book_name $isbn $opisanie $oglavlenie $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $spisano $e_book $bi_book $a_book $cd_book $zakupka
ORDER BY tbl_book.cicle_id, tbl_book.book_num, tbl_book.book_name";
}
$result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom.php"; exit();}
    $res_rows = mysqli_num_rows($result_iskh);
     if($res_rows == 0) {puterror2($result2['skin'],$TEXT['search-err4']); require_once "utils/bottom.php"; exit();}
      elseif($res_rows == 1)
       {
        $result_iskh2 = mysqli_fetch_array($result_iskh);
        echo "<html><head><meta HTTP-EQUIV='Refresh' CONTENT='0; URL=info.php?book_id=".$result_iskh2['book_id']."' /></head></html>";
       }
      elseif($res_rows > 1) {echo "<table align='center' border='0' cellpadding='3' cellspacing='0' width='95%' ><tbody id='tab'>";}
       while($result_body_book = mysqli_fetch_array($result_iskh))
       {
        
        if(!empty($result_body_book['remote_copy'] == "yes")) {$result_bl_pic_e = "&nbsp;<img align='top' alt='remote' src='skins/".$result2['skin']."/internet.png' />";}
          else {$result_bl_pic_e = "";}

        if($result_body_book['bl_id1'] !== $result_body_book['bl_id2']) {
            $bl = preg_replace("/\.\.+./","",$result_body_book['picture1']);
            $bl2 = preg_replace("/\.\.+./","",$result_body_book['picture2']);
            if(!empty($result_body_book['picture1']) && file_exists($bl) && !empty($result_body_book['picture2']) && file_exists($bl2)) {$bilin_pic = "&nbsp;<img alt='".$result_body_book['booklang1']."' height='16' width='22' src='".$bl."' />&nbsp;<img alt='".$result_body_book['booklang2']."' height='16' width='22' src='".$bl2."' />";}
//              else {$bilin_pic = "&nbsp;<span class='menu'>".$TEXT['menu-btn35']." &raquo; ".$result_body_book['booklang1']."&nbsp;".$result_body_book['booklang2']."</span>";}
              else {$bilin_pic = "";}
        } else {$bilin_pic = "";}

        $fl = substr($result_body_book['e_book'],3,255);
        $fla = substr($result_body_book['a_book'],3,255);
        $flcd = substr($result_body_book['cd_book'],3,255);
        if(!empty($result_body_book['e_book']) && file_exists($fl)) {$e_book2 = "&nbsp;<img align='top' alt='local' src='skins/".$result2['skin']."/clip.png' />";}
        else {$e_book2 = "";}
        if(!empty($result_body_book['a_book']) && file_exists($fla)) {$a_book2 = "&nbsp;<img align='top' alt='local' src='skins/".$result2['skin']."/audio.png' />";}
        else {$a_book2 = "";}
        if(!empty($result_body_book['cd_book']) && file_exists($flcd)) {$cd_book2 = "&nbsp;<img align='top' alt='local' src='skins/".$result2['skin']."/cdrom.png' />";}
        else {$cd_book2 = "";}

        //added 28.11.2020 + modified row 409, 434
        $spisano_pic = "&nbsp;<img align='top' alt='local' src='skins/".$result2['skin']."/noobr.png' />";
        ////

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

          $query_book_author = mysqli_query($dbcnx,"SELECT
          tbl_s_book_aut.*,
          tbl_autor.familiya,
          tbl_autor.name
          FROM tbl_s_book_aut
          LEFT JOIN tbl_autor ON tbl_s_book_aut.autor_id=tbl_autor.autor_id
          WHERE tbl_s_book_aut.book_id='".$result_body_book['book_id']."'");
          $query_book_author_result = mysqli_fetch_array($query_book_author);

          if($result_body_book['book_num'] == 0) {$book_num = "";}
           else
            {
            $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 = ", ".$TEXT['book-num']." - ".substr($result_body_book['book_num'],2,3);
               } else {$book_num = ", ".$TEXT['book-num']." - ".substr($result_body_book['book_num'],1,3);}
             } else {$book_num = ", ".$TEXT['book-num']." - ".$result_body_book['book_num'];}
           }

           $book = "<span class='zagolovok_vid'>&nbsp;&nbsp;</span><a href='extsearch.php?cicle_id=".$result_body_book['cicl_book']."&cicle_ch=on' title='".$TEXT['search-all-cicl']."'>(".$TEXT['book-cicle']." - ".rep_back($result_body_book['cicle']).", ".$TEXT['global-now-book']." - ".$coun_book_cicle['c_book_id'].$book_num.")</a>";

           $move_up = "<a href='book-up-down.php?cicle_id=".$result_body_book['cicl_book']."&amp;book_id=".$result_body_book['book_id']."&amp;position=".$result_body_book['book_num']."&amp;moving=up' title='".$TEXT['global-up-down-tit']."'>&uArr;</a>";
           $move_down = "<a href='book-up-down.php?cicle_id=".$result_body_book['cicl_book']."&amp;book_id=".$result_body_book['book_id']."&amp;position=".$result_body_book['book_num']."&amp;moving=down' title='".$TEXT['global-up-down-tit']."'>&dArr;</a>";

         if($result_body_book['vidano'] == '3') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-show5']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_zak'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
         elseif($result_body_book['vidano'] == '2') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-show3']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_sp'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$spisano_pic;}
         elseif($result_body_book['vidano'] == '1') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-vidano']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_vid'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
         else {$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>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
         if($result_body_book['zakazano'] == '1') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['menu-btn32']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_rez'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}

         echo "<tr>";
         echo "<td align= 'right' width='50%'>".$book_name.$a_book2.$cd_book2.$e_book2.$result_bl_pic_e."</td>";
         if($coun_book_cicle['c_book_id'] > 0 && $result2['administrator'] == 1) {echo "<td align= 'left' width='50%'>".$book."&nbsp;".$move_up."&frasl;".$move_down."</td>";}
          else {echo "<td align= 'left' width='50%'>".$book."</td>";}
         echo "</tr>";
         }
          else
           {
            $book = "";

            $query_book_author = mysqli_query($dbcnx,"SELECT
            tbl_s_book_aut.*,
            tbl_autor.familiya,
            tbl_autor.name
            FROM tbl_s_book_aut
            LEFT JOIN tbl_autor ON tbl_s_book_aut.autor_id=tbl_autor.autor_id
            WHERE tbl_s_book_aut.book_id='".$result_body_book['book_id']."'");
            $query_book_author_result = mysqli_fetch_array($query_book_author);

            if($result_body_book['vidano'] == '3') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-show5']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_zak'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
            elseif($result_body_book['vidano'] == '2') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-show3']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_sp'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$spisano_pic;}
            elseif($result_body_book['vidano'] == '1') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['book-vidano']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_vid'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
            else {$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>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}
            if($result_body_book['zakazano'] == '1') {$book_name = "<a href='info.php?book_id=".$result_body_book['book_id']."' title='".$TEXT['menu-btn32']."&nbsp;&#10073;&nbsp;".$TEXT['aut-viewtit']."'><span class='zagolovok_rez'>".rep_back($result_body_book['book_name'])."</span>&nbsp;(".rep_back($query_book_author_result['name'])."&nbsp;".rep_back($query_book_author_result['familiya']).")</a>".$bilin_pic;}

            echo "<tr>";
            echo "<td colspan='2' align= 'center' width='50%'>".$book_name.$a_book2.$cd_book2.$e_book2.$result_bl_pic_e."</td>";
            echo "</tr>";
          }
        }
        echo "</table>";

  require_once "utils/bottom.php";
?>