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

  require_once "utils/chlang_osn.php";

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

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

  if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror2($result2['skin'],$TEXT['error-loginform2']); 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['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['autor_id'])>15) {puterror2($result2['skin'],$TEXT['error-aut14']); require_once "utils/bottom.php"; exit();}
  if(empty($_POST['login_id'])) {puterror2($result2['skin'],$TEXT['error-login15']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['login_id'])>15) {puterror2($result2['skin'],$TEXT['error-login14']); 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($_POST['vidano'])>255) {puterror2($result2['skin'],$TEXT['param_err12']); require_once "utils/bottom.php"; exit();}
  if(strlen($_POST['bl_id'])>5) {puterror($result2['skin'],$TEXT['error-booklang6']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['vidano'] = rep($_POST['vidano']);
  $_POST['ser_id'] = rep($_POST['ser_id']);
  $_POST['bibl_id'] = rep($_POST['bibl_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['oglavlenie'] = rep($_POST['oglavlenie']);
  $_POST['zhanr_id'] = rep($_POST['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['ser_id'] = rep($_POST['ser_id']);
  $_POST['autor_id'] = rep($_POST['autor_id']);
  $_POST['izd_id'] = rep($_POST['izd_id']);
  $_POST['login_id'] = rep($_POST['login_id']);
  $_POST['bl_id'] = rep($_POST['bl_id']);

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

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

  if(empty($_POST['izd_ch'])) {$_POST['izd_ch'] = "";}
  if(empty($_POST['autor_ch'])) {$_POST['autor_ch'] = "";}
  if(empty($_POST['login_ch'])) {$_POST['login_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['vidano'])) {$_POST['vidano'] = "";}
  if(empty($_POST['oglavlenie'])) {$_POST['oglavlenie'] = "";}
  if(empty($_POST['bl_ch'])) {$_POST['bl_ch'] = "";}

  if($_POST['vidano'] !== '')
  {
    switch($_POST['vidano'])
      {
      case 1:
      $vidano = "AND tbl_book.vidano = '1' ";
      $vis_vid = "1";
      break;
      case 2:
      $vidano = "AND tbl_book.vidano = '2' ";
      $vis_vid = "2";
      break;
      case 3:
      $vidano = "AND tbl_book.vidano = '3' ";
      $vis_vid = "3";
      break;
      }
   } else {$vidano = "";}

  if($_POST['login_ch'] == "on") 
  {
   $login = "AND tbl_book.user_id = '".$_POST['login_id']."' ";
   $querylgn = "SELECT name, familiya, otchestvo FROM `tbl_logins` WHERE login_id = '".$_POST['login_id']."'  ";
     $resultlgn = mysqli_query($dbcnx,$querylgn);
       if(!$resultlgn) {puterror2($result2['skin'],$TEXT['error-tbl7']); require_once "utils/bottom.php"; exit();}
         $result_login = mysqli_fetch_array($resultlgn);
          $user_stat = $result_login['familiya']." ".$result_login['name']." ".$result_login['otchestvo'];
  }
   else {$login = "";}

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

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

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

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

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

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

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

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

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

if($_POST['org_viv'] == "on")
{
 if($_POST['autor_ch'] == "on")
 {
$autor_iskh = " AND tbl_s_book_aut.autor_id = '".$_POST['autor_id']."' ";
$query_iskh = "SELECT
tbl_s_book_aut.*,
tbl_book.book_id,
tbl_book.oglavlenie,
tbl_book.isbn,
tbl_book.book_num,
tbl_book.vidano,
tbl_book.book_name,
tbl_book.prichina,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
tbl_seriya.seriya
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
LEFT JOIN tbl_seriya ON tbl_book.ser_id=tbl_seriya.ser_id
WHERE tbl_book.book_id != '0' $autor_iskh $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $vidano $login
ORDER BY 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.book_id,
tbl_book.oglavlenie,
tbl_book.isbn,
tbl_book.book_num,
tbl_book.vidano,
tbl_book.book_name,
tbl_book.prichina,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
tbl_seriya.seriya
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
LEFT JOIN tbl_seriya ON tbl_book.ser_id=tbl_seriya.ser_id
WHERE tbl_book.book_id != '0' $izdatelstvo $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $vidano $login
ORDER BY tbl_book.book_name";
}
else
{
$query_iskh = "SELECT
tbl_book.book_id,
tbl_book.oglavlenie,
tbl_book.isbn,
tbl_book.book_num,
tbl_book.vidano,
tbl_book.book_name,
tbl_book.prichina,
tbl_book.cicle_id AS cicl_book,
tbl_cicle.cicle,
tbl_seriya.seriya
FROM tbl_book
LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
LEFT JOIN tbl_seriya ON tbl_book.ser_id=tbl_seriya.ser_id
WHERE tbl_book.book_id != '0' $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $vidano $login
ORDER BY tbl_book.book_name";
}
$result_iskh = mysqli_query($dbcnx,$query_iskh);
//print $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 > 0) {echo "<div class='logo' valign='top'><img alt='Picture' src='skins/".$result2['skin']."/library.png' />".$TEXT['global-title']."&nbsp;<span class='logover'>".$TEXT['global-vertion']."</span></div>";}
       if($_POST['login_ch'] == "on") {echo "<hr width='250px' align='right' /><div class='logo'>".$TEXT['book-user-stat']."<span class='logouser'>".$user_stat."</span></div><br />";}
       if($vis_vid == "1") {echo "<div class='logouser'>".$TEXT['book-vidano']."</div><hr width='250px' align='left' />";}
       elseif($vis_vid == "2") {echo "<div class='logouser'>".$TEXT['book-show4']."</div><hr width='250px' align='left' />";}
       elseif($vis_vid == "3") {echo "<div class='logouser'>".$TEXT['book-show5']."</div><hr width='250px' align='left' />";}
       echo "<div>";
       echo "<ul id='prn'>";
       while($result_body_book = mysqli_fetch_array($result_iskh))
       {
        $autor = "";
        $izd = "";

       $result_body_book['opisanie'] = rep_back($result_body_book['opisanie']);
       $result_body_book['oglavlenie'] = rep_back($result_body_book['oglavlenie']);
       $result_body_book['book_name'] = rep_back($result_body_book['book_name']);
       $result_body_book['isbn'] = rep_back($result_body_book['isbn']);
       $result_body_book['cicle'] = rep_back($result_body_book['cicle']);

        if($result_body_book['vidano'] == 0) {$book_name = "<span>".$result_body_book['book_name']."</span>";}
         elseif($result_body_book['vidano'] == 1) {$book_name = "<span class='vidano'>".$result_body_book['book_name']."</span>";}
         elseif($result_body_book['vidano'] == 2) {$book_name = "<span class='spisano'>".$result_body_book['book_name']."</span>&nbsp;&#187;&nbsp;<span class='prichina'>".$result_body_book['prichina']."</span> ";}
         elseif($result_body_book['vidano'] == 3) {$book_name = "<span class='zakupka'>".$result_body_book['book_name']."</span>";}

       echo "<li>".$book_name."</li>";
       echo "<ul>";

       $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_body_book['book_id']."' ";
       $result_autor = mysqli_query($dbcnx,$query_autor);
       if(!$result_autor) {puterror2($result2['skin'],$TEXT['error-tbl16']); require_once "utils/bottom.php"; exit();}
        while($result_autor2 = mysqli_fetch_array($result_autor))
        {
        $autor .= rep_back($result_autor2['name'])." ".rep_back($result_autor2['otchestvo'])." ".rep_back($result_autor2['familiya']).", ";
        }
        $autors = $TEXT['menu-btn23']." - ".substr($autor, 0,-2);

       $query_izd = "SELECT
       tbl_s_book_izd.*,
       tbl_izdatelstvo.*
       FROM tbl_s_book_izd
       JOIN tbl_izdatelstvo ON tbl_s_book_izd.izd_id=tbl_izdatelstvo.izd_id
       WHERE book_id = '".$result_body_book['book_id']."' ";
       $result_izd = mysqli_query($dbcnx,$query_izd);
        if(!$result_izd) {puterror2($result2['skin'],$TEXT['error-tbl17']); require_once "utils/bottom.php"; exit();}
        while($result_izd2 = mysqli_fetch_array($result_izd))
        {
        $izd .= $result_izd2['izdatelstvo'].", ";
        }
        $izds = $TEXT['menu-btn22']." - ".substr($izd, 0,-2);

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

           $cicle = $TEXT['cicle-title']." - ".$result_body_book['cicle'];
           $seriya = $TEXT['ser-title']." - ".$result_body_book['seriya'];
           $isbn = $TEXT['book-isbn']." - ".$result_body_book['isbn'];
           $oglavlenie = $TEXT['book-oglavl'].":<br />".nl2br($result_body_book['oglavlenie']);
           echo "<li>".$autors."</li>";
           echo "<ul id='prin'>";
           if($result_body_book['isbn'] !== "") {echo "<li><span class='oglavlenie'>".$isbn."</span></li>";}
           echo "<li><span class='oglavlenie'>".$izds."</span></li>";
           if($result_body_book['seriya'] !== "---") {echo "<li><span class='oglavlenie'>".$seriya."</span></li>";}
           if($result_body_book['cicle'] !== "---") {echo "<li><span class='oglavlenie'>".$cicle."</span></li>";}
           echo "<li><span class='oglavlenie'>".$book_num."</span></li>";
           if($_POST['oglavlenie'] == "on" && $result_body_book['oglavlenie'] !== "") {echo "<li><hr width='50px' align='left' /><span class='oglavlenie'>".$oglavlenie."</span><hr width='150px' align='left' /></li>";}
            else {echo "<li><hr width='150px' align='left' /></li>";}
           echo "</ul>";
           echo "</ul>";
      }
      echo "</ul>";
      echo "<div>";
}
else
{
if($_POST['autor_ch'] == "on")
{
$query_iskh = "SELECT
autor_id,
name,
familiya,
otchestvo,
real_name
FROM tbl_autor
WHERE autor_id = '".$_POST['autor_id']."' ";
}
else
{
$query_iskh = "SELECT
tbl_autor.autor_id,
tbl_autor.name,
tbl_autor.familiya,
tbl_autor.otchestvo,
tbl_autor.real_name
FROM tbl_autor
ORDER BY tbl_autor.familiya, tbl_autor.name, tbl_autor.otchestvo";
}
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror2($result2['skin'],$TEXT['error-tbl1']); 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 > 0)
      {
       echo "<div class='logo' valign='top'><img alt='Picture' src='skins/".$result2['skin']."/library.png' />".$TEXT['global-title']."&nbsp;<span class='logover'>".$TEXT['global-vertion']."</span></div>";
       if($_POST['login_ch'] == "on") {echo "<hr width='250px' align='right' /><br /><div class='logo'>".$TEXT['book-user-stat']."<span class='logouser'>".$user_stat."</span></div><br />";}
       if($vis_vid == "1") {echo "<div class='logouser'>".$TEXT['book-vidano']."</div><hr width='250px' align='left' />";}
       elseif($vis_vid == "2") {echo "<div class='logouser'>".$TEXT['book-show4']."</div><hr width='250px' align='left' />";}
       elseif($vis_vid == "3") {echo "<div class='logouser'>".$TEXT['book-show5']."</div><hr width='250px' align='left' />";}
       echo "<div>";
       echo "<ul id='prn'>";
       while($result_iskh2 = mysqli_fetch_array($result_iskh))
       {
        if($result_iskh2['real_name'] !== "") {$real_name = "&nbsp;<span class='autorname'>&#040;".rep_back($result_iskh2['real_name'])."&#041;</span>";}
         else {$real_name = "";}

        $book_autor = rep_back($result_iskh2['name'])." ".rep_back($result_iskh2['otchestvo'])." ".rep_back($result_iskh2['familiya']);

        if($_POST['izd_ch'] == "on")
        {
         $query_iskh2 = "SELECT
         tbl_s_book_izd.*,
         tbl_s_book_aut.*,
         tbl_book.book_id,
         tbl_book.oglavlenie,
         tbl_book.cicle_id,
         tbl_book.book_num,
         tbl_book.vidano,
         tbl_book.book_name,
         tbl_book.prichina,
         tbl_cicle.*
         FROM tbl_s_book_izd
         JOIN tbl_book ON tbl_s_book_izd.book_id=tbl_book.book_id
         JOIN tbl_s_book_aut ON tbl_s_book_izd.book_id=tbl_s_book_aut.book_id
         LEFT JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
         WHERE tbl_s_book_izd.izd_id = '".$_POST['izd_id']."' AND tbl_s_book_aut.autor_id = ".$result_iskh2['autor_id']." $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $vidano $login
         ORDER BY tbl_book.cicle_id, tbl_book.book_num, tbl_book.book_name ";
        }
        else
         {
         $query_iskh2 = "SELECT
         tbl_s_book_aut.*,
         tbl_book.book_id,
         tbl_book.oglavlenie,
         tbl_book.cicle_id,
         tbl_book.book_num,
         tbl_book.vidano,
         tbl_book.book_name,
         tbl_book.prichina,
         tbl_cicle.*
         FROM tbl_s_book_aut
         JOIN tbl_book ON tbl_s_book_aut.book_id=tbl_book.book_id
         JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
         WHERE tbl_s_book_aut.autor_id = ".$result_iskh2['autor_id']." $data_izdaniya $data_postupleniya $ser $zhanr $cicle $tip_izd $bibl $zal $shkaf $polka $bl $vidano $login
         ORDER BY tbl_book.cicle_id, tbl_book.book_num, tbl_book.book_name";
          }
          $result_iskh3 = mysqli_query($dbcnx,$query_iskh2);
          $cicle_id_prev = 0;
           if(!$result_iskh3) {puterror2($result2['skin'],$TEXT['error-tbl16']); require_once "utils/bottom.php"; exit();}
           $res_rows2 = mysqli_num_rows($result_iskh3);
           if($res_rows2 > 0)
           {
           echo "<li>".$book_autor.$real_name."</li>";
           echo "<ul>";
       while($result_iskh4 = mysqli_fetch_array($result_iskh3))
       {

       $result_iskh4['opisanie'] = rep_back($result_iskh4['opisanie']);
       $result_iskh4['oglavlenie'] = rep_back($result_iskh4['oglavlenie']);
       $result_iskh4['book_name'] = rep_back($result_iskh4['book_name']);
       $result_iskh4['isbn'] = rep_back($result_iskh4['isbn']);
       $result_iskh4['cicle'] = rep_back($result_iskh4['cicle']);

        if($result_iskh4['vidano'] == 0) {$book_name = "<span class='nameste'>".$result_iskh4['book_name']."</span>";}
         elseif($result_iskh4['vidano'] == 1) {$book_name = "<span class='vidano'>".$result_iskh4['book_name']."</span>";}
         elseif($result_iskh4['vidano'] == 2) {$book_name = "<span class='spisano'>".$result_iskh4['book_name']."</span>&nbsp;&#187;&nbsp;<span class='prichina'>".$result_iskh4['prichina']."</span> ";}
         elseif($result_iskh4['vidano'] == 3) {$book_name = "<span class='zakupka'>".$result_iskh4['book_name']."</span>";}

     if($result_iskh4['book_num'] == "" || $result_iskh4['book_num'] == "0" || $result_iskh4['book_num'] == NULL) {$book_num = "";}
      else
      {
      $bnt = substr($result_iskh4['book_num'],0,1);
      if($bnt == '0')
       {
       $book_n = substr($result_iskh4['book_num'],1,1);
        if($book_n == '0')
         {
         $book_num = $TEXT['book-num']." &#8211; ".substr($result_iskh4['book_num'],2,3);
         } else {$book_num = $TEXT['book-num']." &#8211; ".substr($result_iskh4['book_num'],1,3);}
       } else {$book_num = $TEXT['book-num']." &#8211; ".$result_iskh4['book_num'];}
      }

      if($result_iskh4['cicle'] !== "---") 
      {
       $cicle_book = $TEXT['book-cicle']." &#8211; ".$result_iskh4['cicle']."";
        if($result_iskh4['cicle_id'] == $cicle_id_prev) {$cicle_book2 = "";}
            else 
                {
                 $cicle_book2 = "<li><span class='autorname'>".$TEXT['book-cicle']." &#8211; ".$result_iskh4['cicle']."</span></li>";
                 $cicle_id_prev = $result_iskh4['cicle_id'];
                 $cicle_prob = "&nbsp;&nbsp;";
                }
      } else {$cicle_book = "";}

//        if($cicle_book !== "" && $book_num !== "") {echo $cicle_book2."<li>".$cicle_prob.$book_name."&nbsp;<span class='booknum'>&#040; ".$cicle_book." &#124; ".$book_num." &#041;</span></li>";}
//        elseif($cicle_book == "" && $book_num !== "") {echo "<li>".$book_name."&nbsp;<span class='booknum'>&#040; ".$book_num." &#041;</span></li>";}
//        elseif($cicle_book !== "" && $book_num == "") {echo $cicle_book2."<li>".$cicle_prob.$book_name."&nbsp;<span class='booknum'>&#040; ".$cicle_book." &#041;</span></li>";}
//        elseif($cicle_book == "" && $book_num == "") {echo "<li>".$book_name."</li>";}
      
        if($cicle_book !== "" && $book_num !== "") {echo $cicle_book2."<li>".$cicle_prob.$book_name."&nbsp;<span class='booknum'>&#040; ".$book_num." &#041;</span></li>";}
        elseif($cicle_book == "" && $book_num !== "") {echo "<li>".$book_name."&nbsp;<span class='booknum'>&#040; ".$book_num." &#041;</span></li>";}
        elseif($cicle_book !== "" && $book_num == "") {echo $cicle_book2."<li>".$cicle_prob.$book_name."</li>";}
        elseif($cicle_book == "" && $book_num == "") {echo "<li>".$book_name."</li>";}
        if($_POST['oglavlenie'] == "on" && $result_iskh4['oglavlenie'] !== "")
        {
         echo "<ul id='prin'>";
         echo "<li><span class='oglavlenie'>".nl2br($result_iskh4['oglavlenie'])."</span></li>";
         echo "</ul>";
        }

       }
       echo "</ul>";
       echo "<hr align='left' width='45%'/>";
           }
       }
       echo "</ul>";
      }
      echo "<div>";
  }
?>
</body>
</html>